R条形图根据日期计算数据
R bar chart count data based on dates
我有一个由文章文本及其具体日期组成的数据框。我想绘制每月发布的新闻文章数量。
我如何:
- 按月份而不是特定日期汇总文章
- 使用 ggplot 以条形图格式绘制每月发表的文章数量?
articledf <- data.frame(articles = c("on April 3rd","Happening now", "This happened today", "Today, this happened", "Yesterday, a car crashed into a building", "Tomorrow, this will take place"))
articledf$date <- as.Date(c("18/04/2021","21/04/2021","28/05/2021", "30/05/2021","30/05/2021","30/05/2021"), format = "%d/%m/%y")
非常感谢!
使用 lubridate 包中的月份。
df$month = month(df$date)
ggplot(df, aes(x = month)) + geom_bar()
我有一个由文章文本及其具体日期组成的数据框。我想绘制每月发布的新闻文章数量。
我如何:
- 按月份而不是特定日期汇总文章
- 使用 ggplot 以条形图格式绘制每月发表的文章数量?
articledf <- data.frame(articles = c("on April 3rd","Happening now", "This happened today", "Today, this happened", "Yesterday, a car crashed into a building", "Tomorrow, this will take place"))
articledf$date <- as.Date(c("18/04/2021","21/04/2021","28/05/2021", "30/05/2021","30/05/2021","30/05/2021"), format = "%d/%m/%y")
非常感谢!
使用 lubridate 包中的月份。
df$month = month(df$date)
ggplot(df, aes(x = month)) + geom_bar()