问题
How to change a color label node from its id or name?
Ex: I want to change label color node name="4" or id=3
g9<- graph(c(0,1,0,2,0,3,1,4,1,2,3,4,3,5,4,5,5,2),n=6,dir=FALSE)
V(g9)$name<-c(1:6)
V(g9)$label<-V(g9)$name
回答1:
V(g9)$color is an array of colors.
To change color of a specific node say 2:
V(g9)$color[2] ="#343434FF"
If you want different color for each node, you can specify rainbow(n) where n is number of nodes and this function generates a array of colors and then you can specify: V(g9)$color=rainbow(9)
Also note: To get a list of vertices or nodes you can get them: V(g9)
and then if you decide to change the color of vertex 5, you can use V(g9)$color[which(V(g9)==5)]="#434344"
where, which(V(g9)==5) matches to vertex or node 5.
来源:https://stackoverflow.com/questions/10587903/change-attributes-of-one-node