R package for styling graphics for RSS publications.
The package is currently available on GitHub and you can install it with:
remotes::install_github("nrennie/RSSthemes")
You can then load the package using:
library(RSSthemes)
There are currently three palettes available in {RSSthemes}, although we hope to add more in the future.
Let’s set up a basic data set.
library(ggplot2)
plot_df <- data.frame(x = LETTERS[1:4],
y = 1:4)
If all of the bars, lines, points, etc. should have the same colour, you can set either the fill
or colour
arguments to have one of the RSS colours. The options are: signif_red
, signif_blue
, signif_green
, signif_orange
, or signif_yellow
.
ggplot(data = plot_df,
mapping = aes(x = x, y = y)) +
geom_col(fill = signif_yellow)
For working with qualitative (discrete) data, the best palette to use is "signif_qual"
. This palette currently only contains four colours.
ggplot(data = plot_df,
mapping = aes(x = x, y = y, fill = x)) +
geom_col() +
scale_fill_rss_d(palette = "signif_qual")
ggplot(data = plot_df,
mapping = aes(x = x, y = y, colour = x)) +
geom_point(size = 4) +
scale_colour_rss_d(palette = "signif_qual")
For working with sequential (continuous) data, the best palette to use is "signif_seq"
.
ggplot(data = plot_df,
mapping = aes(x = x, y = y, fill = y)) +
geom_col() +
scale_fill_rss_c(palette = "signif_seq")
ggplot(data = plot_df,
mapping = aes(x = x, y = y, colour = y)) +
geom_point(size = 4) +
scale_colour_rss_c(palette = "signif_seq")
For working with diverging (continuous) data, the best palette to use is "signif_div"
.
ggplot(data = plot_df,
mapping = aes(x = x, y = y, fill = y)) +
geom_col() +
scale_fill_rss_c(palette = "signif_div")
If you want to centre the diverging scale around a different value, you can alternatively pass the pre-defined colours into scale_fill_gradient2()
from {ggplot2}:
ggplot(data = plot_df,
mapping = aes(x = x, y = y, fill = y)) +
geom_col() +
scale_fill_gradient2(low = signif_red, high = signif_blue, midpoint = 2)
If all of the bars, lines, points, etc. should have the same colour, you can set col
arguments to have one of the RSS colours. The options are: signif_red
, signif_blue
, signif_green
, signif_orange
, or signif_yellow
.
barplot(table(mtcars$gear), col = signif_blue)
You can use the set_rss_palette()
function to change the default colours used in base R plotting:
set_rss_palette("signif_qual")
plot(1:4, 1:4, col=1:4, pch=19, cex=3, xlab="", ylab="")
Run palette("default")
to reset to original base R colours.
Theme functions style the non-data elements of plots, e.g. fonts, text colour, or background colour.
Apply styling to plots made with {ggplot2} using the theme_significance()
function:
ggplot(data = plot_df,
mapping = aes(x = x, y = y, fill = x)) +
geom_col() +
labs(title = "My Significance Plot",
subtitle = "Some longer sentence explaining what is happening in the chart.",
caption = "Source: name of data source") +
scale_fill_rss_d(palette = "signif_qual") +
theme_significance()
Apply styling to plots made with base R using the set_signif_par()
function. We also recommend adding reference lines using the abline()
function:
set_signif_par()
plot(1:4, 1:4, col=1:4, pch=19, cex=3, xlab="", ylab="",
main = "My Significance Plot",
sub = "Source: data source")
abline(h=1:4, v=1:4, col = "lightgrey")