Change attributes of one node

余生颓废 提交于 2019-12-07 21:40:21

问题


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

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