clplot is a ggplot2 theme for the House of Commons Library. It is currently in development so theme elements and scale colors are likely to change in future.
This theme uses Open Sans as the default font, but an alternative font can be specified in the call to theme_commonslib
.
On Windows, the system wide fonts may not be avilable in R by default. If this is the case, you can make them available with the extrafont package in the following way.
install.packages("extrafont")
library(extrafont)
font_import()
loadfonts(device = "win")
You will only need to do the above step once. After that, loading the extrafont package in your script with library(extrafont)
is enough to make the fonts available.
Note that on MacOS Open Sans is not installed on the system by default, but it is freely available to download and install. You don't need to use extrafont to use system fonts in R on a Mac.
Install from GitHub using remotes.
install.packages("remotes")
remotes::install_github("olihawkins/clplot")
The base colors that are used by the theme are available in a named vector called commonslib_colors
.
The base color names are:
You can use the commonslib_color
function to return the unnamed hex code value for a given name. This makes it easy to map specific colors to categorical variables using the scale_color_manual()
and scale_fill_manual()
functions.
scale_color_manual(values = c(
"a" = commonslib_color("green_1"),
"b" = commonslib_color("green_3")))
These colors are also avaialable as ggplot2 scales with a range of palettes representing different subsets of the colors (see below).
Set the theme for the session with:
library(ggplot2)
library(clplot)
theme_set(theme_commonslib())
Or apply the theme directly to a specific plot with + theme_commonslib()
.
clplot::theme_commonslib(background = "#edf7f2", family = "Open Sans", subtitle = TRUE, axes = "bl", grid = "")
Sets the theme with the following arguments:
Use scale_color_commonslib()
or scale_fill_commonslib()
as approriate. Both functions have the same signature.
clplot::scale_color_commonslib(palette = "main", discrete = TRUE, reverse = FALSE, ...) clplot::scale_fill_commonslib(palette = "main", discrete = TRUE, reverse = FALSE, ...)
Sets the scales with the following arguments:
discrete_scale
or scale_color_gradient
, depending on the value of discrete
.Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.