theme_commonslib | R Documentation |
This ggplot theme implements the Commons Library chart style. The theme
offers various options for easily controlling plot settings so that you
don't need to resort to additional uses of the ggplot2 theme
function
in most cases.
theme_commonslib(
axes = "bl",
grid = "",
legend_position = "right",
caption_position = "right",
title_family = "National-LFSN Semibd",
subtitle_family = "National-LFSN Book",
axis_title_family = "Open Sans",
axis_text_family = "Open Sans",
legend_title_family = "Open Sans",
legend_text_family = "Open Sans",
facet_title_family = "Open Sans",
caption_family = "National-LFSN Book",
title_size = 18,
subtitle_size = 14,
axis_title_size = 11,
axis_text_size = 10,
legend_title_size = 10,
legend_text_size = 10,
facet_title_size = 10,
caption_size = 12,
title_color = "#006548",
subtitle_color = "#006548",
axis_title_color = "#404040",
axis_text_color = "#404040",
legend_title_color = "#404040",
legend_text_color = "#404040",
facet_title_color = "#404040",
caption_color = "#404040",
background_color = "#f0eeed",
axis_line_color = "#a6a6a6",
grid_color = "#dad5d1"
)
axes |
A string indicating which axes should have lines and ticks. Specify which axes to show by including the matching characters in the string: "t" for top, "r" for right, "b" for bottom, "l" for left. You will need to ensure this argument is consistent with the axes settings in your plot for the lines and ticks to be displayed. The default is "bl", meaning ticks and lines for the bottom and left axes are shown by default. |
grid |
A string indicating which gridlines should be shown. Specify the gridlines to show by including the matching characters in the string: "h" for horizontal, "v" for vertical. The default is an empty string, meaning no gridlines are shown by default. |
legend_position |
A string indicating the position of the legend. Valid positions are "top", "right", "bottom", "left", "top-right", "top-left", "bottom-right", "bottom-left", and "none". The default is "right". |
caption_position |
A string indicating the horizontal position of the caption. Valid positions are "left" or "right". The default is "right". |
title_family |
A string indicating the font-family to use for the title. The default is "National-LFSN Semibd". |
subtitle_family |
A string indicating the font-family to use for the subtitle. The default is "National-LFSN Book". |
axis_title_family |
A string indicating the font-family to use for axis titles. The default is "Open Sans". |
axis_text_family |
A string indicating the font-family to use for axis text. The default is "Open Sans". |
legend_title_family |
A string indicating the font-family to use for legend titles. The default is "Open Sans". |
legend_text_family |
A string indicating the font-family to use for legend text. The default is "Open Sans". |
facet_title_family |
A string indicating the font-family to use for facet titles. The default is "Open Sans". |
caption_family |
A string indicating the font-family to use for captions. The default is "National-LFSN Book". |
title_size |
An integer indicating the font size to use for the title in points. The default is 18 points. |
subtitle_size |
An integer indicating the font size to use for the subtitle in points. The default is 14 points. |
axis_title_size |
An integer indicating the font size to use for axis titles in points. The default is 11 points. |
axis_text_size |
An integer indicating the font size to use for axis text in points. The default is 10 points. |
legend_title_size |
An integer indicating the font size to use for legend titles in points. The default is 10 points. |
legend_text_size |
An integer indicating the font size to use for legend text in points. The default is 10 points. |
facet_title_size |
An integer indicating the font size to use for facet titles in points. The default is 10 points. |
caption_size |
An integer indicating the font size to use for captions in points. The default is 12 points. |
title_color |
An RGB hex string indicating the color to use for the title. The default is "#006548". |
subtitle_color |
An RGB hex string indicating the color to use for the subtitle. The default is "#006548". |
axis_title_color |
An RGB hex string indicating the color to use for axis titles. The default is "#404040". |
axis_text_color |
An RGB hex string indicating the color to use for axis text. The default is "#404040". |
legend_title_color |
An RGB hex string indicating the color to use for legend titles. The default is "#404040". |
legend_text_color |
An RGB hex string indicating the color to use for legend text. The default is "#404040". |
facet_title_color |
An RGB hex string indicating the color to use for facet titles. The default is "#404040". |
caption_color |
An RGB hex string indicating the color to use for captions. The default is "#404040". |
background_color |
An RGB hex string indicating the color to use for the background. The default is "#f0eeed". |
axis_line_color |
An RGB hex string indicating the color to use for the axis lines. The default is "#a6a6a6". |
grid_color |
An RGB hex string indicating the color to use for the gridlines. The default is "#dad5d1". |
The main arguments are axes
, grid
, caption_position
,
and legend_positon
. Arguments are also available to set the color and
font properties of elements of the plot. You should not normally need to use
these arguments but they are provided for unusual cases.
When creating plots using this theme, the title and subtitle elements should
not normally be set using ggplot2's labs
function. This is because
the Commons Library chart style aligns the title and subtitle with the
left-hand edge of the y-axis text rather than the left-hand edge of the
plotting area.
To set the title and subtitle using this theme, first create a plot in the
normal way, without specifying any title or subtitle in labs
using
this theme function. Then use the add_commonslib_titles
function to
add the title and subtitle elements. Using add_commonslib_titles
also
has the benefit of correctly setting the distance between the bottom of the
title and the rest of the plot when no subtitle is needed.
The arguments for controlling the properties of text elements in this
function include options for setting the properties for the title and
subtitle. These will control titles and subtitles that are set using the
ggplot2 labs
function. As explained above, this is not the normal way
to set the title and subtitle of a plot when using this theme, but in some
cases you may want the default ggplot2 behaviour. You can separately
configure the properties of the title and subtitle in
add_commonslib_titles
if you need to change the appearance of the
title elements when they are set in the recommended way.
A ggplot2 theme that implements the Commons Library style.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.