• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar

Data Viz with Python and R

Learn to Make Plots in Python and R

  • Home
  • Python Viz
  • Seaborn
  • Altair
  • R Viz
  • ggplot2
  • About
    • Privacy Policy
  • Show Search
Hide Search

Bump Plot with ggbump

datavizpyr · March 28, 2022 ·

Bump plots are line plots with dots showing the data points. Bump plots can be useful in understanding the change in rank over time. In this tutorial, we will learn how to make bump plots using ggbump package, a ggplot2 extension package.

To make a bump plot we will use the top browser usage over time. First, let us get started creating the dataframe with browser usage percentages of the most commonly used web browsers like Chrome, Firefox, Safari and IE.

We will create vectors containing the data for each browser.

years <- c(2007,2010,2013,2016,2019)
chrome <- c(0, 10.6, 33.4, 59.5, 56.1)
safari <- c(2.4, 2.1, 15.2, 13.1,18.1)
IE <- c(67.7, 48.3, 23, 10.2,7.5) 
firefox <- c(25,34.1,19.1,10.1,5.5)
opera <- c(1.8,2.3,2.4,2.6,3.7)

Then use tibble() function to create a tibble/dataframe in a wide form.

df <- tibble(year=years,
             Chrome=chrome/100,
             Safari=safari/100,
             IE=IE/100,
             Firfox=firefox/100,
             Opera=opera/100)

## # A tibble: 5 × 6
##    year Chrome Safari    IE Firfox Opera
##   <dbl>  <dbl>  <dbl> <dbl>  <dbl> <dbl>
## 1  2007  0      0.024 0.677  0.25  0.018
## 2  2010  0.106  0.021 0.483  0.341 0.023
## 3  2013  0.334  0.152 0.23   0.191 0.024
## 4  2016  0.595  0.131 0.102  0.101 0.026
## 5  2019  0.561  0.181 0.075  0.055 0.037

Using pivot_longer() we reshape the data in wide form to long tidy form.

df_long <- df %>%
  pivot_longer(-year, names_to = "browser", values_to="usage_share" )

df_long %>% head()
## # A tibble: 6 × 3
##    year browser usage_share
##   <dbl> <chr>         <dbl>
## 1  2007 Chrome        0    
## 2  2007 Safari        0.024
## 3  2007 IE            0.677
## 4  2007 Firfox        0.25 
## 5  2007 Opera         0.018
## 6  2010 Chrome        0.106

bump plot with ggbump

ggbump package has a geom, geom_bump, for making bump plot. We first use geom_point() and then add the geom_bump() layer.

df_long %>%
  ggplot(aes(year, usage_share, color = browser)) +
  geom_point(size = 5) +
  geom_bump() 
ggsave("bump_plot_ggbump.png", width=8, height=6)
Bump plot with ggbump
Bump plot with ggbump

Customizing bump plot

Here we customize the x and y axes, first we use scales package to add percent sign on y-axis and then specify breaks on x-axis.

df_long %>%
  ggplot(aes(year, usage_share, color = browser)) +
  geom_point(size = 5) +
  geom_bump() +
  scale_y_continuous(labels = scales::percent)+
  scale_x_continuous(breaks=c(2007,2010,2013,2016,2019))
ggsave("bump_plot_ggbump_customize.png", width=8, height=6)
Customizing Bump Plot made with ggbump
Customizing Bump Plot made with ggbump

Check out ggbump’s github page to learn other intersting uses of bump chart in R

Related posts:

Customizing Mean mark to boxplot with ggplot2How To Show Mean Value in Boxplots with ggplot2? Scatterplot with marginal multi-histogram with ggExtraHow To Make Scatterplot with Marginal Histograms in R? ggforce geom_circle(): Annotate with a circleHow To Annotate a Plot with Circle in R Default ThumbnailHow to Make Axis Text Bold in ggplot2

Filed Under: ggplot2, R Tagged With: bump plot with ggbump, ggbump ggplot2 extension

Primary Sidebar

Tags

Altair barplot Boxplot boxplot python boxplot with jiitered text labels Bubble Plot Color Palette Countplot Density Plot Facet Plot gganimate ggplot2 ggplot2 Boxplot ggplot2 error ggplot boxplot ggridges ggtext element_markdown() Grouped Barplot R heatmap heatmaps Histogram Histograms Horizontal boxplot Python lollipop plot Maps Matplotlib Pandas patchwork pheatmap Pyhon Python R RColorBrewer reorder boxplot ggplot Ridgeline plot Scatter Plot Scatter Plot Altair Seaborn Seaborn Boxplot Stock Price Over Time Stripplot UpSetR Violinplot Violin Plot World Map ggplot2

Buy Me a Coffee

Copyright © 2025 · Daily Dish Pro on Genesis Framework · WordPress · Log in

Go to mobile version