stat_contourstat_contour(mapping=NULL, data=NULL, geom="path", position="identity", na.rm=FALSE, ...)
Contours of 3d data
This page describes stat_contour, see layer and qplot for how to create a complete plot from individual components.
What do you think of the documentation? Please let me know by filling out this short online survey.
The following aesthetics can be used with stat_contour. Aesthetics are mapped to variables in the data with the aes function: stat_contour(aes(x = var)). Note that you do not need quotes around the variable name.
Scales control how the variable is mapped to the aesthetic and are listed after each aesthetic.
| Aesthetic | Default | Related scales |
|---|---|---|
| x | required | continuous, date, datetime, discrete |
| y | required | continuous, date, datetime, discrete |
| z | required | discrete |
| group | ..piece.. | |
| order | ..level.. |
Layers are divided into groups by the group aesthetic. By default this is set to the interaction of all categorical variables present in the plot.
To use these variables in an aesthetic mapping, you need to surrond them with .., like aes(x = ..output..). This tells ggplot that the variable isn't the original dataset, but has been created by the statistic.
level, z value of contourParameters control the appearance of the stat. In addition to the parameters listed below (if any), any aesthetic can be used as a parameter, in which case it will override any aesthetic mapping.
bins: NULLbinwidth: NULLbreaks: numeric vector indicating where breaks should liena.rm: NULL...: ignored This function returns a layer object.
> # Generate data > volcano3d <- melt(volcano) > names(volcano3d) <- c("x", "y", "z") > > # Basic plot > v <- ggplot(volcano3d, aes(x, y, z = z)) > v + stat_contour()> > # Setting bins creates evenly spaced contours in the range of the data > v + stat_contour(bins = 2)
> v + stat_contour(bins = 10)
> > # Setting binwidth does the same thing, parameterised by the distance > # between contours > v + stat_contour(binwidth = 2)
> v + stat_contour(binwidth = 5)
> v + stat_contour(binwidth = 10)
> v + stat_contour(binwidth = 2, size = 0.5, colour = "grey50") + + stat_contour(binwidth = 10, size = 1)
> > # Add aesthetic mappings > v + stat_contour(aes(size = ..level..))
> v + stat_contour(aes(colour = ..level..))
> > # Change scale > v + stat_contour(aes(colour = ..level..), size = 2) + + scale_colour_gradient(low = "brown", high = "white")
> > # Set aesthetics to fixed value > v + stat_contour(colour = "red")
> v + stat_contour(size = 2, linetype = 4)
> > # Try different geoms > v + stat_contour(geom="polygon", aes(fill=..level..))
> v + geom_tile(aes(fill = z)) + stat_contour()
> > # Use qplot instead > qplot(x, y, z, data = volcano3d, geom = "contour")
> qplot(x, y, z, data = volcano3d, stat = "contour", geom = "path")
![]()
What do you think of the documentation? Please let me know by filling out this short online survey.