Three key ingredients to make a data graphic

Tuesday, Jul 6, 2021
Data Graphics R

When constructing a data graphics using grammer of graphics, it’s worth noting there there are three key ingredients:

  1. Data: Can’t do much of a data graphics without data.
  2. Axis Mapping: Pick one or two variables from data and map those to axes (x, y or both x & y).
  3. Geometrical Element: Select an appropriate geometrical element to visually display the data.

Thinking in this way give us a good starting point to build common plots but more importantly, it provides a flexible framework to construct the plots we want. This is what I slowly will attempt to learn.

Let’s see how these elements come together using some examples:

Scatter Plot

For scatter plot, we need two numerical variables.

ggplot(faithful, aes(eruptions, waiting)) +


For histogram, we need one numerical variable.

ggplot(faithful, aes(eruptions)) +

Bar chart

Bar chart has one categorical variable and the each bar’s height represents the count for each category.

ggplot(InsectSprays, aes(spray)) +

Time series

Time series is a plot of numeric variable as a function of time.

ggplot(economics, aes(date, psavert)) +