theme_cmap | R Documentation |
Return one or more ggplot objects that together construct a plot area in accordance with CMAP design standards.
theme_cmap(
xlab = NULL,
ylab = NULL,
hline = NULL,
vline = NULL,
gridlines = c("h", "v", "hv", "none"),
axislines = c("none", "x", "y", "xy"),
axisticks = c("none", "x", "y", "xy"),
show.legend = TRUE,
legend.max.columns = NULL,
debug = FALSE,
overrides = list(),
...
)
xlab , ylab |
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
|
hline , vline |
Numeric, the location of a strong horizontal or vertical
line to be added to the plot. Use |
gridlines |
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). |
axislines |
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). |
axisticks |
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 |
show.legend |
Bool, |
legend.max.columns |
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). |
debug |
Bool, Defaults to |
overrides |
Named list, overrides the default drawing attributes defined
in |
... |
pass additional arguments to ggplot2's |
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.
## Not run:
# 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")
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.