Sankey Diagrams as Collapsible Trees
Combining Sankey diagrams with collapsible trees and adding some new interactivity might help us analyze, instruct, and decide.
devtools::install_github("timelyportfolio/sankeytree")
library(rpart)
library(partykit)
library(pipeR)
library(sankeytreeR)
#set up a little rpart as an example
rp <- rpart(
hp ~ cyl + disp + mpg + drat + wt + qsec + vs + am + gear + carb,
method = "anova",
data = mtcars,
control = rpart.control(minsplit = 4)
)
#convert rpart to a hierarchy using convert_rpart in converters.R
# this was the original conversion
# and I already see lots of room for improvement
sankeytreeR:::convert_rpart(rp)
#see what it looks like
sankeytree(rp)
sankeytree(rp, maxLabelLength = 10, nodeHeight = 100)
# do with kyphosis example
sankeytree(
rpart(Kyphosis ~ Age + Number + Start, data = kyphosis),
maxLabelLength = 10,
nodeHeight = 200
)
MIT + file LICENSE © Kenton Russell