我正在使用一个自行车共享数据集,我将其命名为";all_rides_v02";。
相关列为day_of_the_week(不言自明(和member_casual
$ ride_id <chr> "99103BB87CC6C1BB", "EAFCCCFB0A3FC5A1", "9EF4F46C57AD23…
$ rideable_type <chr> "electric_bike", "electric_bike", "electric_bike", "ele…
$ member_casual <chr> "member", "member", "member", "member", "member", "memb…
$ date <date> 2021-08-10, 2021-08-10, 2021-08-21, 2021-08-21, 2021-0…
$ month <chr> "08", "08", "08", "08", "08", "08", "08", "08", "08", "…
$ day <chr> "10", "10", "21", "21", "19", "19", "19", "13", "17", "…
$ year <chr> "21", "21", "21", "21", "21", "21", "21", "21", "21", "…
$ day_of_the_week <chr> "Tuesday", "Tuesday", "Saturday", "Saturday", "Thursday…
我试图创建一个具有多(两(条线的折线图,其中一条线表示";会员乘车";而另一行是"0";休闲骑行";。x轴将是星期几,y轴将是骑行次数(未明确记录在数据集中(。
有什么建议吗?
ggplot(data=all_rides_v02)+
geom_line(aes(x=day_of_the_week, y=value, color=as.factor(member_casual)))+
geom_line()+
geom_point()
我可能会发布十几种我做得不对的方法。我一直遇到的主要问题是,我不知道如何解决没有";y值";。我只希望它是乘车次数。
您需要首先聚合数据。如果你正在使用完整的tidyverse,你可以去
all_rides_v02 %>%
group_by(day_of_the_week, member_casual) %>%
summarise(count = n()) %>%
mutate(day_of_the_week = factor(day_of_the_week, levels = c("Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday")) %>%
ggplot() +
geom_line(aes(x = day_of_the_week, y = count, colour = member_casual))