简体   繁体   English

geom_line() 在使用分组数据的 ggplot 中不起作用

[英]geom_line() not working in ggplot using grouped data

I am trying to compare the average number of reviews an android app receives based on the month it was last updated.我正在尝试根据上次更新的月份比较 Android 应用收到的平均评论数。 Here is my code / geom_point graph:这是我的代码/ geom_point 图:

# Creating a group-means data set
gd <- appset %>% group_by(Month) %>% summarize(Reviews=mean(Reviews))

ggplot(appset, aes(Month, log(Reviews))) +
geom_point(data=gd) + scale_x_discrete(limits = month.abb)

Scatter Plot散点图

My problem: I have been able to create a scatterplot, but I would like to connect the dots with geom_line() or geom_path(), but instead I keep getting the same scatterplot with vertical lines drawing up from the x-axis through each point.我的问题:我已经能够创建一个散点图,但我想用 geom_line() 或 geom_path() 连接点,但我一直得到相同的散点图,垂直线从 x 轴通过每个点绘制. Here's my code and and image:这是我的代码和图像:

ggplot(appset, aes(Month, log(Reviews))) +
geom_point(data=gd) + geom_line() +
scale_x_discrete(limits = month.abb)

Attempted with geom_line()尝试使用 geom_line()

For future reference:备查:

ggplot(appset, aes(Month, log(Reviews))) +
geom_point(data=gd) + geom_line(data=gd) +
scale_x_discrete(limits = month.abb)

You need to add data=gd to the geom_line call, otherwise the data is inherited from the original ggplot call.需要在geom_line调用中添加data=gd ,否则数据继承自原始 ggplot 调用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM