Using lubridate and ggplot2 effectively for date axis

有些话、适合烂在心里 提交于 2019-11-28 13:39:10

One solution could be to add a column to your dataframe that will contain for each row the day and the month in another year (the same for all rows), for example year 2015.

df$days<-as.Date(format(df$date,"%d-%m-2015"),format="%d-%m-%y")

You can then plot using this column as x

library(scales)
ggplot(df, aes(x=days, y=value, color=factor(year(date)))) +
  geom_line()+scale_x_date(labels = date_format("%b"))

Edit: simplified the df$days line

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