将ggplot中条带标签的位置从顶部更改为底部?
我知道这不完全是一个数据可视化问题,但老板要求这样做,所以我需要弄清楚是否可以。
I know this is not quite a data visualization issue, but the boss asked for it, so I need to figure out if it is possible.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
2016 年搜索者的答案。
从 ggplot2 2.0 开始,switch 参数 将为
facet_grid
或facet_wrap
执行此操作:从 ggplot2 2.2.0 开始,
当前文档仍为 2.1,但
strip.position
已记录 在开发文档上。An answer for those searching in 2016.
As of
ggplot2
2.0, the switch argument will do this forfacet_grid
orfacet_wrap
:As of ggplot2 2.2.0,
Current docs, are still at 2.1, but
strip.position
is documented on the dev docs.您现在可以使用facet_wrap(~var, strip.position = "bottom"),尽管由于某种原因,这会导致标签位于轴刻度线标签上方,而不是下方(我认为会更有意义),正如您可以从我的图表的一小部分的屏幕截图中看到的
如果您愿意要获得下面的标签,您必须这样做
如下所示: https://github.com/ tidyverse/ggplot2/issues/2622
you can now use
facet_wrap(~var, strip.position = "bottom")
, though for some reason this results in the labels being located above the axis tick mark labels, rather than below (which I think would make more sense), as you can see from my screenshot of a small portion of my graphIf you want to have the label below, you have do to this
As seen here: https://github.com/tidyverse/ggplot2/issues/2622
作为 2024 年 6 月
ggplot2_3.5.1
的更新,switch
选项仍然发生变化:此外,
facet_grid()
函数使用rows = vars()
和cols = vars()
而不是旧的公式表示法。As an update for June 2024 with
ggplot2_3.5.1
, theswitch
option is still changed:Also, the
facet_grid()
function usesrows = vars()
andcols = vars()
rather than the old formula notation.