plot data structure as a tree in R

萝らか妹 提交于 2020-05-27 06:21:29

问题


I'm using sizetree() function from plotrix package to draw my data structure as a tree (see below) and it works just fine.

However, I was wondering if there might be another way (or a package) that would provide a more elegant tree plot of the same data with the same information displayed?

(Note: In the below plot, fonts are unnecessarily either too big or too small so are the rectangles etc. also may be the plot could be inverted to get a better look.)-- it's subjective but I appreciate any suggestion!

library(plotrix)

data <- read.csv('https://raw.githubusercontent.com/hkil/m/master/z.csv')

sizetree(data[c(2,3,5)])


回答1:


This is an educated guess. Maybe...

X <- read.csv(url("https://raw.githubusercontent.com/hkil/m/master/z.csv"))

energy <- jsonlite::fromJSON(URL)

# Plot
sankeyNetwork(Links = energy$scid, Nodes = energy$group, Source = 'source',
             Target = 'target', Value = 'value', NodeID = 'name',
             units = 'TWh', fontSize = 12, nodeWidth = 30)

# Colour links
energy$links$energy_type <- sub(' .*', '',
                               energy$nodes[energy$links$source + 1, 'name'])

sankeyNetwork(Links = energy$links, Nodes = energy$nodes, Source = 'source',
             Target = 'target', Value = 'value', NodeID = 'name',
             LinkGroup = 'energy_type', NodeGroup = NULL)

See the link below for reference.

https://www.rdocumentation.org/packages/networkD3/versions/0.4/topics/sankeyNetwork



来源:https://stackoverflow.com/questions/61924157/plot-data-structure-as-a-tree-in-r

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!