当我试图以这种方式创建散点图时,它会变成一条平坦的线.以下是我的数据的标题: see here个
> head(seattle_thefts)
# A tibble: 6 × 2
report_date_time offense
<dttm> <chr>
1 2020-02-04 13:54:37 Motor Vehicle Theft
2 2020-02-04 13:11:35 Motor Vehicle Theft
3 2020-02-04 09:46:13 Motor Vehicle Theft
4 2020-02-03 16:02:33 Motor Vehicle Theft
5 2020-02-03 15:49:24 Motor Vehicle Theft
6 2020-02-03 13:16:00 Motor Vehicle Theft
如何按月或年 for each 事件创建一段时间的曲线图?例如,一个散点图,它显示在2020年1月,然后2020年2月发生了多少次,等等.
这只会创建一条平坦的直线:
ggplot(seattle_thefts, aes(x = report_date_time, y = offense)) +
geom_point()
我try 将其更改为一个数值:
seattle_thefts$offense <- mutate(seattle_thefts, offense = 1)
seattle_thefts %>%
group_by(month = floor_date(report_date_time, 'month')) %>%
summarize(sum_of_thefts = sum(offense))