【发布时间】:2015-04-13 07:22:00
【问题描述】:
我在 R 中使用 ggplot 来绘制带有 facet_wrap 的几个条件。 我想将带有绘图名称的条带放在右侧而不是顶部的垂直轴上。
这是一个例子:
library(ggplot2)
dat<- data.frame(name= rep(LETTERS[1:5], each= 4), value= rnorm(20), time= rep(1:5, 4))
gg<- ggplot(data= dat, aes(x= time, y= value)) +
geom_point() +
facet_wrap(~ name, ncol= 1)
这里地块名称(A、B、C、D、E)位于顶部,我希望它们位于右侧,如下所示:
gg + facet_grid(name ~ .)
是否有一个简单的开关来做到这一点?
(我没有使用facet_grid,因为我想使用facet_wrap 附带的选项nrow 和ncol)。
谢谢!达里奥
sessionInfo()
R version 3.0.1 (2013-05-16)
Platform: x86_64-apple-darwin10.8.0 (64-bit)
locale:
[1] en_GB.UTF-8/en_GB.UTF-8/en_GB.UTF-8/C/en_GB.UTF-8/en_GB.UTF-8
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] ggplot2_0.9.3.1
loaded via a namespace (and not attached):
[1] colorspace_1.2-4 dichromat_2.0-0 digest_0.6.4 grid_3.0.1
[5] gtable_0.1.2 labeling_0.2 MASS_7.3-29 munsell_0.4.2
[9] plyr_1.8.1 proto_0.3-10 RColorBrewer_1.0-5 Rcpp_0.11.0
[13] reshape2_1.2.2 scales_0.2.3 stringr_0.6.2 tools_3.0.1
【问题讨论】:
-
我认为这并不容易。我唯一能想到的就是制作一个虚拟变量并将其与
facet_grid一起使用。您总是可以尝试使用grid/gridExtra进行低级操作,但这是一条复杂的路径。 -
好的,感谢您的反馈。我猜虚拟变量路径是最简单的,虽然我不愿意仅仅为了美观而改变数据。
标签: r ggplot2 facet-wrap