Line Chart
ggplot2: geom_line() · Package: ggplot2 · Variables: 1 temporal + 1-7 numerical series
WHAT IS A LINE CHART?
A line chart connects data points with straight lines to show how values change over a continuous dimension, most commonly time. It is the default chart for time-series data — answering "how has this metric changed over time?" Line charts can show multiple series on the same axes for comparison (e.g., revenue by product over months). They work best with at least 5-7 data points and an ordered x-axis. In ggplot2, use geom_line() and optionally geom_point() to mark individual data points.
HOW TO READ A LINE CHART
A line chart encodes change as slope, so the eye reads direction and rate rather than absolute level. Steepness between two points is the story; the points themselves are secondary. This is why the line implies something specific — that the values between the plotted points are meaningful and continuous. Connecting monthly revenue is honest because revenue existed throughout the month. Connecting five unrelated product categories is not, because nothing exists between "Furniture" and "Electronics" and the slope invites a reading of change that has no referent. Unlike bar charts, line charts may use a truncated y-axis: position rather than length carries the meaning, and a zero baseline often compresses the very variation you are trying to show.
BEST FOR
- · Trends over time
- · Comparing multiple series
- · Continuous data patterns
- · Forecasting context
AVOID WHEN
- · Categorical/unordered x-axis
- · Fewer than 4 data points
- · Unconnected discrete categories
R + GGPLOT2 CODE EXAMPLE
ggplot(economics, aes(x = date, y = unemploy)) + geom_line(color = "#ff6a00", linewidth = 0.8) + labs(title = "US Unemployment Over Time", x = "Date", y = "Unemployed (thousands)")
MULTIPLE SERIES WITH DIRECT LABELS
Directly labelled lines instead of a legend, with a comma-formatted axis and date breaks — the form that reads well in a report or slide.
library(ggplot2)
library(dplyr)
# long format: one row per series per date
monthly <- economics_long |>
filter(variable %in% c("psavert", "uempmed"))
ggplot(monthly, aes(x = date, y = value, colour = variable)) +
geom_line(linewidth = 0.7) +
geom_text(
data = monthly |> group_by(variable) |> slice_max(date, n = 1),
aes(label = variable),
hjust = -0.1, size = 3.5
) +
scale_x_date(date_breaks = "10 years", date_labels = "%Y",
expand = expansion(mult = c(0.02, 0.12))) +
scale_colour_manual(values = c(psavert = "#ff6a00", uempmed = "#3d9970")) +
labs(title = "Savings rate and median unemployment duration",
x = NULL, y = NULL) +
theme_minimal(base_size = 12) +
theme(legend.position = "none")COMMON MISTAKES WITH THIS CHART
Plotting an unordered categorical variable on the x-axis
The connecting line implies continuity between adjacent points. If the x-axis is nominal, use a bar or dot plot instead.
Crowding in too many series
Beyond about five lines the chart becomes a tangle. Highlight the two or three that matter, grey the rest as context, or facet with facet_wrap().
Letting gaps in the data close silently
ggplot2 draws straight through missing dates, hiding the gap. Complete the series with tidyr::complete() so absent periods appear as breaks rather than interpolation.
Relying on a legend for series identity
Label lines directly at their right-hand end. It removes the back-and-forth between legend and line, and survives being printed in greyscale.
Run this code now
Paste the code above into RChat and see the line chart rendered instantly in your browser.