Member-only story

True Colors: Facts about using Color in ggplot2

Data Scientist Dude
12 min readFeb 20, 2023
ggplot gives you many options when it comes to the use of color

One of the most striking features of the R programming language package ggplot2 is it’s ability to apply color to data. A data analyst does not need to do much coding and she can use the grammar of graphics to make professional grade charts and graphs.

ggplot2 is an open-source data visualization package. It was created by Hadley Wickham in 2005. ggplot2is a bold implementation of Leland Wilkinson’s Grammar of Graphics — a general scheme for data visualization which breaks up graphs into semantic components such as scales and layers. Layers that you can add or take away with a few key strokes, making design easier.

However, a beginner may not always know what part of that syntax applies to the data and what part applies to the chart itself. As with any language, it just takes some routine analysis and some easy mnemonics to break down color usage and that beginner can perform like a professional in any colorful situation.

As usual, I owe a lot to Winston Chang and his excellent book, R Graphics Cookbook. I use it often and you should too. There is also an excellent thread on Stack Overflow about using continuous versus discrete color scales. This is by far the error that I make the most. There are certain ggplot2 color settings that are only for continuous variables and certain ggplot2 color settings that are…

--

--

Data Scientist Dude
Data Scientist Dude

Written by Data Scientist Dude

Data Scientist, Linguist and Autodidact - I help people understand and use data models.

Responses (1)