How to not show all labels on ggplot axis?

后端 未结 4 1336
自闭症患者
自闭症患者 2020-12-09 02:12

I\'m trying to using ggplot2 to plot this: But as you can see on the x axis you can\'t read anything...

So how can I show on the x axis the value every

4条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-09 02:57

    The other answers have covered the case where your dates are numerical years, but if (as @Gregor notes) your dates are actual Date objects, it's a lot easier:

    scale_x_date(name = 'My date axis title', date_breaks = '20 years',
            date_labels = '%Y')
    

    With scale_date, you can control the breaks with intuitive language and the labelling with (hopefully) familiar strptime notation.

提交回复
热议问题