ggsmooth {ggplot} | R Documentation

## Grob function: smooth

### Description

Add a smooth line to a plot

### Usage

    ggsmooth(plot = .PLOT, aesthetics=list(), ..., data=plot$data)

### 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

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

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:

- x: x position (required)
- y: y position (required)
- size: size of the point, in mm (see `scsize)`
- colour: point colour (see `sccolour)`

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:

- method: smoothing method (function) to use
- formula: formula to use in smoothing function
- se: display one standard error on either side of fit? (true by default)
- other arguments are passed to smoothing function

### Author(s)

Hadley Wickham <h.wickham@gmail.com>

### Examples

    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))

[Package ggplot version 0.2.2 Index]