visTree {visNetwork} | R Documentation

## Visualize Recursive Partitioning and Regression Trees (rpart object)

### Description

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

### Usage

    visTree(object, 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)

### Arguments

`object` | `rpart`, rpart object
`main` | For add a title. See visNetwork
`submain` | For add a subtitle. See visNetwork
`footer` | For add a footer. See visNetwork
`direction` | `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
`fallenLeaves` | `boolean` leaf nodes at the bottom of the graph ? Default to FALSE
`rules` | `boolean`, add rules in tooltips ? Default to TRUE
`simplifyRules` | `boolean`, simplify rules writing
`shapeVar` | `character`, shape for variables nodes See visNodes
`shapeY` | `character`, shape for terminal nodes See visNodes
`colorVar` | `character` colors to use or `data.frame` To set color of variables. 2 columns : "variable" : names of variables "color" : colors (in hexa). See examples
`colorY` | 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)
`colorEdges` | `character` color of edges, in hexa. Default to #8181F7
`nodesFontSize` | `numeric`, size of labels of nodes. Default to 16
`edgesFontSize` | `numeric`, size of labels of edges Default to 14
`edgesFontAlign` | `character`, for edges only. Default tp 'horizontal'. Possible options: 'horizontal' (Default),'top','middle','bottom'. See visEdges
`legend` | `boolean`, add legend ? Default TRUE. visLegend
`legendNodesSize` | `numeric`, size of nodes in legend. Default to 22
`legendFontSize` | `numeric`, size of labels of nodes in legend. Default to 16
`legendWidth` | `numeric`, legend width, between 0 and 1. Default 0.1
`legendNcol` | `numeric`, number of columns in legend. Default 1
`legendPosition` | `character`, one of "left" (Default) or "right"
`nodesPopSize` | `boolean`, nodes sizes depends on population ? Default to FALSE
`minNodeSize` | `numeric`, in case of `nodesPopSize`, minimum size of a node. Defaut to 15. Else, nodes size is minNodeSize + maxNodeSize / 2
`maxNodeSize` | `numeric`, in case of `nodesPopSize`, maximum size of a node. Defaut to 30. Else, nodes size is minNodeSize + maxNodeSize / 2
`highlightNearest` | `list`, Highlight nearest nodes. See visOptions
`collapse` | `list`, collapse or not using double click on a node ? See visOptions
`updateShape` | `boolean`, in case of collapse, udpate cluster node shape as terminal node ? Default to TRUE
`tooltipDelay` | `numeric`, delay for tooltips in millisecond. Default 500
`digits` | `numeric`, number of digits. Default to 3
`height` | `character`, default to "600px"
`width` | `character`, default to "100%"
`export` | `boolean`, add export button. Default to TRUE

### Value

a visNetwork object

### See Also

visTreeEditor, visTreeModuleServer

### Examples

    ## Not run:

    library(rpart)

    # Basic classification tree
    res <- rpart(Species~., data=iris)
    visTree(res, 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, height = "800px", nodesPopSize = TRUE, minNodeSize = 10, maxNodeSize = 30)

    # ----- 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
    # disable hover highlight
    visTree(res, rules = FALSE, tooltipDelay = 0,
     highlightNearest = list(enabled = TRUE, degree = list(from = 50000, to = 0),
     hover = FALSE, 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"))

    ## End(Not run)

[Package visNetwork version 2.0.1 Index]