【发布时间】:2019-06-12 03:07:34
【问题描述】:
library(tidyverse)
ggplot(mpg, aes(cty, hwy)) +
geom_point() +
facet_grid(year ~ fl) +
geom_hline(yintercept = mean(mpg$hwy))
我希望上面显示的方面中的每个geom_hline() 都是仅包含在该方面中的点的平均值。我认为我可以用(如下)之类的东西来做到这一点。但这不起作用。我很接近,对吧?
library(tidyverse)
ggplot(mpg, aes(cty, hwy)) +
geom_point() +
facet_grid(year ~ fl) +
geom_hline(yintercept = mean(mpg %>% group_by(year, fl)$hwy))
【问题讨论】: