d3_nest | R Documentation |
data.frame
to a 'd3.js' HierarchyConvert a data.frame
to a 'd3.js' Hierarchy
d3_nest(data = NULL, value_cols = character(), root = "root", json = TRUE)
data |
|
value_cols |
|
root |
|
json |
|
nested data.frame
# convert Titanic to a nested d3 hierarchy
# devtools::install_github("timelyportfolio/d3r")
library(d3r)
library(dplyr)
titanic_df <- data.frame(Titanic)
tit_tb <- titanic_df %>%
select(Class,Age,Survived,Sex,Freq) %>%
d3_nest(value_cols="Freq", root="titanic")
tit_tb
# see as tibble
titanic_df %>%
select(Class,Age,Survived,Sex,Freq) %>%
d3_nest(value_cols="Freq", root="titanic", json=FALSE)
# see the structure with listviewer
tit_tb %>%
listviewer::jsonedit()
## Not run:
library(treemap)
library(d3r)
library(dplyr)
library(tidyr)
treemap::random.hierarchical.data() %>%
d3_nest(value_cols = "x")
# use example from ?treemap
data(GNI2014)
treemap(
GNI2014,
index=c("continent", "iso3"),
vSize="population",
vColor="GNI",
type="value",
draw=FALSE
) %>%
{.$tm} %>%
select(continent,iso3,color,vSize) %>%
d3_nest(value_cols = c("color", "vSize"))
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.