geom_smooth() what are the methods available?

RGgplot2

R Problem Overview


I'm using geom_smooth() from ggplot2.

In Hadley Wickham's book ("ggplot2 - Elegant Graphics for Data Analysis") there is an example (page 51), where method="lm" is used. In the online manual there is no talk of the method argument. I see other Google results (and questions here) of people using method='loess'.

Is there a an exhaustive list somewhere that explains the options?

From what I can see, 'lm' draws a straight line, and 'loess' draws a very smooth curve. I assume there are others that draw more of a jagged line between reference points?

The se argument from the example also isn't in the help or online documentation.

FWIW here is my code.

p <- ggplot(output8, aes(age, myoutcome, group=id, colour=year_diag_cat2)) +
  geom_line() + scale_y_continuous(limits = c(lwr,upr))
p + geom_smooth(aes(group=year_diag_cat2), method="loess", size=2, se=F)

R Solutions


Solution 1 - R

Sometimes it's asking the question that makes the answer jump out. The methods and extra arguments are listed on the ggplot2 wiki stat_smooth page.

Which is alluded to on the geom_smooth() page with:

> "See stat_smooth for examples of using built in model fitting if you > need some more flexible, this example shows you how to plot the fits > from any model of your choosing".

It's not the first time I've seen arguments in examples for ggplot graphs that aren't specifically in the function. It does make it tough to work out the scope of each function, or maybe I am yet to stumble upon a magic explicit list that says what will and will not work within each function.

Solution 2 - R

The method argument specifies the parameter of the smooth statistic. You can see stat_smooth for the list of all possible arguments to the method argument.

Solution 3 - R

The se argument from the example also isn't in the help or online documentation.

When 'se' in geom_smooth is set 'FALSE', the error shading region is not visible

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionnzcoopsView Question on Stackoverflow
Solution 1 - RnzcoopsView Answer on Stackoverflow
Solution 2 - RwespiserAView Answer on Stackoverflow
Solution 3 - RRAMYA HARIHARANView Answer on Stackoverflow