Learn R Programming

ggplot2 (version 2.0.0)

layer: Create a new layer

Description

Create a new layer

Usage

layer(geom = NULL, stat = NULL, data = NULL, mapping = NULL,
  position = NULL, params = list(), inherit.aes = TRUE, subset = NULL,
  show.legend = NA)

Arguments

geom, stat, position
Geom, stat and position adjustment to use in this layer. Can either be the name of a ggproto object, or the object itself.
data
A data frame. If specified, overrides the default data frame defined at the top level of the plot.
mapping
Set of aesthetic mappings created by aes or aes_. If specified and inherit.aes = TRUE (the default), is combined with the default mapping at the top le
params
Additional parameters to the geom and stat.
inherit.aes
If FALSE, overrides the default aesthetics, rather than combining with them. This is most useful for helper functions that define both data and aesthetics and shouldn't inherit behaviour from the default plot specification, e.g.
subset
DEPRECATED. An older way of subsetting the dataset used in a layer.
show.legend
logical. Should this layer be included in the legends? NA, the default, includes if any aesthetics are mapped. FALSE never includes, and TRUE always includes.

Examples

Run this code
# geom calls are just a short cut for layer
ggplot(mpg, aes(displ, hwy)) + geom_point()
# shortcut for
ggplot(mpg, aes(displ, hwy)) +
  layer(geom = "point", stat = "identity", position = "identity",
    params = list(na.rm = FALSE)
  )

Run the code above in your browser using DataLab