如何为每个组申请geom_smooth()

下面的代码使用facet_wrap(),因此在单独的图中绘制每个组。
我想整合图表,并获得一张图表。

ggplot(data = iris, aes(x = Sepal.Length,  y = Petal.Length)) +
  geom_point(aes(color = Species)) +
  geom_smooth(method = "nls", formula = y ~ a * x + b, se = F,
              method.args = list(start = list(a = 0.1, b = 0.1))) +
  facet_wrap(~ Species)

最佳答案

您必须将所有变量放在ggplot aes()中:

ggplot(data = iris, aes(x = Sepal.Length,  y = Petal.Length, color = Species)) +
  geom_point() +
  geom_smooth(method = "nls", formula = y ~ a * x + b, se = F,
              method.args = list(start = list(a = 0.1, b = 0.1)))


r - 如何为每个组应用geom_smooth()?-LMLPHP

关于r - 如何为每个组应用geom_smooth()?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/40600824/

10-11 09:30