Add Units to A Scale
enmeasure_scale.RdCreate a ggplot2::ggproto object that inherits from super, designed
to be a ggplot2 scale for measure objects that adds units to the
aesthetic label.
Arguments
- super
a
ggplot2::Scaleobject returned from ascale_*()function likeggplot2::scale_x_continuous()
Value
A ggplot2::Scale object
Details
make_title() is redefined to return a formula derived from
super$make_title() and units. See plot_math().
transform() is redefined to set units to units(x) and pass a plain
double to super$transform().
Examples
library(ggplot2)
p <- ggplot(mpg, aes(measure(displ, "L"))) + geom_histogram()
s <- scale_x_continuous("Engine displacement")
p + enmeasure_scale(s)
#> `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.