我知道这不是一个数据可视化的问题,但老板要求它,所以我需要弄清楚是否可能。
谢谢!
为那些在 2016 年寻找答案的人提供答案。
从ggplot2
2.0 开始,switch 参数将为facet_grid
or执行此操作facet_wrap
:
默认情况下,标签显示在图的顶部和右侧。如果为“x”,则顶部标签将显示在底部。如果为“y”,则右侧标签将显示在左侧。也可以设置为“两者”。
ggplot(...) + ... + facet_grid(facets, switch="both")
从 ggplot2 2.2.0 开始,
条带现在可以
facet_wrap()
使用 strip.position 参数自由定位(不推荐使用switch
)。
strip.position
当前文档仍为 2.1,但记录在开发文档中。
默认情况下,标签显示在图的顶部。使用 strip.position 可以通过设置将标签放置在四个侧面中的任何一个上
strip.position = c("top", "bottom", "left", "right")
ggplot(...) + ... + facet_wrap(facets, strip.position="right")
您现在可以使用facet_wrap(~var, strip.position = "bottom")
,但由于某种原因,这会导致标签位于轴刻度标签上方,而不是下方(我认为这更有意义),正如您从我的图表一小部分的屏幕截图中看到的那样
如果你想有下面的标签,你必须这样做
ggplot(zzz, aes(x = c1, y = c2)) +
facet_wrap(~ gp, scales = "free", nrow = 3, strip.position = "bottom") +
geom_point() +
theme(
aspect.ratio = 1,
strip.background = element_blank(),
strip.placement = "outside"
)
答案是肯定的!
theme(strip.text=element_text(vjust=-10))
数字 -10 取决于您在绘图中使用的比例和单位。
继续使用主题:
主题(strip.text=element_text(vjust=-10))
确保您的标签都有相同数量的回车。
Label /n Facet /n One
将以不同于 的速度变化Label /n Facet Two
。