+ is the key to constructing sophisticated ggplot2 graphics. It
allows you to start simple, then get more and more complex, checking your
work at each step.
1 2 3 4
## S3 method for class 'gg' e1 + e2 e1 %+% e2
An object of class
A plot component, as described below.
You can add any of the following types of objects:
aes() objects replaces the default aesthetics.
A layer created by a
stat_ function adds
scale overrides the existing scale.
theme modifies the current theme.
coord overrides current coordinate system.
facet specificatio override current faceting.
To replace the current default data frame, you must use
due to S3 method precedence issues.
You can also supply a list, in which case each element of the list will be added in turn.
1 2 3 4 5 6 7 8 9
base <- ggplot(mpg, aes(displ, hwy)) + geom_point() base + geom_smooth() # To override the data, you must use %+% base %+% subset(mpg, fl == "p") # Alternatively, you can add multiple components with a list. # This can be useful to return from a function. base + list(subset(mpg, fl == "p"), geom_smooth())
`geom_smooth()` using method = 'loess' `geom_smooth()` using method = 'loess'
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.