bty =“n”在ggplot2中 [英] bty = "n" in ggplot2
问题描述
在ggplot2中有没有使正常的R图形中的bty =n不在一起的轴?
像这样:
谢谢
这有点笨重,但是你可以通过抑制坐标轴并在适当的位置用段进行注释来做到这一点:了解ggplot将在图的左侧/底部放置x / y坐标为 -Inf
的元素...
pre $
library(ggplot2)
axrange< - list(y = c(50,90),x = c(2 ,5))
g0 < - ggplot(忠诚,aes(x = eruptions,y =等待))+
geom_point(shape = 21)
g0 +
theme_classic )+
theme(axis.line.y = element_blank(),axis.line.x = element_blank())+
annotate(segment,x = -Inf,xend = -Inf,y = axrange $ y [1],yend = axrange $ y [2])+
annotate(segment,y = -Inf,yend = -Inf,x = axrange $ x [1],xend = axrange $ x $ [2])
我不知道更简单/更自动的方式;我不认为有人存在,但希望我错了。
来自 ggthemes
包的Tufte主题给出另一种最小的图,但不是你想要的...
library(ggthemes)
g0 + theme_tufte()
Is there a way in ggplot2 to make the not being together axis such as bty="n" in normal R graphics?
Like this:
Thank you
It's a little bit clunky, but you can do it by suppressing the axes and annotating with segments in the appropriate places: it's useful to know that ggplot will place elements with x/y coordinates of -Inf
at the left/bottom of the plot ...
library("ggplot2")
axrange <- list(y=c(50,90),x=c(2,5))
g0 <- ggplot(faithful, aes(x=eruptions, y=waiting)) +
geom_point(shape=21)
g0 +
theme_classic()+
theme(axis.line.y=element_blank(),axis.line.x=element_blank())+
annotate("segment",x=-Inf,xend=-Inf,y=axrange$y[1],yend=axrange$y[2])+
annotate("segment",y=-Inf,yend=-Inf,x=axrange$x[1],xend=axrange$x[2])
I don't know of an easier/more automatic way; I don't think one exists, but hopefully I'm wrong.
The Tufte theme from the ggthemes
package gives another sort of minimal graph, but not what you want ...
library("ggthemes")
g0+theme_tufte()
这篇关于bty =“n”在ggplot2中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!