stat_density_2d {ggplot2}R Documentation

stat_density_2d

Description

Density estimation, 2D

Usage

stat_density_2d(mapping=NULL, data=NULL, geom="density_2d", position="identity", na.rm=FALSE, ...)

Arguments

mapping mapping between variables and aesthetics generated by aes
data dataset used in this layer, if not specified uses plot dataset
geom geometric used by this layer
position position adjustment used by this layer
na.rm NULL
... ignored

Details

This page describes stat_density_2d, see layer and qplot for how to create a complete plot from individual components.

Value

A layer

Aesthetics

The following aesthetics can be used with stat_density_2d. Aesthetics are mapped to variables in the data with the aes function: stat\_density\_2d(\code{aes}(x = var))

Author(s)

Hadley Wickham, http://had.co.nz/

See Also

Examples

## Not run: 
    m <- ggplot(movies, aes(x=rating, y=length)) + geom_point() + scale_y_continuous(limits=c(1, 500))
    m + geom_density_2d()

    dens <- MASS::kde2d(movies$rating, movies$length, n=100)
    densdf <- data.frame(expand.grid(rating = dens$x, length = dens$y), z=as.vector(dens$z))
    m + geom_contour(aes(z=z), data=densdf)

    m + geom_density_2d() + scale_y_log10()
    m + geom_density_2d() + coord_trans(y="log10")
    
    m + stat_density_2d(aes(fill = ..level..), geom="polygon")

    qplot(rating, length, data=movies, geom=c("point","density2d"), ylim=c(1, 500))
## End(Not run)

[Package ggplot2 version 0.6 Index]