Customise x-axis ticks

匿名 (未验证) 提交于 2019-12-03 02:35:01

问题:

I have a very large data frame (2 columns) in terms of records. I have plotted the graph in ggplot2. The X axis is the time and the Y axis is values. Over a specific interval from time 50 to 60, I want to make the ticks increments to be smaller such as (50,51,51,53,...59,60). For the rest of the axis, it is fine to have the ticks incremented by 10. So,I would expect to have X-axis values like :

10,20,30,40,50,51,52,53,54,55,56,57,58,58,60,70,80,90,..190,200. 

I know, I can modify the ticks through scale_x_continuous by using breaks and minor_breaks. However, I'm not getting the expected output. Here is my try:(note: have created data just for example as my data is very large).

data: ----- x

Based on the suggestion below, the only problem now is the values of X-axis during the interval between 50-60 is not clearly appeared.

Any suggestions to make it clear!!

回答1:

With argument minor_breaks= you set the minor gridlines. To set numbers under the x axis all number should be provided with argument breaks=.

ggplot(data=df, aes(x,y))+geom_line(size=1.6)+    scale_x_continuous(breaks=c(10,20,30,40,seq(50,60,by=1),seq(70,200,10)),           minor_breaks=seq(50,60,by=1)) 

For the second problem - you set axis.ticks.x=element_line(size=5) inside theme() - that makes your axis ticks wider so they appear as small rectangles. If you want to make axis ticks longer use axis.ticks.length=.

+theme(axis.ticks.length=unit(0.5,"cm")) 


标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!