更改一个节点的属性 [英] Change attributes of one node
问题描述
如何从其ID或名称更改颜色标签节点?
How to change a color label node from its id or name?
例如:我想更改标签颜色节点名称="4"或id = 3
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
推荐答案
V(g9)$color
是颜色的数组.
要更改特定节点的颜色,请说2:
V(g9)$color[2] ="#343434FF"
To change color of a specific node say 2:
V(g9)$color[2] ="#343434FF"
如果每个节点需要不同的颜色,则可以指定rainbow(n)
,其中n是节点数,此函数生成颜色数组,然后可以指定:V(g9)$color=rainbow(9)
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)
还请注意:要获取顶点或节点的列表,您可以获取它们:V(g9)
然后如果您决定更改顶点5的颜色,则可以使用V(g9)$color[which(V(g9)==5)]="#434344"
其中,which(V(g9)==5)
匹配顶点或节点5.
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.
这篇关于更改一个节点的属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!