Visualize Recursive Partitioning and Regression Trees rpart. Have a look to visTreeEditor to edity and get back network, or to visTreeModuleServer to use custom tree module in R
visTree(
object,
data = NULL,
tooltipColumns = if (!is.null(data)) {
1:ncol(data)
} else {
NULL
},
main = "",
submain = "",
footer = "",
direction = "UD",
fallenLeaves = FALSE,
rules = TRUE,
simplifyRules = TRUE,
shapeVar = "dot",
shapeY = "square",
colorVar = NULL,
colorY = NULL,
colorEdges = "#8181F7",
nodesFontSize = 16,
edgesFontSize = 14,
edgesFontAlign = "horizontal",
legend = TRUE,
legendNodesSize = 22,
legendFontSize = 16,
legendWidth = 0.1,
legendNcol = 1,
legendPosition = "left",
nodesPopSize = FALSE,
minNodeSize = 15,
maxNodeSize = 30,
highlightNearest = list(enabled = TRUE, degree = list(from = 50000, to = 0), hover =
FALSE, algorithm = "hierarchical"),
collapse = list(enabled = TRUE, fit = TRUE, resetHighlight = TRUE, clusterOptions =
list(fixed = TRUE, physics = FALSE)),
updateShape = TRUE,
tooltipDelay = 500,
digits = 3,
height = "600px",
width = "100%",
export = TRUE
)rpart, rpart object
data.frame, adding mini-graphics in tooltips using sparkline and tooltipColumns ?
numeric, indice of columns used in tooltip. All by default.
So, we add boxplot / pie focus on sub-population vs all population using sparkline package. NULL to disable.
Title. See visNetwork
Subtitle. See visNetwork
Footer. See visNetwork
character, The direction of the hierarchical layout.
The available options are: UD, DU, LR, RL. To simplify:
up-down, down-up, left-right, right-left. Default UD. See visHierarchicalLayout
boolean leaf nodes at the bottom of the graph ? Default to FALSE
boolean, add rules in tooltips ? Default to TRUE
boolean, simplify rules writing
character, shape for variables nodes See visNodes
character, shape for terminal nodes See visNodes
character, colors to use or data.frame To set color of variables. 2 columns :
"variable" names of variables
"color" colors (in hexa). See examples
if classification tree : character colors to use or data.frame 2 columns :
"modality" levels of Y
"color" colors (in hexa)
if regression tree : character, 2 colors (min and max, in hexa)
character, color of edges, in hexa. Default to #8181F7
numeric, size of labels of nodes. Default to 16
numeric, size of labels of edges Default to 14
character, for edges only. Default tp 'horizontal'. Possible options: 'horizontal' (Default),'top','middle','bottom'. See visEdges
boolean, add legend ? Default TRUE. visLegend
numeric, size of nodes in legend. Default to 22
numeric, size of labels of nodes in legend. Default to 16
numeric, legend width, between 0 and 1. Default 0.1
numeric, number of columns in legend. Default 1
character, one of "left" (Default) or "right"
boolean, nodes sizes depends on population ? Default to FALSE
numeric, in case of nodesPopSize, minimum size of a node. Default to 15. Else, nodes size is minNodeSize + maxNodeSize / 2
numeric, in case of nodesPopSize, maximum size of a node. Default to 30. Else, nodes size is minNodeSize + maxNodeSize / 2
list, Highlight nearest nodes. See visOptions
list, collapse or not using double click on a node ? See visOptions
boolean, in case of collapse, udpate cluster node shape as terminal node ? Default to TRUE
numeric, delay for tooltips in millisecond. Default 500
numeric, number of digits. Default to 3
character, default to "600px"
character, default to "100%"
boolean, add export button. Default to TRUE
a visNetwork object
See online documentation https://datastorm-open.github.io/visNetwork/
visTreeEditor, visTreeModuleServer, visNetworkEditor
if (FALSE) { # \dontrun{
library(rpart)
# Basic classification tree
res <- rpart(Species~., data=iris)
visTree(res, data = iris, main = "Iris classification Tree")
# Basic regression tree
res <- rpart(Petal.Length~., data=iris)
visTree(res, edgesFontSize = 14, nodesFontSize = 16)
# Complex tree
data("solder")
res <- rpart(Opening~., data = solder, control = rpart.control(cp = 0.00005))
visTree(res, data = solder, nodesPopSize = TRUE, minNodeSize = 10,
maxNodeSize = 30, height = "800px")
# ----- Options
res <- rpart(Opening~., data = solder, control = rpart.control(cp = 0.005))
# fallen leaves + align edges label & size
visTree(res, fallenLeaves = TRUE, height = "500px",
edgesFontAlign = "middle", edgesFontSize = 20)
# disable rules in tooltip, and render tooltip faster
# enable hover highlight
visTree(res, rules = FALSE, tooltipDelay = 0,
highlightNearest = list(enabled = TRUE, degree = list(from = 50000, to = 0),
hover = TRUE, algorithm = "hierarchical"))
# Change color with data.frame
colorVar <- data.frame(variable = names(solder),
color = c("#339933", "#b30000","#4747d1","#88cc00", "#9900ff","#247856"))
colorY <- data.frame(modality = unique(solder$Opening),
color = c("#AA00AA", "#CDAD15", "#213478"))
visTree(res, colorEdges = "#000099", colorVar = colorVar, colorY = colorY)
# Change color with vector
visTree(res, colorEdges = "#000099",
colorVar = substring(rainbow(6), 1, 7),
colorY = c("blue", "green", "orange"))
# Use visNetwork functions to add more options
visTree(res) %>%
visOptions(highlightNearest = TRUE)
} # }