missing yearmon labels using ggplot scale_x_yearmon

后端 未结 2 728
既然无缘
既然无缘 2021-01-16 07:51

I have grouped some data by month and year, converted to yearmon using zoo and am now plotting it in ggplot. Does anyone know why one of the ticklabels are missing and there

2条回答
  •  一生所求
    2021-01-16 08:06

    I think scale_x_yearmon was meant for xy plots as it calls scale_x_continuous but we can just call scale_x_continuous ourselves like this (only the line marked ## is changed):

    ggplot(df, aes(x = dates, y = values)) + 
     geom_bar(position="dodge", stat="identity") +      
     theme_light() +
     xlab('Month') +
     ylab('values')+ 
     scale_x_continuous(breaks=as.numeric(df$dates), labels=format(df$dates,"%Y %m")) ##
    

提交回复
热议问题