【问题标题】:R: ggplot2: change strip.text from "y" axis to "x" axis in faceted plot?R:ggplot2:在多面图中将strip.text从“y”轴更改为“x”轴?
【发布时间】:2015-12-27 16:37:12
【问题描述】:

为了更好的可视化,我需要将分面的条形文本移动到每个分面的顶部。

现在它们在右侧,但我需要它们在顶部。

这是我的代码:

tvs.rangos <- ggplot(tvs , aes(rangos))
tvs.rangos + geom_histogram(aes(fill = marca), width = .7) + labs(title = "Marcas de TV por rangos de precios",
                                                                x = "rango de precios", y = "cantidad de tvs")  +
        facet_grid(ecommerce ~ .) +
        scale_fill_brewer(palette="Set3") +
        theme(axis.text.x = element_text(colour="grey10",size=16,hjust=.5,vjust=.5,face="bold"),
              axis.text.y = element_text(colour="grey10",size=18,,hjust=1,vjust=0,face="plain"),  
              axis.title.x = element_text(colour="grey40",size=12,angle=0,hjust=.5,vjust=0,face="plain"),
              axis.title.y = element_text(colour="grey40",size=12,angle=90,hjust=.5,vjust=.5,face="plain"),
              plot.title = element_text(size = 16,vjust=2),
              legend.title = element_text(colour="grey40", size=16, face="bold"),
              legend.text = element_text(colour="grey10", size=16, face="bold"),
              strip.text.y = element_text(size = 20, angle = 0))

我找到了这个话题:

ggplot2: Using gtable to move strip labels to top of panel for facet_grid

但是,如果有的话,我正在寻找一种更简单的方法。

【问题讨论】:

  • 您能否提供数据(您的对象 tvs.rangos)以便人们更容易提供帮助?
  • 也许您可以尝试使用coord_flipscale_x_reverse,就像他们在这里所做的那样:stackoverflow.com/questions/29504883/…

标签: r ggplot2


【解决方案1】:

如果您正在寻找替代方案,为什么不简单地使用 facet_wrap()。文本将位于每个方面的顶部。我无权访问您的数据集,但这是一个简单的示例

ggplot(data=iris, aes(x=Sepal.Length, y=Sepal.Width)) + geom_point() + facet_wrap(~Species, nrow=3)

【讨论】:

  • 谢谢。你能解释一下为什么我的“facet_grid”方法是错误的吗?何时使用“facet_wrap”,何时使用“facet_grid”?谢谢。
  • 您没有错,但您只是在寻找不同的东西 :-) 一个在顶部,另一个在侧面!并感谢您接受答案!
猜你喜欢
  • 1970-01-01
  • 2021-10-15
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-11-05
相关资源
最近更新 更多