我可以在ggplot中从上到下更改条形标签的位置吗? [英] can I change the position of the strip label in ggplot from the top to the bottom?
问题描述
我知道这不是一个数据可视化问题,但是老板问了这个问题,所以我需要弄清楚是否有可能。
谢谢! / p>
为2016年搜索者提供的答案。
code> ggplot2 2.0,切换参数将会对 facet_grid
或 facet_wrap
: $ b
默认情况下,标签显示在图的顶部和右侧。如果x,顶部标签将显示在底部。如果y,则右侧标签将显示在左侧。也可设置为两者。
ggplot(...)+ .. 。+ facet_grid(facets,switch =both)
自ggplot2 2.2.0 ,
现在可以使用
strip.position参数将条带自由定位在facet_wrap()
中(弃用switch
目前的文档仍然在2.1,但 strip.position
记录在开发者文档上。
默认情况下,标签显示在图的顶部。使用strip.position可以通过设置
strip.position = c(top,bottom,left,right)
$ b $ pre $ ggplot(...)+ ... + facet_wrap(方面,strip.position =right)
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.
Thanks!
解决方案An answer for those searching in 2016.
As of
ggplot2
2.0, the switch argument will do this forfacet_grid
orfacet_wrap
:By default, the labels are displayed on the top and right of the plot. If "x", the top labels will be displayed to the bottom. If "y", the right-hand side labels will be displayed to the left. Can also be set to "both".
ggplot(...) + ... + facet_grid(facets, switch="both")
As of ggplot2 2.2.0,
Strips can now be freely positioned in
facet_wrap()
using the strip.position argument (deprecatesswitch
).Current docs, are still at 2.1, but
strip.position
is documented on the dev docs.By default, the labels are displayed on the top of the plot. Using strip.position it is possible to place the labels on either of the four sides by setting
strip.position = c("top", "bottom", "left", "right")
ggplot(...) + ... + facet_wrap(facets, strip.position="right")
这篇关于我可以在ggplot中从上到下更改条形标签的位置吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!