1
ggplot(data = wheatX, 
       aes(x = No.of.species, 
       y = Weight.of.weed,
       color = Treatment)) + 
   geom_point(shape = 1) + 
   scale_colour_hue(l = 50) + 
   geom_smooth(method = glm,
               se = FALSE)

This draws a straight line. But the species number will decrease at somepoint. I want to make the line curve. How can I do it. Thanksenter image description here

Daniel
  • 129
  • 9
Mr Good News
  • 121
  • 1
  • 3
  • 15

1 Answers1

1

This is going to depend on what you mean by "smooth"

One thing you can do is apply a loess curve:

ggplot() + ... + stat_smooth(method = "loess", formula = biomass ~ numSpecies, size = 1)

Or you can manually build a polynomial model using the regular lm method:

ggplot() + ... + stat_smooth(method = "lm", formula = biomass ~ numSpecies + I(numSpecies^2), size = 1)

You'll need to figure out the exact model you want to use for the second case, hence what I originally meant by the definition of the term "smooth"

Simon
  • 9,762
  • 15
  • 62
  • 119