ggsmooth: Grob function: smooth

Description Usage Arguments Details Examples

View source: R/grobs-complex.r

Description

This grob adds a smoother to the graphic to aid the eye in seeing important patterns, especially when there is a lot of overplotting.

Usage

1
ggsmooth(plot, aesthetics = list(), ..., data = NULL)

Arguments

plot

the plot object to modify

aesthetics

named list of aesthetic mappings, see details for more information

...

other options, see details for more information

data

data source, if not specified the plot default will be used

Details

You can customise this very freely, firstly by choosing the function used to fit the smoother (eg. loess, lm, rlm, gam, glm) and the formula used to related the y and x values (eg. y ~ x, y ~ poly(x,3)).

This smoother is automatically restricted to the range of the data. If you want to perform predictions (or fit more complicated variabels with covariates) then you should fit the model and plot the predicted results.

Aesthetic mappings that this grob function understands:

These can be specified in the plot defaults (see ggplot) or in the aesthetics argument. If you want to modify the position of the points or any axis options, you will need to add a position scale to the plot. These functions start with ps, eg. pscontinuous or pscategorical

Other options:

Examples

1
2
3
4
5
6
p <- ggpoint(ggplot(mtcars, aesthetics=list(y=wt, x=qsec)))
ggsmooth(p)
ggsmooth(p, span=0.9)
ggsmooth(p, method=lm)
ggsmooth(p, method=lm, formula = y~splines::ns(x,3))
ggsmooth(p, method=MASS::rlm, formula = y~splines::ns(x,3))

hadley/ggplot1 documentation built on Aug. 19, 2019, 2:42 p.m.