【问题标题】:ggplot with overlapping X axis label具有重叠 X 轴标签的 ggplot
【发布时间】:2017-03-04 18:50:04
【问题描述】:

我有一个看起来像这样的 ggplot。

 p2=ggplot(data=data1, aes(x=ID, y = value)) + 
 geom_line(group=1,color='steelblue', size=2) +  facet_wrap(~variable)+theme_economist() 


p2=p2+theme(text = element_text(size=10), axis.text.x = element_text(angle=90, hjust=1))


p2

问题是,我在 X 轴上得到了重叠的 X 标签。有没有办法获得不重叠的 X 轴标签。

【问题讨论】:

  • 您需要显示所有标签吗?如果不是,scale_x_discrete 可以选择限制显示的集合。
  • 嗨 @RichardTelford 是的,我需要在 X 轴上显示所有值,因为它们是唯一的 ID

标签: r ggplot2


【解决方案1】:

ggplot2 3.3.0 版很好地解决了这个问题。 scale_x_discrete(guide = guide_axis(n.dodge=3))

这是example

【讨论】:

    【解决方案2】:

    试试+ coord_flip()——标签可能更适合并且在 y 轴上更清晰。

    【讨论】:

      【解决方案3】:

      怎么样?

      theme(axis.text.x = element_text(angle =45, hjust = 1))
      

      【讨论】:

        猜你喜欢
        • 2018-05-19
        • 1970-01-01
        • 1970-01-01
        • 2014-04-30
        • 2016-05-07
        • 2017-06-03
        • 1970-01-01
        • 1970-01-01
        • 2019-08-25
        相关资源
        最近更新 更多