View source: R/gizmo-density.R
gizmo_density | R Documentation |
This guide displays a kernel density estimate (KDE) of the aesthetic. If the
aesthetic is colour
or fill
, the shape will reflect this.
gizmo_density(
key = waiver(),
density = NULL,
density.args = list(),
density.fun = stats::density,
just = 0.5,
oob = "keep",
alpha = NA,
theme = NULL,
position = waiver(),
direction = NULL
)
key |
A sequence key or binned key specification. Internally defaults to a sequence key when the scale is continuous and a binned key when the scale is binned. |
density |
One of the following:
|
density.args |
A |
density.fun |
A |
just |
A |
oob |
An out-of-bounds handling function that affects the cap colour. Can be one of the following:
|
alpha |
A |
theme |
A |
position |
A |
direction |
A |
Non-finite values such as NA
and NaN
are ignored while infinite values
such as -Inf
and Inf
are squished to the limits.
A <GizmoDensity>
object.
Other gizmos:
gizmo_barcap()
,
gizmo_grob()
,
gizmo_histogram()
,
gizmo_stepcap()
# A standard plot
p <- ggplot(mpg, aes(displ, hwy, colour = cty)) +
geom_point() +
scale_colour_viridis_c()
# Density from plot data
p + guides(colour = gizmo_density())
# Using bins instead of gradient
p + guides(colour = gizmo_density("bins"))
# Providing custom values to compute density of
p + guides(colour = gizmo_density(density = runif(1000, min = 5, max = 35)))
# Providing a precomputed density
p + guides(colour = gizmo_density(density = density(mpg$cty, adjust = 0.5)))
# Alternatively, parameters may be passed through density.args
p + guides(colour = gizmo_density(density.args = list(adjust = 0.5)))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.