collapsibleTreeSummary {collapsibleTree}R Documentation

Create Summary Interactive Collapsible Tree Diagrams

Description

Interactive Reingold-Tilford tree diagram created using D3.js, where every node can be expanded and collapsed by clicking on it. This function serves as a convenience wrapper to add color gradients to nodes either by counting that node's children (default) or specifying another numeric column in the input data frame.

Usage

collapsibleTreeSummary(
  df,
  hierarchy,
  root = deparse(substitute(df)),
  inputId = NULL,
  attribute = "leafCount",
  fillFun = colorspace::heat_hcl,
  maxPercent = 25,
  percentOfParent = FALSE,
  linkLength = NULL,
  fontSize = 10,
  tooltip = TRUE,
  nodeSize = NULL,
  collapsed = TRUE,
  zoomable = TRUE,
  width = NULL,
  height = NULL,
  ...
)

Arguments

df

a data frame (where every row is a leaf) from which to construct a nested list

hierarchy

a character vector of column names that define the order and hierarchy of the tree network

root

label for the root node

inputId

the input slot that will be used to access the selected node (for Shiny). Will return a named list of the most recently clicked node, along with all of its parents.

attribute

numeric column not listed in hierarchy that will be used as weighting to define the color gradient across nodes. Defaults to 'leafCount', which colors nodes by the cumulative count of its children

fillFun

function that takes its first argument and returns a vector of colors of that length. rainbow_hcl is a good example.

maxPercent

highest weighting percent to use in color scale mapping. All numbers above this value will be treated as the same maximum value for the sake of coloring in the nodes (but not the ordering of nodes). Setting this value too high will make it difficult to tell the difference between nodes with many children.

percentOfParent

toggle attribute tooltip to be percent of parent rather than the actual value of attribute

linkLength

length of the horizontal links that connect nodes in pixels. (optional, defaults to automatic sizing)

fontSize

font size of the label text in pixels

tooltip

tooltip shows the node's label and attribute value.

nodeSize

numeric column that will be used to determine relative node size. Default is to have a constant node size throughout. 'leafCount' can also be used here (cumulative count of a node's children), or 'count' (count of node's immediate children).

collapsed

the tree's children will start collapsed by default (There is no conditional collapsing in this function yet, but it could be implemented if there's sufficient demand)

zoomable

pan and zoom by dragging and scrolling

width

width in pixels (optional, defaults to automatic sizing)

height

height in pixels (optional, defaults to automatic sizing)

...

other arguments passed on to fillFun, such declaring a palette for brewer.pal

Source

Christopher Gandrud: http://christophergandrud.github.io/networkD3/.

d3noob: https://bl.ocks.org/d3noob/43a860bc0024792f8803bba8ca0d5ecd.

Examples

# Color in by number of children
collapsibleTreeSummary(warpbreaks, c("wool", "tension", "breaks"), maxPercent = 50)

# Color in by the value of breaks and use the terrain_hcl gradient
collapsibleTreeSummary(
  warpbreaks,
  c("wool", "tension", "breaks"),
  attribute = "breaks",
  fillFun = colorspace::terrain_hcl,
  maxPercent = 50
)

[Package collapsibleTree version 0.1.8 Index]