# Install packages
if (!requireNamespace("waterfalls", quietly = TRUE)) {
install.packages("waterfalls")
}if (!requireNamespace("ggplot2", quietly = TRUE)) {
install.packages("ggplot2")
}
# Load packages
library(waterfalls)
library(ggplot2)
Waterfalls Plot2
Note
Hiplot website
This page is the tutorial for source code version of the Hiplot Waterfalls Plot2
plugin. You can also use the Hiplot website to achieve no code ploting. For more information please see the following link:
Used to visualize changes in data, with the difference from version 1 being the ability to customize the colors for upward and downward values.
Setup
System Requirements: Cross-platform (Linux/MacOS/Windows)
Programming language: R
Dependent packages:
waterfalls
;ggplot2
Data Preparation
# Load data
<- read.delim("files/Hiplot/185-waterfalls-plot-data.txt", header = T)
data
# convert data structure
"name"]] <- factor(data[["name"]], levels = data[["name"]])
data[[$fill <- ifelse(data$value > 0, "#B71C1C", "#1B5E20")
data
# View data
head(data)
name value fill
1 A 100 #B71C1C
2 B -20 #1B5E20
3 C 120 #B71C1C
4 D -40 #1B5E20
5 E -100 #1B5E20
6 F 80 #B71C1C
Visualization
# Waterfalls Plot2
<- waterfall(data, calc_total = T, rect_width = 0.7, fill_by_sign = F,
p fill_colours = data$fill, total_rect_color = "#1E065D") +
theme_bw()
p
