我需要移除X轴上的所有内容,包括标签和刻度线,以便只标记Y轴。我该怎么做?在下面的图像中,我想要删除'clarity'和所有刻度线和标签,以便只剩下坐标轴线。样例 ggplotdata(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
。这是一项很大的工作。 - jtr13ggplot(data = diamonds, mapping = aes(x = clarity)) + geom_bar(aes(fill = cut)) + theme_void()
- Augusto Fadelscale_x_discrete
和labs
来实现:ggplot(data = diamonds, mapping = aes(x = clarity)) + geom_bar(aes(fill = cut)) + scale_x_discrete(labels = NULL, breaks = NULL) + labs(x = "")
。这与IT有关。 - Will Pikelabs(x = NULL)
可以完全移除用于标签的边距。 - Breaking Waves