All Projects → AdeelK93 → Collapsibletree

AdeelK93 / Collapsibletree

Create Interactive Collapsible Tree Diagrams in R using D3.js

Programming Languages

r
7636 projects

Projects that are alternatives of or similar to Collapsibletree

d3Tree
htmlwidget that binds d3js collapsible trees to R and Shiny to make an interactive search tool
Stars: ✭ 79 (-37.3%)
Mutual labels:  shiny, d3js, htmlwidgets
Scatterd3
R scatter plot htmlwidget based on D3.js
Stars: ✭ 135 (+7.14%)
Mutual labels:  shiny, htmlwidgets, d3js
rAmCharts4
An R interface to amCharts 4
Stars: ✭ 26 (-79.37%)
Mutual labels:  shiny, htmlwidgets
jsTreeR
A wrapper of the jQuery plugin `jsTree`.
Stars: ✭ 36 (-71.43%)
Mutual labels:  shiny, htmlwidgets
vueR
vue.js for R
Stars: ✭ 131 (+3.97%)
Mutual labels:  shiny, htmlwidgets
RagGrid
R interface to ag-grid.
Stars: ✭ 31 (-75.4%)
Mutual labels:  shiny, htmlwidgets
grillade
Grid sytem for shiny apps or rmarkdown and to create htmlwidgets matrix
Stars: ✭ 16 (-87.3%)
Mutual labels:  shiny, htmlwidgets
compareBars
Simplify comparative bar charts 📊
Stars: ✭ 28 (-77.78%)
Mutual labels:  d3js, htmlwidgets
DraggableRegressionPoints
Draggable regression points in R Shiny
Stars: ✭ 18 (-85.71%)
Mutual labels:  shiny, d3js
Rhandsontable
A htmlwidgets implementation of Handsontable.js
Stars: ✭ 320 (+153.97%)
Mutual labels:  shiny, htmlwidgets
rfrappe
htmlwidget for frappe charts js library
Stars: ✭ 24 (-80.95%)
Mutual labels:  shiny, htmlwidgets
Reactable
Interactive data tables for R
Stars: ✭ 345 (+173.81%)
Mutual labels:  shiny, htmlwidgets
Plotly
An interactive graphing library for R
Stars: ✭ 2,096 (+1563.49%)
Mutual labels:  shiny, d3js
Explor
Interfaces for Multivariate Analysis in R
Stars: ✭ 157 (+24.6%)
Mutual labels:  shiny, htmlwidgets
lineup htmlwidget
HTMLWidget wrapper of LineUp for Visual Analysis of Multi-Attribute Rankings
Stars: ✭ 51 (-59.52%)
Mutual labels:  shiny, htmlwidgets
Highcharter
R wrapper for highcharts
Stars: ✭ 583 (+362.7%)
Mutual labels:  shiny, htmlwidgets
Dt
R Interface to the jQuery Plug-in DataTables
Stars: ✭ 451 (+257.94%)
Mutual labels:  shiny, htmlwidgets
Manipulatewidget
Add More Interactivity to htmlwidgets
Stars: ✭ 110 (-12.7%)
Mutual labels:  shiny, htmlwidgets
Excelr
An Interface to 'jExcel.js' Library
Stars: ✭ 106 (-15.87%)
Mutual labels:  shiny
Just Dashboard
📊 📋 Dashboards using YAML or JSON files
Stars: ✭ 1,511 (+1099.21%)
Mutual labels:  d3js

collapsibleTree 0.1.7

CRAN_Status_Badge CRAN downloads

collapsibleTree is an R htmlwidget that allows you to create interactive collapsible Reingold-Tilford tree diagrams using D3.js, adapted from Mike Bostock’s example. Turn your data frame into a hierarchical visualization without worrying about nested lists or JSON objects!

If you’re using Shiny, you can bind the most recently clicked node to a Shiny input, allowing for easier interaction with complex nested objects. The input will return a named list containing the most recently selected node, as well as all of its parents. See the Shiny example for more info.

Installation

# Install package from CRAN:
install.packages("collapsibleTree")

# Alternately, install the latest development version from GitHub:
# install.packages("devtools")
devtools::install_github("AdeelK93/collapsibleTree")

Changelog can be found here.

Usage

When working with data in R, it makes sense (at least to me) to represent everything as a data frame. I’m a big fan of tidy data, but this structure does not lend itself to easily designing hierarchical networks.

collapsibleTree uses data.tree to handle all of that, freeing you from a lot of recursive list construction.

Click here to see some interactive charts.

library(collapsibleTree)

collapsibleTree(warpbreaks, c("wool", "tension", "breaks"))

Collapsible Tree

The color of each node can be customized to draw attention to the levels of hierarchy. Thanks to Ryan Derickson for the implementation idea! Colors can be constants or generated from a gradient function.

# Data from US Forest Service DataMart
species <- read.csv("https://apps.fs.usda.gov/fia/datamart/CSV/REF_SPECIES_GROUP.csv")

collapsibleTree(
  species,
  hierarchy = c("REGION", "CLASS", "NAME"), 
  fill = c(
    # The root
    "seashell",
    # Unique regions
    rep("brown", length(unique(species$REGION))),
    # Unique classes per region
    rep("khaki", length(unique(paste(species$REGION, species$CLASS)))),
    # Unique names per region
    rep("forestgreen", length(unique(paste(species$NAME, species$REGION))))
  )
)

Collapsible Tree Colored

Gradients can be mapped to a column in the data frame to help visualize relative weightings of nodes. Node weighting can also be mapped to a tooltip.

collapsibleTreeSummary(
  warpbreaks,
  c("wool", "tension", "breaks"),
  attribute = "breaks",
  maxPercent = 50
)

Collapsible Tree Gradient

Likewise, node size can also be mapped to a column in the data frame to help visualize relative weightings of nodes.

collapsibleTreeSummary(
  warpbreaks,
  c("wool", "tension", "breaks"),
  attribute = "breaks",
  maxPercent = 50,
  nodeSize = "breaks",
  collapsed = FALSE
)

Collapsible Tree Gradient

Parent-child relationships can be mapped to the tree to give more customizability for each node, such as passing custom html elements to each node.

# Create a simple org chart
org <- 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"
  )
)

# Add in colors and sizes
org$Color <- org$Title
levels(org$Color) <- colorspace::rainbow_hcl(11)

# Use unsplash api to add in random photos to tooltip
org$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"
)

Collapsible Tree Network

Shiny Interaction

An interactive Shiny demo is also included. For example, you could use the collapsibleTree htmlwidget to select a portion of a larger categorical dataset, with your filter being as deep or shallow as you’d prefer. You can find a live demo here, or run the included examples locally.

# Basic Shiny Interaction
shiny::runApp(system.file("examples/02shiny", package = "collapsibleTree"))

# Interactive Gradient Mapping
shiny::runApp(system.file("examples/03shiny", package = "collapsibleTree"))

Issues and Suggestions

Feel free to submit an issue if you run into any bugs or have any feature suggestions! Would love to hear your comments.

Test Results

library(collapsibleTree)
date()
#> [1] "Mon Nov 12 10:26:36 2018"

testthat::test_dir("tests/testthat", reporter = testthat::SummaryReporter)
#> Error handling: .........
#> Margin sizing: ................
#> Missing values: ....
#> Network: .........
#> Root labelling: ..........
#> 
#> ══ DONE ═══════════════════════════════════════════════════════════════════════════════
#> You are a coding rockstar!
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].