# Install packages
if (!requireNamespace("ggplot2", quietly = TRUE)) {
install.packages("ggplot2")
}if (!requireNamespace("ggbump", quietly = TRUE)) {
install.packages("ggbump")
}if (!requireNamespace("dplyr", quietly = TRUE)) {
install.packages("dplyr")
}
# Load packages
library(ggplot2)
library(ggbump)
library(dplyr)
Bumpchart
Note
Hiplot website
This page is the tutorial for source code version of the Hiplot Bumpchart
plugin. You can also use the Hiplot website to achieve no code ploting. For more information please see the following link:
Bump chart can be used to display the change of grouped values.
Setup
System Requirements: Cross-platform (Linux/MacOS/Windows)
Programming language: R
Dependent packages:
ggplot2
;ggbump
;dplyr
Data Preparation
# Load data
<- read.table("files/Hiplot/017-bumpchart-data.txt", header = T)
data
# View data
head(data)
x y group
1 2019 4 A
2 2020 2 A
3 2021 2 A
4 2019 3 B
5 2020 1 B
6 2021 4 B
Visualization
# Bumpchart
<- ggplot(data, aes(x = x, y = y, color = group)) +
p geom_bump(size = 1.5) +
geom_point(size = 5) +
geom_text(data = data %>% filter(x == min(x)),
aes(x = x - 0.1, label = group),
size = 5, hjust = 1) +
geom_text(data = data %>% filter(x == max(x)),
aes(x = x + 0.1, label = group),
size = 5, hjust = 0) +
theme_void() +
theme(legend.position = "none") +
scale_color_manual(values = c("#0571B0","#92C5DE","#F4A582","#CA0020"))
p
