How to adjust time scale axis for ggplot histogram

前端 未结 1 1882
抹茶落季
抹茶落季 2021-02-05 20:56

I am working with a data frame where one of the columns consists of POSIXct date-time values. I am trying to plot a histogram of these timestamps using ggplo

相关标签:
1条回答
  • 2021-02-05 21:23
    1. The binwidth is measured in seconds, so to bin per week set binwidth=7*24*60*60.
    2. Limits can be given as a vector of 2 POSIXct objects.

    An example:

    y<-as.POSIXct('1970/01/01')+cumsum(rnorm(100,mean=24*60*60,sd=24*60*60))
    p<-qplot(y,binwidth=7*24*60*60,fill=I('steelblue'),col=I('black'))
    p<-p+scale_x_datetime(major="1 week",
                          minor="1 days",
                          format="%e/%m/%Y",
                          limits=c(as.POSIXct('1970/02/01'),
                                   as.POSIXct('1970/03/31')))
    print(p)
    
    0 讨论(0)
提交回复
热议问题