Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
477 views
in Technique[技术] by (71.8m points)

r - How to apply geom_smooth() for every group?

How can I apply geom_smooth() for every group ?

The code below uses facet_wrap(), so plots every group in a separate 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)
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...