This post describes how to build a basic
treemap with d3.js from a
Json format input file. See
here for .csv input
format. More treemaps in the
dedicated section of the gallery. This
example works with d3.js v4 and v6
.json format.
Have a look
.csv input, you can transform it
with the code below, or see
this example.
d3.hierarchy directly, without reshaping step
that increase loading time of the chart.
Json format
The
d3r R library
allows to switch from
.csv format to
json format. Here
is the R code allowing to build the json file used above.
# Load library
library(d3r)
# Build a dummy data frame
data <- data.frame(
level2=c( rep("boss1",4), rep("boss2",4), rep("boss3",6)),
level3=paste0("mister_", letters[1:14]),
value=rep(23,14),
group=c("A","A","C","C","C","A","B","B","B","A","A","D","D","D" )
)
# Create the json format. Note that columns that are leave features are specified.
a <- d3_nest(data, root="CEO", value_cols=c("group", "value"))
# Save it in a .json file
write(a, "data_dendrogram_full.json")