gizmo_density {legendry} | R Documentation |
Guide gizmo: kernel density estimate
Description
This guide displays a kernel density estimate (KDE) of the aesthetic. If the
aesthetic is colour
or fill
, the shape will reflect this.
Usage
gizmo_density(
key = "sequence",
density = NULL,
density.args = list(),
density.fun = stats::density,
just = 0.5,
oob = "keep",
alpha = NA,
theme = NULL,
position = waiver(),
direction = NULL
)
Arguments
key |
A sequence key or binned key specification. |
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 |
Details
Non-finite values such as NA
and NaN
are ignored while infinite values
such as -Inf
and Inf
are squished to the limits.
Value
A <GizmoDensity>
object.
See Also
Other gizmos:
gizmo_barcap()
,
gizmo_grob()
,
gizmo_histogram()
,
gizmo_stepcap()
Examples
# 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)))