首页 文章

删除ggplot中的所有x轴标签[重复]

提问于
浏览
131

这个问题在这里已有答案:

我需要删除x轴上的所有内容,包括标签和刻度线,以便只标记y轴 . 我该怎么办?

在下图中,我希望“清晰度”,并删除所有刻度线和标签,以便只有轴线 .

Sample ggplot

data(diamonds)
ggplot(data = diamonds, mapping = aes(x = clarity)) + geom_bar(aes(fill = cut))

ggplot Chart:

enter image description here

Desired chart:

enter image description here

1 回答

  • 305

    您必须在需要删除的 theme() 元素中设置为 element_blank()

    ggplot(data = diamonds, mapping = aes(x = clarity)) + geom_bar(aes(fill = cut))+
      theme(axis.title.x=element_blank(),
            axis.text.x=element_blank(),
            axis.ticks.x=element_blank())
    

相关问题