在R中将数据结构绘制为树 [英] plot data structure as a tree in R
问题描述
我正在使用 plotrix
包中的 sizetree()
函数绘制我的数据
作为树的结构(请参见下文),它可以正常工作。
但是,我想知道是否还有其他方法(或程序包)可以为相同的 data
是否显示相同的信息?
(注意:在下面的图中,字体不必要太大或太大了较小,因此矩形等也可以将图倒置以获得更好的外观。)-这是主观的,但我很感谢任何建议!
library(plotrix)
数据<-read.csv('https://raw.githubusercontent.com/hkil/m/master/ z.csv')
sizetree(data [c(2,3,5)])
这是有根据的猜测。也许...
X<-read.csv(url( https://raw.githubusercontent.com/hkil /m/master/z.csv))
energy<-jsonlite :: fromJSON(URL)
#绘制
sankeyNetwork(Links = energy $ scid,节点=能源$ group,源='源',
目标='目标',值='值',NodeID ='名称',
单位='TWh',fontSize = 12 nodeWidth = 30)
#颜色链接
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 ='名称',
LinkGroup ='energy_type',NodeGroup = NULL)
请参阅li
https://www.rdocumentation.org/packages/networkD3/versions/0.4/topics/sankeyNetwork
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)])
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
这篇关于在R中将数据结构绘制为树的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!