Colors and text in R

Colours

See Color Pitfalls on this webpage.

The colorspace package can be used to A LOT of things. Examples:

Text

See package ggtext for ways to fx. color text labels, titles, etc. based on categories in data.

See also gridtext for text rendering support for grid graphics in R.

Fonts

See Fonts in R for a small introduction

Getting new fonts

Download font online:

  1. Go to font download site, fx. Google Gruppo
  2. Click download
  3. When downloaded, extract it 3a) On windows, click the Gruppo-regular file and press “Install”
  4. In R, use the cairo graphics device 4a) In Rstudio: Tools -> Global options -> General -> Graphics (top) -> Backend -> Choose cairo 4b) In Rmarkdown: Include knitr::opts_chunk$set(dev.args = list(png = list(type ="cairo"))) in setup chunk.
  5. Refer to the new font by it’s folder name in your system. Fx. ggplot2::element_text(family = "Gruppo")

References

Practical advice on how to use colors most “efficiently” in your plots

  • Chapters 4 and 19 of “Fundamentals of Data Visualization” by Claus O. Wilke.
Back to top