Description Usage Arguments Computed variables Examples
View source: R/stat-density-grid.R
Generate 2d kernel density estimates
1 2 3 4 |
mapping |
Set of aesthetic mappings created by |
data |
The data to be displayed in this layer. There are three options: If A A |
geom |
The geometric object to use display the data |
position |
Position adjustment, either as a string, or the result of a call to a position adjustment function. |
... |
Other arguments passed on to |
n |
Number of grid points in each direction. |
h |
Bandwidth (vector of length two). If |
bins |
Number of bins for discretization. Has priority
over |
binwidth |
Binwidth used during discretization. |
breaks |
Explicit bin boundaries to use for discretization.
Has priority over both |
na.rm |
If |
show.legend |
logical. Should this layer be included in the legends?
|
inherit.aes |
If |
Same as stat_isolevels()
, with the addition of:
density
the density estimate
ndensity
density estimate scaled to maximum of 1
z
the density estimate, identical to density
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 | library(ggplot2)
# default uses `geom_tile()` for drawing
ggplot(faithful, aes(eruptions, waiting)) +
stat_density_grid(aes(fill = stat(density))) +
geom_point(size = 0.3, color = "white")
# discretized colors
ggplot(faithful, aes(eruptions, waiting)) +
stat_density_grid(aes(fill = stat(zmin))) +
geom_point(size = 0.3, color = "white")
# points
ggplot(faithful, aes(eruptions, waiting)) +
stat_density_grid(
aes(color = stat(density), size = stat(density)),
geom = "point", n = 20, stroke = 0
) +
geom_point(size = 0.75, shape = 21, fill = "white", color = "black")
# contour bands
ggplot(faithful, aes(eruptions, waiting)) +
stat_density_grid(
aes(fill = stat(zmin)), geom = "isobands",
color = "gray70"
) +
geom_point(size = 0.3, color = "white")
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.