ogawa ogawa - 22 days ago 7
R Question

How to apply geom_smooth() for every group?

How to apply geom_smooth() for every group ?

under program is use

facet_wrap()
,
so plot every group graph.

I would like to integrate the graph, and get one graph.

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)

Answer

You have to put all your variable in 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)))

enter image description here