Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

geom_smooth() what are the methods available?

Tags:

r

ggplot2

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) 
like image 473
nzcoops Avatar asked Aug 10 '11 03:08

nzcoops


People also ask

What does Geom_smooth do in R?

Key R function: geom_smooth() for adding smoothed conditional means / regression line. Key arguments: color , size and linetype : Change the line color, size and type. fill : Change the fill color of the confidence region.

What is method GAM in Geom_smooth?

gam smoothing is called generalized additive mode smoothing. It works with a large number of points. We specify this by adding method="gam", formula = y~s(x) into the geom_smooth() layer.

What does Geom_smooth () using formula YX mean?

The warning geom_smooth() using formula 'y ~ x' is not an error. Since you did not supply a formula for the fit, geom_smooth assumed y ~ x, which is just a linear relationship between x and y.

What does Geom_smooth SE False do in R?

If FALSE , the default, missing values are removed with a warning. If TRUE , missing values are silently removed. The orientation of the layer. The default ( NA ) automatically determines the orientation from the aesthetic mapping.


1 Answers

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.

like image 154
nzcoops Avatar answered Sep 19 '22 20:09

nzcoops