简体   繁体   English

自定义ggplot2中的x轴刻度标签

[英]Customize x-axis tick labels in ggplot2

In ggplot2, I set breaks for a histogram, and the tick labels automatically shows all the breaks, is there a way to customize the showing tick labels? 在ggplot2中,我为直方图设置了中断,刻度标签会自动显示所有中断,是否可以自定义显示的刻度标签?

ggplot(plotdata,aes(x=vals))+
geom_histogram(aes(y=..density..),fill='cyan')+
geom_vline(aes(xintercept=mycrit,color='red'))+
scale_x_continuous(name='',breaks=mybreaks)+
theme(axis.text.x=element_text(angle=90))

在此处输入图片说明 I don't want that many tick labels, only a fraction of them, is there a way to do that? 我不想有那么多刻度线标签,只是其中的一小部分,有没有办法做到这一点?

I also tried setting binwidth instead of breaks and set labels, but I got the error message Breaks and Labels are different lengths 我也尝试设置binwidth而不是breaks和set labels,但是我收到了错误消息Breaks and Labels are different lengths

plotdata$vals <- as.numeric(plotdata$vals)

然后运行您的代码。

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

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