scale_thickness | R Documentation |
This ggplot2 scale linearly scales all thickness
values of geoms
that support the thickness
aesthetic (such as geom_slabinterval()
). It
can be used to align the thickness
scales across multiple geoms (by default,
thickness
is normalized on a per-geom level instead of as a global scale).
For a comprehensive discussion and examples of slab scaling and normalization,
see the thickness
scale article.
scale_thickness_shared(
name = waiver(),
breaks = waiver(),
labels = waiver(),
limits = function(l) c(min(0, l[[1]]), l[[2]]),
renormalize = FALSE,
oob = scales::oob_keep,
guide = "none",
...
)
scale_thickness_identity(..., guide = "none")
thickness(x = double(), lower = NA_real_, upper = NA_real_)
By default, normalization/scaling of slab thicknesses is controlled by geometries,
not by a ggplot2 scale function. This allows various functionality not
otherwise possible, such as (1) allowing different geometries to have different
thickness scales and (2) allowing the user to control at what level of aggregation
(panels, groups, the entire plot, etc) thickness scaling is done via the normalize
parameter to geom_slabinterval()
.
However, this default approach has one drawback: two different geoms will always
have their own scaling of thickness
. scale_thickness_shared()
offers an
alternative approach: when added to a chart, all geoms will use the same
thickness
scale, and geom-level normalization (via their normalize
parameters)
is ignored. This is achieved by "marking" thickness values as already
normalized by wrapping them in the thickness()
data type (this can be
disabled by setting renormalize = TRUE
).
thickness()
is used by scale_thickness_shared()
to create numeric()
-like
objects marked as being in units of slab "thickness". Unlike regular numeric()
s,
thickness()
values mapped onto the thickness
aesthetic are not rescaled by
scale_thickness_shared()
or geom_slabinterval()
. In most cases thickness()
is not useful directly; though it can be used to mark values that should not be
rescaled—see the definitions of stat_ccdfinterval()
and stat_gradientinterval()
for some usages.
Note: while a slightly more typical name for scale_thickness_shared()
might
be scale_thickness_continuous()
, the latter name would cause this scale
to be applied to all thickness
aesthetics by default according to the rules
ggplot2 uses to find default scales. Thus, to retain the usual behavior
of stat_slabinterval()
(per-geom normalization of thickness
), this scale
is called scale_thickness_shared()
.
A ggplot2::Scale representing a scale for the thickness
aesthetic for ggdist
geoms. Can be added to a ggplot()
object.
Matthew Kay
The thickness
aesthetic of geom_slabinterval()
.
Other ggdist scales:
scale_colour_ramp
,
scale_side_mirrored()
,
sub-geometry-scales
library(distributional)
library(ggplot2)
library(dplyr)
prior_post = data.frame(
prior = dist_normal(0, 1),
posterior = dist_normal(0.1, 0.5)
)
# By default, separate geoms have their own thickness scales, which means
# distributions plotted using two separate geoms will not have their slab
# functions drawn on the same scale (thus here, the two distributions have
# different areas under their density curves):
prior_post %>%
ggplot() +
stat_halfeye(aes(xdist = posterior)) +
stat_slab(aes(xdist = prior), fill = NA, color = "red")
# For this kind of prior/posterior chart, it makes more sense to have the
# densities on the same scale; thus, the areas under both would be the same.
# We can do that using scale_thickness_shared():
prior_post %>%
ggplot() +
stat_halfeye(aes(xdist = posterior)) +
stat_slab(aes(xdist = prior), fill = NA, color = "#e41a1c") +
scale_thickness_shared()
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.