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

时间:2017-08-02 19:28:30

标签: r ggplot2

在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))

enter image description here 我不想要那么多滴答标签,只有一小部分,有没有办法做到这一点?

我也尝试设置binwidth而不是中断和设置标签,但我收到了错误消息Breaks and Labels are different lengths

1 个答案:

答案 0 :(得分:-1)

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

然后运行你的代码。