Movatterモバイル変換


[0]ホーム

URL:


Type:Package
Title:Interactive Collapsible Tree Diagrams using 'D3.js'
Version:0.1.8
Maintainer:Adeel Khan <AdeelK@gwu.edu>
Description: Interactive Reingold-Tilford tree diagrams created using 'D3.js', where every node can be expanded and collapsed by clicking on it. Tooltips and color gradients can be mapped to nodes using a numeric column in the source data frame. See 'collapsibleTree' website for more information and examples.
License:GPL (≥ 3)
URL:https://github.com/AdeelK93/collapsibleTree,https://AdeelK93.github.io/collapsibleTree/
BugReports:https://github.com/AdeelK93/collapsibleTree/issues
Encoding:UTF-8
Depends:R (≥ 3.0.0)
Imports:htmlwidgets, data.tree, stats, methods
Enhances:knitr, shiny
RoxygenNote:7.2.3
Suggests:colorspace, RColorBrewer, dplyr, testthat, tibble
NeedsCompilation:no
Packaged:2023-11-13 05:25:03 UTC; Adeel
Author:Adeel Khan [aut, cre], Dhrumin Shah [ctb], Mike Bostock [ctb, cph] (D3.js library, http://d3js.org)
Repository:CRAN
Date/Publication:2023-11-13 05:53:23 UTC

Create 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.

Usage

collapsibleTree(  df,  ...,  inputId = NULL,  attribute = "leafCount",  aggFun = sum,  fill = "lightsteelblue",  linkLength = NULL,  fontSize = 10,  tooltip = FALSE,  tooltipHtml = NULL,  nodeSize = NULL,  collapsed = TRUE,  zoomable = TRUE,  width = NULL,  height = NULL)## S3 method for class 'data.frame'collapsibleTree(  df,  hierarchy,  root = deparse(substitute(df)),  inputId = NULL,  attribute = "leafCount",  aggFun = sum,  fill = "lightsteelblue",  fillByLevel = TRUE,  linkLength = NULL,  fontSize = 10,  tooltip = FALSE,  nodeSize = NULL,  collapsed = TRUE,  zoomable = TRUE,  width = NULL,  height = NULL,  ...)## S3 method for class 'Node'collapsibleTree(  df,  hierarchy_attribute = "level",  root = df$name,  inputId = NULL,  attribute = "leafCount",  aggFun = sum,  fill = "lightsteelblue",  linkLength = NULL,  fontSize = 10,  tooltip = FALSE,  tooltipHtml = NULL,  nodeSize = NULL,  collapsed = TRUE,  zoomable = TRUE,  width = NULL,  height = NULL,  ...)

Arguments

df

adata.frame from which to construct a nested list(where every row is a leaf) or a preconstructeddata.tree

...

other arguments to pass onto S3 methods that implementthis generic function -collapsibleTree.data.frame,collapsibleTree.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 usedfor tooltips, if applicable. Defaults to 'leafCount',which is the cumulative count of a node's children

aggFun

aggregation function applied to the attribute column to determinevalues of parent nodes. Defaults tosum, butmean also makes sense.

fill

either a single color or a mapping of colors:

  • Fordata.frame input, a vector of colors the same length as the numberof nodes. By default, vector should be ordered by level, such that the root color isdescribed first, then all the children's colors, and then all the grandchildren's colors

  • Fordata.tree input, a tree attribute containing the color for each node

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.

tooltipHtml

column name (possibly containing html) to override default tooltipcontents, allowing for more advanced customization. Applicable only fordata.tree input.

nodeSize

numeric column that will be used to determine relative node size.Default is to have a constant node size throughout. 'leafCount' can alsobe 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

  • Fordata.frame input, can also be a vector of logical values the same lengthas the number of nodes. Follows the same logic as the fill vector.

  • Fordata.tree input, can also be a tree attribute for conditionally collapsing nodes

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)

hierarchy

a character vector of column names that define the orderand hierarchy of the tree network. Applicable only fordata.frame input.

root

label for the root node

fillByLevel

which order to assign fill values to nodes.TRUE: Filling by level; will assign fill values to nodes vertically.FALSE: Filling by order; will assign fill values to nodes horizontally.

hierarchy_attribute

name of thedata.tree attribute that containshierarchy information of the tree network. Applicable only fordata.tree input.

Source

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

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

Examples

collapsibleTree(warpbreaks, c("wool", "tension", "breaks"))# Data from US Forest Service DataMartspecies <- read.csv(system.file("extdata/species.csv", package = "collapsibleTree"))collapsibleTree(df = species, c("REGION", "CLASS", "NAME"), fill = "green")# Visualizing the order in which the node colors are filledlibrary(RColorBrewer)collapsibleTree(  warpbreaks, c("wool", "tension"),  fill = brewer.pal(9, "RdBu"),  fillByLevel = TRUE)collapsibleTree(  warpbreaks, c("wool", "tension"),  fill = brewer.pal(9, "RdBu"),  fillByLevel = FALSE)# Tooltip can be mapped to an attribute, or default to leafCountcollapsibleTree(  warpbreaks, c("wool", "tension", "breaks"),  tooltip = TRUE,  attribute = "breaks")# Node size can be mapped to any numeric column, or to leafCountcollapsibleTree(  warpbreaks, c("wool", "tension", "breaks"),  nodeSize = "breaks")# collapsibleTree.Node exampledata(acme, package="data.tree")acme$Do(function(node) node$cost <- data.tree::Aggregate(node, attribute = "cost", aggFun = sum))acme$Do(function(node) node$lessThanMillion <- node$cost < 10^6)collapsibleTree(  acme,  nodeSize  = "cost",  attribute = "cost",  tooltip = TRUE,  collapsed = "lessThanMillion")# Emulating collapsibleTree.data.frame using collapsibleTree.Nodespecies <- read.csv(system.file("extdata/species.csv", package = "collapsibleTree"))hierarchy <- c("REGION", "CLASS", "NAME")species$pathString <- paste(  "species",  apply(species[,hierarchy], 1, paste, collapse = "//"),  sep = "//")df <- data.tree::as.Node(species, pathDelimiter = "//")collapsibleTree(df)

