如何在R中绘制具有特定节点特定属性的条形图?我有一个像这样的gml文件:
graph [
node [
id 0
label "Apple"
year 1997
bold 1
normal 4
light 15
]
node [
id 1
label "Apple"
year 2000
bold 2
normal 16
light 2
]
node [
id 2
label "BBC"
year 2010
bold 18
normal 2
light 0
]
]
并且我运行此R脚本,当我需要从节点选择中提取属性值时遇到麻烦:
install.packages(c("igraph"))
library(igraph)
g = read.graph(file = "/media/Data/TEMP/R_test/test.gml", format = "gml")
apple = V(g)$label[V(g)$label == "Apple"]
table(apple)
for(i in seq(along=apple)){
mL = apple[,i]$bold
L = apple[,i]$normal
pL = apple[,i]$light
barplot(????)
}
我该如何修复该脚本?
这是苹果每年的粗体图:
df <- subset(as_data_frame(g, "vertices"), label=="Apple", c(year, bold))
barplot(df$bold, names.arg = df$year, main = "Apple")
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句