我想绘制多个方面,每个方面有几行。在每个方面,对于一组线图,我想展示一种平滑线,表示给定特定方面中所有这些线的总趋势。有人知道是否有可能吗?我到目前为止尝试过这样的事情:
ggplot(data = mydata, aes(x = x, y = y, group = group)) + geom_line('GRAY') + facet_wrap(~ class) + geom_smooth('loess')
(see figure)
但是,我观察到的是每个方面内每个线图的另一条线,而不是每个方面内的一条线。
提前致谢
这是iris数据集的示例:
gg <- ggplot(iris, aes(x = Sepal.Length, y = Petal.Length)) +
geom_line() +
facet_wrap(~ Species) +
geom_smooth(data = within(iris, Species <- NULL), fill = "red")
gg
... +
geom_smooth(aes(group=class), method="lm") +
...
应该做一行pr。面