Lesson 4 of 4

Publication-Ready Figures

Maya the bakery owner has found something worth sharing. Quiet little Sourdough, ordered only 3 times last Saturday, quietly out-earned Coffee, her busiest seller. She wants that surprise on the front of the bakery's monthly newsletter. So she draws the bar chart and... it comes out grey, the axis says revenue in tiny lowercase, there is no title, and the finding is buried. A chart on your own screen and a figure a stranger can read in three seconds are not the same thing.

Across this course you learned the grammar (Lesson 1), scatter and line charts (Lesson 2), and bars and distributions (Lesson 3). You can now draw almost anything. This final lesson is about the last mile: picking the right chart, then polishing one to publication quality. Drag the controls below to feel where we are headed.

By the end of this lesson you will be able to:

  • Pick the chart that answers a given question, from a quick chooser
  • Make a figure explain itself with labs(): a title that states the finding, plus a subtitle, axis labels and a source caption
  • Style with intent: a clean theme, and colour used to encode meaning, not decorate, kept colorblind-safe
  • Assemble the layers into one publication figure and export it with ggsave()

Prerequisites: Lesson 1, the grammar of graphics, Lesson 2, scatter and line charts, and Lesson 3, bars and distributions. Every new function is defined as it appears.

Start here

First, choose the right chart

Before you style anything, you have to pick the right chart, and a beautiful theme cannot rescue the wrong one. Choosing is not about taste; it is two quick questions: what do you want the reader to see? and what shape is your data? Answer those and the chart almost picks itself.

Let us rebuild Maya's week in this fresh R session (each lesson starts clean, so the data lives on this page, run this once):

RInteractive R
library(ggplot2) # Maya's last week: one row per day week <- data.frame( day = c("Mon","Tue","Wed","Thu","Fri","Sat","Sun"), foot_traffic = c(110, 125, 130, 150, 185, 240, 205), # people who walked in revenue = c(340, 380, 400, 455, 560, 720, 610) # dollars taken ) # Saturday's 30 orders, already totalled to one row per pastry (from Lesson 3) by_pastry <- data.frame( pastry = c("Coffee", "Croissant", "Muffin", "Sourdough"), revenue = c(72, 64, 56, 76), orders = c(14, 7, 6, 3) ) by_pastry

  

The same two columns can become several different charts; your question decides which. The gallery below takes Maya's week (foot traffic against revenue) and draws it two ways: a scatter to ask are these two numbers related? and a line that traces revenue as foot traffic climbs. Flip between them and watch the same numbers answer different questions.

Here is the whole course as a one-line chooser. Name your question, read across:

Your question The data you have The chart The geom
Are two numbers related? two continuous columns scatterplot geom_point()
How did a value move over an order or time? a value across an ordered sequence line chart geom_line()
How do categories compare on an amount? one number per category bar chart geom_col()
How many rows fall in each group? raw rows with a category bar chart geom_bar()
How is one number spread out? one continuous column histogram geom_histogram()
How does a distribution differ across groups? a number split by a category boxplot geom_boxplot()
Key Insight
Choose the chart from the question, not the other way around. Pretty styling on the wrong chart still answers the wrong question.