These functions allow for setting and resetting default aesthetic values for
certain ggplot2 geoms. This is necessary for geoms to be "themed" to CMAP
style standards, because (at least at the moment) setting geom aesthetic
defaults on a plot-by-plot basis (such as with ggplot2::theme
) is not
possible. The geoms impacted are stored in
cmapplot_globals$geoms_that_change
.
apply_cmap_default_aes(quietly = FALSE)
unapply_cmap_default_aes(quietly = FALSE)
These functions are employed implicitly within finalize_plot
to
apply preferred aesthetic defaults to final outputs. They are only necessary
to use explicitly if you would like plots to use these defaults
pre-finalize
.
CAUTION: Running apply_cmap_default_aes
will set defaults for all
ggplot2 plots drawn in the current session. To reset to ggplot2
defaults (technically, to whatever the defaults were when cmapplot
was loaded), use unapply_cmap_default_aes
.
Note: CMAP aesthetic defaults are loaded into
cmapplot_globals$default_aes_cmap
by the internal pkg function
init_cmap_default_aes
when cmapplot
is first loaded into R.
apply_cmap_default_aes()
: Apply CMAP aesthetic defaults to all ggplots in
the current session
unapply_cmap_default_aes()
: Reset modified geom aesthetics to their values
when cmapplot
was first loaded
if (FALSE) { # \dontrun{
g <- ggplot(filter(grp_over_time, category == "Services"),
aes(x = year, y = realgrp, color = cluster)) +
geom_recessions(ymax = 0.4, text_nudge_x = 0.1) +
theme_cmap(hline = 0,
axislines = "x",
legend.max.columns = 2) +
ggtitle("Change in gross regional product over time") +
geom_line() +
scale_x_continuous("Year", breaks = seq(2007, 2017, 2)) +
coord_cartesian(clip = "off") +
geom_text_lastonly(aes(label = realgrp), add_points = TRUE)
# print normally
g
# overwrite `default_aes`
apply_cmap_default_aes()
g
# reset `default_aes`
unapply_cmap_default_aes()
g
# finalize alters the defaults implicitly, but then resets them automatically.
finalize_plot(g)
# you can also use `finalize` without these modifications
finalize_plot(g, use_cmap_aes = FALSE)
} # }