Shiny bindings for collapsibleTree

Description

Output and render functions for using collapsibleTree within Shinyapplications and interactive Rmd documents.

Usage

collapsibleTreeOutput(outputId, width = "100%", height = "400px")renderCollapsibleTree(expr, env = parent.frame(), quoted = FALSE)

Arguments

outputId

output variable to read from

width,height

Must be a valid CSS unit (like'100%','400px','auto') or a number, which will be coerced to astring and have'px' appended.

expr

An expression that generates a collapsibleTree

env

The environment in which to evaluateexpr.

quoted

Isexpr a quoted expression (withquote())? Thisis useful if you want to save an expression in a variable.

Examples

if(interactive()) {  # Shiny Interaction  shiny::runApp(system.file("examples/02shiny", package = "collapsibleTree"))  # Interactive Gradient Mapping  shiny::runApp(system.file("examples/03shiny", package = "collapsibleTree"))}

Create Network 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 for network style data framescontaining the node's parent in the first column, node parent in the secondcolumn, and additional attributes in the rest of the columns. The root nodeis denoted by having anNA for a parent. There must be exactly 1 root.

Usage

collapsibleTreeNetwork(  df,  inputId = NULL,  attribute = "leafCount",  aggFun = sum,  fill = "lightsteelblue",  linkLength = NULL,  fontSize = 10,  tooltip = TRUE,  tooltipHtml = NULL,  nodeSize = NULL,  collapsed = TRUE,  zoomable = TRUE,  width = NULL,  height = NULL)

Arguments

df

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

  • First column must be the parent (NA for root node)

  • Second column must be the child

  • Additional columns are passed on as attributes for other parameters

  • There must be exactly 1 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.(ForcollapsibleTreeNetwork the names of the list are tree depth)

attribute

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

aggFun

aggregation function applied to the attribute column to determinevalues of parent nodes. Defaults tosum, butmean also makes sense.

fill

either a single color or a column name with the color for each node

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.

tooltipHtml

column name (possibly containing html) to overridedefault tooltip contents, allowing for more advanced customization

nodeSize

numeric column that will be used to determine relative node size.Default is to have a constant node size throughout. 'leafCount' can alsobe 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.Can also be a logical value found in the data for conditionally collapsing nodes.

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)

Source

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

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

See Also

FromDataFrameNetwork for underlying functionthat constructs trees from the network data frame

Examples

# Create a simple org chartorg <- data.frame(  Manager = c(    NA, "Ana", "Ana", "Bill", "Bill", "Bill", "Claudette", "Claudette", "Danny",    "Fred", "Fred", "Grace", "Larry", "Larry", "Nicholas", "Nicholas"  ),  Employee = c(    "Ana", "Bill", "Larry", "Claudette", "Danny", "Erika", "Fred", "Grace",    "Henri", "Ida", "Joaquin", "Kate", "Mindy", "Nicholas", "Odette", "Peter"  ),  Title = c(    "President", "VP Operations", "VP Finance", "Director", "Director", "Scientist",    "Manager", "Manager", "Jr Scientist", "Operator", "Operator", "Associate",     "Analyst", "Director", "Accountant", "Accountant"  ))collapsibleTreeNetwork(org, attribute = "Title")# Add in colors and sizesorg$Color <- org$Titlelevels(org$Color) <- colorspace::rainbow_hcl(11)collapsibleTreeNetwork(  org,  attribute = "Title",  fill = "Color",  nodeSize = "leafCount",  collapsed = FALSE)# Use unsplash api to add in random photos to tooltiporg$tooltip <- paste0(  org$Employee,  "<br>Title: ",  org$Title,  "<br><img src='https://source.unsplash.com/collection/385548/150x100'>")collapsibleTreeNetwork(  org,  attribute = "Title",  fill = "Color",  nodeSize = "leafCount",  tooltipHtml = "tooltip",  collapsed = FALSE)

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 nodeseither by counting that node's children (default) or specifying another numericcolumn 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 orderand 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 usedas 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 vectorof 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 thesake of coloring in the nodes (but not the ordering of nodes). Setting this valuetoo high will make it difficult to tell the difference between nodes with manychildren.

percentOfParent

toggle attribute tooltip to be percent of parentrather 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 alsobe 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 implementedif 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 tofillFun, such declaring apalette forbrewer.pal

Source

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

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

Examples

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

[8]ページ先頭

©2009-2025 Movatter.jp