Return one or more ggplot objects that together construct a plot area in accordance with CMAP design standards.
Char, the string used to label the x and y axes,
respectively. If unspecified, the axis label will be left off the graph. See
details for unexpected outcomes when using these arguments along with
coord_flip()
.
Numeric, the location of a strong horizontal or vertical
line to be added to the plot. Use hline = 0
, for example, to place a
line at y = 0 to differentiate between positive and negative values. The
width of this line is determined by
cmapplot_globals$consts$lwd_strongline
. Note that on most displays
the difference between this line and gridlines is impossible to discern in
R. The difference will be visible upon export.
Char, the grid lines to be displayed on the chart. If left as default, horizontal grid lines will be displayed while vertical grid lines will be masked. Acceptable values are "h" (horizontal only), "v" (vertical only), "hv" (both horizontal and vertical), and "none" (neither).
Char, the axis lines to be displayed on the chart. Acceptable values are "x" (x axis only), "y" (y axis only), "xy" (both axes), and "none" (neither, the default).
Char, the axis ticks to be displayed on the chart. Acceptable
values are "x" (x axis only), "y" (y axis only), "xy" (both axes), and
"none" (neither, the default). Because ggplot2
defaults to moderately
expanding the range of displayed data, this may need to be accompanied by a
call to expand = c(0, 0)
within an appropriate scale_*_*
argument in order for ticks to appear to touch the outermost gridline(s).
Bool, TRUE
is the default. FALSE
to hide the
legend.
Integer, the maximum number of columns in the legend. If no value is set, the chart will rely on `ggplot`'s default and automatic column handling behavior, which should work for most cases. Manual adjustment may be required if legend entries are particularly numerous and/or lengthy. Note that `ggplot` will still auto-adjust in ways that may mean the total number of columns is less than the maximum (e.g., if there are five items in a legend with four columns as the maximum, the output will be one row of three and another row of two).
Bool, Defaults to FALSE
. Set to TRUE
to show
rectangles around all geom_rect()
elements for debugging.
Named list, overrides the default drawing attributes defined
in cmapplot_globals$consts
which are drawn by
theme_cmap
. Units are in bigpts (1/72 of an inch).
pass additional arguments to ggplot2's theme
function to override any elements of the default CMAP theme.
Using either the xlab
or ylab
argument, but not both, will have
undesireable outcomes in a ggplot that also invokes coord_flip()
. Under
the hood, theme_cmap(xlab = "foo")
both sets ggplot2::xlab =
"foo"
and 'turns on' the ggplot theme element axis.title.x
. With
coord_flip()
, the xlab travels with the data (becoming the ylab) but
the theme modifier stays on the x axis. To solve this, rewrite your ggplot
construction to avoid coord_flip()
or manually turn off and on the
correct elements from ggplot2's theme
function in the
...
of this function.
if (FALSE) { # \dontrun{
# The only way to place the origin line (`hline`, `vline`) behind any data geoms
# is to or place `theme_cmap()` before the geoms:
ggplot(grp_over_time, aes(x = year, y = realgrp, color = cluster)) +
theme_cmap(hline = 0, ylab = "Percent change") +
geom_line() +
scale_x_continuous(breaks = scales::breaks_pretty(11))
df <- dplyr::filter(traded_emp_by_race, variable %in% c("SpecializedTraded",
"UnspecializedTraded"))
ggplot(df, aes(x = reorder(Race, -value), y = value, fill = variable)) +
geom_col(position = position_stack(reverse = TRUE)) +
scale_y_continuous(labels = scales::percent) +
theme_cmap(hline = 0, ylab = "This is the y axis")
ggplot(df, aes(y = reorder(Race, -value), x = value, fill = variable)) +
geom_col(position = position_stack(reverse = TRUE)) +
scale_x_continuous(labels = scales::percent) +
theme_cmap(vline = 0, gridlines = "v")
} # }