Streamgraph

Authors

[Editor] Hu Zheng;

[Contributors]

Note

Hiplot website

This page is the tutorial for source code version of the Hiplot Streamgraph 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/streamgraph?lang=en

Setup

  • System Requirements: Cross-platform (Linux/MacOS/Windows)

  • Programming language: R

  • Dependent packages: streamgraph

# Install packages
if (!requireNamespace("streamgraph", quietly = TRUE)) {
  install_github("hrbrmstr/streamgraph")
}

# Load packages
library(streamgraph)

Data Preparation

# Load data
data <- read.delim("files/Hiplot/168-streamgraph-data.txt", header = T)

# convert data structure
colnames(data) <- c("date","key","value")

# View data
head(data)
  date key  value
1 1990   a 0.7688
2 1990   b 0.5782
3 1990   c 0.8164
4 1990   d 0.4791
5 1990   e 0.8793
6 1990   f 0.4640

Visualization

# Streamgraph
p <- streamgraph(data, key = "key", value = "value", date = "date",
                 offset = "silhouette", interpolate = "cardinal",
                 interactive = F, scale = "date") %>% 
  sg_fill_brewer(palette = "Spectral")

p
FigureΒ 1: Streamgraph