【发布时间】:2016-05-07 13:31:51
【问题描述】:
我需要删除 x 轴上的所有内容,包括标签和刻度线,以便只标记 y 轴。我该怎么做?
在下图中,我想要“清晰”并删除所有刻度线和标签,以便只保留轴线。
示例 ggplot
data(diamonds)
ggplot(data = diamonds, mapping = aes(x = clarity)) + geom_bar(aes(fill = cut))
ggplot图表:
所需图表:
【问题讨论】:
我需要删除 x 轴上的所有内容,包括标签和刻度线,以便只标记 y 轴。我该怎么做?
在下图中,我想要“清晰”并删除所有刻度线和标签,以便只保留轴线。
示例 ggplot
data(diamonds)
ggplot(data = diamonds, mapping = aes(x = clarity)) + geom_bar(aes(fill = cut))
ggplot图表:
所需图表:
【问题讨论】:
您必须在需要删除的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())
【讨论】:
axes = FALSE。这是很多工作。
ggplot(data = diamonds, mapping = aes(x = clarity)) + geom_bar(aes(fill = cut)) + theme_void()
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 = "")