【问题标题】:Remove all of x axis labels in ggplot [duplicate]删除ggplot中的所有x轴标签[重复]
【发布时间】:2016-05-07 13:31:51
【问题描述】:

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

在下图中,我想要“清晰”并删除所有刻度线和标签,以便只保留轴线。

示例 ggplot

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

ggplot图表:

所需图表:

【问题讨论】:

    标签: r ggplot2


    【解决方案1】:

    您必须在需要删除的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())
    

    【讨论】:

    • 有没有办法摆脱整个轴,比如 base R 中的axes = FALSE。这是很多工作。
    • @jtr13,你可以使用theme_void()来摆脱一切:ggplot(data = diamonds, mapping = aes(x = clarity)) + geom_bar(aes(fill = cut)) + theme_void()
    • 参考:ggplot doc
    • 使用scale_x_discrete 和labs 有一种非常“ggplot”的方式:ggplot(data = diamonds, mapping = aes(x = clarity)) + geom_bar(aes(fill = cut)) + scale_x_discrete(labels = NULL, breaks = NULL) + labs(x = "")
    猜你喜欢
    • 2018-05-19
    • 1970-01-01
    • 2021-11-30
    • 2020-10-24
    • 1970-01-01
    • 1970-01-01
    • 2019-08-25
    • 1970-01-01
    • 2020-05-21
    相关资源
    最近更新 更多