【发布时间】:2017-03-18 15:12:11
【问题描述】:
我的二元图基于边列表。每个顶点都是股票市场的行情代码(例如:BARC= Barclay's)
net_full_phase1=graph.edgelist(full_phase1, directed=FALSE)
V(net_full_phase1)$color=V(net_full_phase1)$name
V(net_full_phase1)$size=degree(net_full_phase1)
V(net_full_phase1)$color=gsub("BARC", "slategrey", V(net_full_phase1)$color)
V(net_full_phase1)$color=gsub("BNP", "blue", V(net_full_phase1)$color)
V(net_full_phase1)$color=gsub("CBK", "black", V(net_full_phase1)$color)
V(net_full_phase1)$color=gsub("WFC", "red", V(net_full_phase1)$color)
V(net_full_phase1)$color=gsub("BKIR", "orange", V(net_full_phase1)$color)
V(net_full_phase1)$color=gsub("ISP", "purple", V(net_full_phase1)$color)
V(net_full_phase1)$color=gsub("TPEIR", "lightblue", V(net_full_phase1)$color)
V(net_full_phase1)$color=gsub("SAB", "yellow", V(net_full_phase1)$color)
V(net_full_phase1)$color=gsub("BCP", "green", V(net_full_phase1)$color)
plot(net_full_phase1, layout=layout.fruchterman.reingold)
我得到这个错误:
符号错误(x = coords[, 1], y = coords[, 2], bg = vertex.color, : nom de couleur 'WFred' 不正确
刚跑unique(as.character(V(net_full_phase1)$name))
结果如下:
"BARC" "WFC" "ISP" "TPEIR" "BCP" "SAB" "BNP" "CBK" "BKIR"
我也跑了:table(V(net_full_phase1)$color) 结果:
black blue BredP green lightblue purple red redIR slategrey WFred yellow
为什么 R 不将某些颜色视为“BredP”、“redIR”、“WFred”?
【问题讨论】:
-
我认为它告诉您
gsub("WFC", "red", V(net_full_phase1)$color)不会评估为有效颜色......不知何故,对我来说并不明显。我会先自己运行那段代码,可能包含在table()中。 -
或扩展 Frank 的建议,在运行所有 gsub 后查看
table(V(net_full_phase1)$color)。有哪些颜色? -
我可以在没有颜色规范的情况下运行代码。一旦我对颜色进行编码,它就不起作用了。刚跑 table(V(net_full_phase1)$color) 结果是: black blue BredP green lightblue Purple red redIR slategrey UredG WFred yellow
-
好的,谢谢。很明显,其中一些不是颜色。
-
意思是“橙色”被“翻译”为:UredG、WFred、redIR和BredP?