create specific date range in ggplot2 ( scale_x_date)

后端 未结 1 450
广开言路
广开言路 2021-01-06 05:14

Hi i have yearly data from 2010 to 2050. i am trying make line plot so that my x-axis start from 2010 and end in 2050 showing 5 years interval i e i want x-axis break as ( 2

相关标签:
1条回答
  • 2021-01-06 05:36

    If you know exactly where you want your break values to be, then just tell ggplot

    plot1<- ggplot(test, aes(yr, y=value)) +
    geom_line()+
    scale_x_date(breaks = seq(as.Date("2010-01-01"), as.Date("2050-12-31"), by="5 years"), 
        labels=date_format("%Y")) +
    scale_y_continuous(breaks=seq(-4,6, by=1))
    

    enter image description here

    0 讨论(0)
提交回复
热议问题