Multiple Line Plot

A multiple line plot is used for visualizing trends, patterns, or changes over time or across different categories for more than one group or variable simultaneously. It is particularly effective in comparing the progression of these variables, allowing analysts to identify correlations, contrasts, and interactions between them.

The example below implements multiple line plots for GDP data for three countries: Canada, Germany, Japan

library(tidyverse)
library(ggplot2)

# read the data
data = read.csv('../data/gdp_time_series.csv')
head(data)
A data.frame: 6 × 3
Country.NameYearGDP
<chr><int><dbl>
1Canada20007.447734e+11
2Canada20017.389818e+11
3Canada20027.606493e+11
4Canada20038.955406e+11
5Canada20041.026690e+12
6Canada20051.173109e+12

Implementing Multiple Line Plots - Economist Theme

To implement the line plots, I leverage geom_line() and geom_point() functions to plot the time series plot. I also use the popular economist.

# Multiple line plot
ggplot(data = data, aes( x = Year, y = GDP, colour = Country.Name )) +
geom_line(linewidth = 1.2) + 
geom_point(size = 3.2) + 
scale_x_continuous(breaks = seq(2000,2022,3)) +
labs( title="GDP Comparison by Country (in USD$)", 
      subtitle = 'Canada, Germany and Japan',
      x = 'Year', y = 'GDP in (US$)') +
theme_economist() +
theme( axis.line.x = element_line(size = .5, colour = "black"),
       legend.position = "bottom",
       legend.direction = "horizontal",
       legend.title = element_blank(),
       text = element_text(size = 14))
Multiple Line Plots