Interactive visualization of hierarchical datasets with R and Shiny - includes horizontal and vertial Sankey, Sunburst, Partition, Icicle and Treemap. Based on d3-hierarchy and d3-hiervis.
hiervis_demo()
showcases the supported visualizations and prints the command to reproduce the visualization. Also works with custom data.
# devtools::install_github("fbreitwieser/hiervis")
library(hiervis)
hiervis_demo()
Tabular data works with default arguments:
> str(Titanic)
table [1:4, 1:2, 1:2, 1:2] 0 0 35 0 0 0 17 0 118 154 ...
- attr(*, "dimnames")=List of 4
..$ Class : chr [1:4] "1st" "2nd" "3rd" "Crew"
..$ Sex : chr [1:2] "Male" "Female"
..$ Age : chr [1:2] "Child" "Adult"
..$ Survived: chr [1:2] "No" "Yes"
> hiervis(Titanic, "sankey")
> hiervis(HairEyeColor, "vertical sankey")
> str(HairEyeColor)
table [1:4, 1:4, 1:2] 32 53 10 3 11 50 10 30 10 25 ...
- attr(*, "dimnames")=List of 3
..$ Hair: chr [1:4] "Black" "Brown" "Red" "Blond"
..$ Eye : chr [1:4] "Brown" "Blue" "Hazel" "Green"
..$ Sex : chr [1:2] "Male" "Female"
For data.frame
s with a path, specify nameField (with path), pathSep and valueField:
> str(d3_modules)
'data.frame': 463 obs. of 2 variables:
$ size: int NA NA NA NA NA NA NA NA NA NA ...
$ path: chr "d3" "d3/d3-array" "d3/d3-array/threshold" "d3/d3-axis" ...
> hiervis(d3_modules, "sunburst", nameField = "path", pathSep = "/", valueField = "size")
For data.frame
s with parent-child information, supply nameField and parentField
> data <- data.frame(name = c("Root Node", "Node A", "Node B", "Leaf Node A.1", "Leaf Node A.2"),
parent = c(NA, "Root Node", "Root Node", "Node A", "Node A"))
> hiervis(data, "sankey", nameField = "name", parentField = "parent", stat = "count")