ggplot {ggplot2} | R Documentation |
ggplot()
initializes a ggplot object. It can be used to declare
the input data frame for a graphic and to specify the set of
plot aesthetics intended to be common throughout all subsequent
layers unless specifically overridden.
ggplot(
data = NULL,
mapping = Call "aes"(),
colorSet = "paper",
... = NULL);
ggplot()
is used to construct the initial plot object, and is
almost always followed by + to add component to the plot. There
are three common ways to invoke ggplot()
:
+ ggplot(df, aes(x, y, other aesthetics))
+ ggplot(df)
+ ggplot()
The first method Is recommended If all layers use the same data
And the same Set Of aesthetics, although this method can also be
used To add a layer Using data from another data frame. See the
first example below. The second method specifies the Default
data frame To use For the plot, but no aesthetics are defined up
front. This Is useful When one data frame Is used predominantly
As layers are added, but the aesthetics may vary from one layer
To another. The third method initializes a skeleton ggplot Object
which Is fleshed out As layers are added. This method Is useful
When multiple data frames are used To produce different layers,
As Is often the Case In complex graphics.
a ggplot base layer object which can be rendering to graphics by
invoke the plot
function.