How can I create a histogram from aggregated data in R?

前端 未结 4 1618
一向
一向 2020-12-10 05:30

I have a data frame that has a format like the following:

Month       Frequency
2007-08     2
2010-11     5
2011-01     43
2011-02     52
2011-03     31
2011         


        
4条回答
  •  鱼传尺愫
    2020-12-10 06:18

    take a gander at ggplot2.

    if you data is in a data.frame called df:

    ggplot(df,aes(x=Month,y=Frequency))+geom_bar(stat='identity')
    

    or if you want continuous time:

    df$Month<-as.POSIXct(paste(df$Month, '01', sep='-'),format='%Y-%m-%d')
    ggplot(df,aes(x=Month,y=Frequency))+geom_bar(stat='identity')
    

提交回复
热议问题