Skip to course content
Free R data course

R Foundations for Data Analysis

Unit 07.02: Pick the chart from the question

Five chart types, five different questions. Choosing by appearance is how the wrong one gets used.

Pick the chart from the question

A bar chart compares an amount across categories. A line chart shows how something moved over time, and implies that the points between are meaningful — which is why it is wrong for categories. A histogram shows how one variable is spread, and its bin count changes the story it tells. A box plot compares spread between groups. A scatter plot asks whether two variables move together.

Bar charts of a mean are the most common misuse. A bar shows one number and hides everything about how the values are distributed, so two groups with the same total look identical no matter how differently they behave.

This block draws all five from one dataset and then shows what the bar chart concealed.

suppressPackageStartupMessages(library(ggplot2))

set.seed(42)
daily <- data.frame(
  ward   = rep(c("North", "South"), each = 30),
  day    = rep(1:30, times = 2),
  visits = c(round(rnorm(30, 410, 25)), round(rnorm(30, 390, 40)))
)

charts <- list(
  bar     = ggplot(daily, aes(ward, visits)) + stat_summary(fun = sum, geom = "col"),
  line    = ggplot(daily, aes(day, visits, colour = ward)) + geom_line(),
  hist    = ggplot(daily, aes(visits)) + geom_histogram(bins = 12),
  box     = ggplot(daily, aes(ward, visits)) + geom_boxplot(),
  scatter = ggplot(daily, aes(day, visits)) + geom_point()
)

questions <- c(bar = "how much in each category",
               line = "how it changed over time",
               hist = "how one variable is spread",
               box = "how the spread compares between groups",
               scatter = "whether two variables move together")

for (nm in names(charts)) {
  cat(sprintf("%-8s answers: %s\n", nm, questions[[nm]]))
}

cat("\nSpread that the bar chart hides:\n")
cat("  North SD:", round(sd(daily$visits[daily$ward == "North"]), 1), "\n")
cat("  South SD:", round(sd(daily$visits[daily$ward == "South"]), 1), "\n")
cat("Two wards with similar totals and very different consistency.\n")

Each chart is paired with the question it answers. The final lines make the cost of the wrong choice concrete: North's standard deviation is 31.3 and South's is 42, so South is markedly less consistent day to day. A bar chart of totals draws two similar bars and says nothing about that; a box plot shows it immediately.

The mistake this prevents

The mistake is a bar chart of group means with no indication of spread. It is the standard way to make two very different distributions look like two similar numbers.

Takeaway

Write the question before choosing the geom. Use a box plot or a histogram when spread matters, keep line charts for genuine time series, and treat a bar chart of a mean as a summary that hides its own uncertainty.