问题
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