Colour specific node in igraph

感情迁移 提交于 2019-12-11 04:39:01

问题


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,
)

I tried the ifelse() above but they don't seem to take numerical value. I would appreciate some help please.

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.

Thank you!


回答1:


You could do

V(g)$color <- "red" 
V(g)$color[6] <- "white"
V(g)$color[7] <- "green"



回答2:


You can also do:

V(g)["nameofnode"]$color<-"red"


来源:https://stackoverflow.com/questions/31992685/colour-specific-node-in-igraph

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!