ggplot2
themeThis is a ggplot2
theme I use for almost all my plots. You can use it and adapt it if you want. It's designed to be truly plug-and-play. See below for examples.
As with any software project, this has a collection of dependencies it builds on:
R
graphics are notoriously difficult. The package extrafont
solves this.ggplot2
.On mac computers, first install the Fira Sans
font to the font book.
remotes::install_github("vankesteren/firatheme")
The preferred way to save plots is via the firaSave()
function. For png output, this works out of the box.
For pdf output, firaSave()
embeds the Fira Sans font by default using the extrafont
package. The requirement for this is ghostscript
:
R
or RStudio
applicationbrew install ghostscript
R
or RStudio
applicationPATH
.R
or RStudio
applicationBelow you can find some example plots made using theme_fira()
library(ggplot2)
library(firatheme)
ggplot(mtcars, aes(x = mpg*0.43, y = wt*0.4535924, colour = factor(cyl))) +
geom_point(size = 2) + geom_smooth(se = FALSE) +
labs(title = "Car weight vs efficiency",
x = "Efficiency (km/l)",
y = "Weight (1000 kg)",
colour = "Cylinders") +
theme_fira() +
scale_colour_fira()
firaSave("plot.png", device = "png")
library(ggplot2)
library(firatheme)
ggplot(chickwts, aes(x = feed, y = weight)) +
geom_bar(stat = "identity", width=0.8, fill = firaCols[1]) +
labs(title = "Chicken weights by feed type",
y = "Weight (grams)",
x = "") +
theme_fira()
library(ggplot2)
library(firatheme)
ggplot(iris, aes(y = Sepal.Length, x = Species, fill = Species)) +
geom_boxplot(col = firaCols[4], width = 0.5, size = 1) +
labs(y = "Sepal Length", title = "Iris data") +
theme_fira() +
scale_fill_fira() +
theme(legend.position = "none")
library(ggplot2)
library(firatheme)
ggplot(airquality, aes(y = Ozone, x = 1:nrow(airquality))) +
geom_line(colour = firaCols[2], size = 0.7) +
geom_point(colour = firaCols[2], size = 1.7) +
geom_smooth(colour = firaCols[1], size = 0.7, se = FALSE) +
labs(title = "Ozone in New York", x = "Days") +
theme_fira()
The colour palette of firatheme
is available through firaCols
and firaPalette()
. In ggplot
objects, you should use scale_fill_fira()
and scale_colour_fira()
for mapped variables. Optionally, the argument continuous = TRUE
can be passed.
Using the palette functions, you can get any number of colours from the palette, for example firaPalette(n = 25)
--- the last image in the figure below:
If you want to cite firatheme
, you can use the following bibtex
:
@article{vankesteren2021firatheme,
title = {vankesteren/firatheme: firatheme version 0.2.4},
DOI = {10.5281/zenodo.4679413},
publisher = {Zenodo},
author = {Erik-Jan van Kesteren},
year = {2021},
month = {apr}
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.