Waterfalls Plot2

Authors

[Editor] Hu Zheng;

[Contributors]

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:

https://hiplot.cn/basic/waterfalls-plot?lang=en

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

# Install packages
if (!requireNamespace("waterfalls", quietly = TRUE)) {
  install.packages("waterfalls")
}
if (!requireNamespace("ggplot2", quietly = TRUE)) {
  install.packages("ggplot2")
}

# Load packages
library(waterfalls)
library(ggplot2)

Data Preparation

# Load data
data <- read.delim("files/Hiplot/185-waterfalls-plot-data.txt", header = T)

# convert data structure
data[["name"]] <- factor(data[["name"]], levels = data[["name"]])
data$fill <- ifelse(data$value > 0, "#B71C1C", "#1B5E20")

# 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
p <- waterfall(data, calc_total = T, rect_width = 0.7, fill_by_sign = F,
               fill_colours = data$fill, total_rect_color = "#1E065D") +
  theme_bw()

p
FigureΒ 1: Waterfalls Plot2