json - Collapsible tree in R -


i motivated article regarding collapsible tree in r

http://bl.ocks.org/mbostock/4339083

i trying reproduce same example using toy dataset this

id      car bus train   feedback_car    feedback_bus    feedback_train 23433   yes yes yes     toyota          greyhound       amtrak 

which can represented collapsible tree follows

enter image description here

i wondering if can me reproduce concept (collapsible trees) using toy dataset above, example give me idea how different components work, example formatting json data in r etc...and serve starting point. in advance.

you can use data.tree package data converted json, or use networkd3 package:

dat <- read.table(text="id      car bus train   feedback_car    feedback_bus    feedback_train 23433   yes yes yes     toyota          greyhound       amtrak", header=true)  ## make edgelist data edges <- rbind(cbind(dat$id, names(dat)[2:4]),                cbind(names(dat)[2:4], as.vector(t(dat[5:7]))))  library(data.tree) tree <- fromdataframenetwork(as.data.frame(edges))  tree 

that print this:

          levelname 1 23433             2  ¦--car           3  ¦   °--toyota    4  ¦--bus           5  ¦   °--greyhound 6  °--train         7      °--amtrak    

now, use tree structure plot networkd3:

lol <- tolistexplicit(tree, unname = true)  library(networkd3)  diagonalnetwork(lol) 

unfortunately, doesn't support collapsible trees yet. here example how want shiny. in order convert data correct json format, this:

library(jsonlite) json <- tojson(lol) 

Comments

Popular posts from this blog

javascript - Chart.js (Radar Chart) different scaleLineColor for each scaleLine -

apache - Error with PHP mail(): Multiple or malformed newlines found in additional_header -

android - Go back to previous fragment -