Creating month-sized bins with ggplot2 in r

前端 未结 1 1062
走了就别回头了
走了就别回头了 2021-01-12 03:23

I have a set of data that I need to plot in ggplot2. It is time ordered. This is the data set:

testset <- data.table(Date=as.Date(c(\"2013-07-02\",\"2013-         


        
相关标签:
1条回答
  • 2021-01-12 04:12

    You can use the yearmon class from the zoo package. There is a scale_..._yearmon function in the zoo package that works similarly to the scale_x_date function in the scales package

    library(zoo)
    ggplot(testset, aes(as.yearmon(Date), fill=Action)) + 
      geom_bar(position = position_dodge(width  = 1/12), 
               binwidth=1/12, colour='black') + 
      scale_x_yearmon()
    

    enter image description here

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