igraph中的颜色特定节点 [英] Colour specific node in igraph
本文介绍了igraph中的颜色特定节点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图为节点6和7着色,无论从对象'd'中选择了什么字母.
I am trying to colour node 6 and 7 regardless of whatever letter is selected from object 'd'.
g <- graph_from_literal(1:2:3:4:5 -- 6:7)
# Rename (sum up all the vertices)
d <- c("a", "b", "c", "d", "e", "f", "g","h", "i", "j")
V(g)$name <- sample(d, 7, replace=TRUE)
colours <- c("red")
V(g)$color <- ifelse(V(g)$name == c('a','e'), "white", colours)
plot.igraph(g, layout=layout_with_dh, vertex.label=V(g)$name,
vertex.size=35,
vertex.color=V(g)$color, #colors.r
vertex.label.cex=0.7,
)
我尝试了上面的ifelse(),但是它们似乎没有数值.我希望得到一些帮助.
I tried the ifelse() above but they don't seem to take numerical value. I would appreciate some help please.
我想要的是节点6例如白色,例如7绿色,其他节点均为红色.
What I want is that node 6 is e.g. white and 7 is e.g. green and the rest of the other nodes are red.
谢谢!
推荐答案
您可以做到
V(g)$color <- "red"
V(g)$color[6] <- "white"
V(g)$color[7] <- "green"
这篇关于igraph中的颜色特定节点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文