简体   繁体   English

如何在ggplot2中独立控制y轴刻度和x轴刻度?

[英]How can I control y-axis ticks and x-axis ticks independently in ggplot2?

I want to remove axis ticks from the x-axis without removing them from the y-axis. 我想从x轴移除轴刻度而不从y轴移除它们。

Right now, I can get both to be removed using: 现在,我可以使用以下方法删除它们:

axis.ticks=theme_blank()

For instance: 例如:

# Generate data
c <- ggplot(mtcars, aes(factor(cyl)))

c + geom_bar()+opts(axis.ticks=theme_blank())
#c + geom_bar(width=.5)
#c + geom_bar() + coord_flip()
#c + geom_bar(fill="white", colour="darkgreen")

But I don't know how to control them independently. 但我不知道如何独立控制它们。

To remove just x axis ticks use axis.ticks.x= 要仅删除x轴刻度,请使用axis.ticks.x=

 c <- ggplot(mtcars, aes(factor(cyl))) 
 c + geom_bar()+opts(axis.ticks.x=theme_blank())

For the latest ggplot2 version (0.9.3) instead of opts() use theme() and element_blank() . 对于最新的ggplot2版本(0.9.3)而不是opts()使用theme()element_blank()

 c <- ggplot(mtcars, aes(factor(cyl))) 
 c + geom_bar()+theme(axis.ticks.x=element_blank())

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM