Basic bump plot



This post explains how to build a basic bump plot with R. It uses the ggbump package, provides reproducible code and explain how input data must be formatted.

For a more advanced usage of ggbump charts, check out how to customize bump plot

Bump plot Data to Viz

Libraries and dataset


The ggbump package provides a geom_bump() function that allows to build ggbump charts.

Install the package with install.packages("ggbump").

The input dataset is simple: we just have 3 groups, with one value per group and per year. Here is how to build it:

# Library
#install.packages("ggbump")
library(ggbump)
library(tidyverse)

# Create data
year <- rep(2019:2021, 3)
products_sold <- c(
  500, 600, 700,
  550, 650, 600,
  600, 400, 500
)
store <- c(
  "Store A", "Store A", "Store A",
  "Store B", "Store B", "Store B",
  "Store C", "Store C", "Store C"
)

# Create the new dataframe
df <- data.frame(
  year = year,
  products_sold = products_sold,
  store = store
)

Most basic bump plot


Thanks to the geom_bump() function, we can easily build a ggbump chart.

ggplot(df, aes(x = year, y = products_sold, color = store)) +
  geom_bump(size = 2)

Add individual points


It is possible to add individual points to the bump chart. This is done by adding a geom_point() layer.

ggplot(df, aes(x = year, y = products_sold, color = store)) +
  geom_bump(size = 2) +
  geom_point(size = 6)

Going further


You might be interested in

Related chart types


Barplot
Spider / Radar
Wordcloud
Parallel
Lollipop
Circular Barplot



❤️ 10 best R tricks ❤️

👋 After crafting hundreds of R charts over 12 years, I've distilled my top 10 tips and tricks. Receive them via email! One insight per day for the next 10 days! 🔥