是否有可能重命名igraph中的顶点。我想在顶点上用不同的符号多次绘制某个图形。鉴于以下igraph az:
> az
IGRAPH DN-- 24 23 --
+ attr: name (v/c), label (v/c), color (v/c), fill (v/c), width (e/n)
与
> V(az)
Vertex sequence:
[1] "x1" "x2" "x3" "x4" "x5" "x7" "x8" "x9" "x10" "x11" "x12" "x13"
[13] "x14" "x15" "x16" "x19" "x20" "x21" "x22" "x23" "x24" "x25" "x26" "x27"
我想将顶点更改为,比如y1-y27 但是,
V(az)$name <- paste("y",1:27,sep="")
无效。我怎样才能做到这一点? 提前谢谢。
干杯
编辑: 作为记录。
V(az)$name <- paste("y",1:27,sep="")
以这种方式工作,以便它返回:
> V(az)
Vertex sequence:
[1] "y1" "y2" "y3" "y4" "y5" "y7" "y8" "y9" "y10" "y11" "y12" "y13"
[13] "y14" "y15" "y16" "y19" "y20" "y21" "y22" "y23" "y24" "y25" "y26" "y27"
然而,plot(az)stills返回带有x个节点的图形
答案 0 :(得分:13)
您可以使用
ay <- set.vertex.attribute(az, "name", value=paste("y",1:27,sep=""))
也适用于"label"
而不是"name"
。
答案 1 :(得分:10)
如果V(az)同时具有一组“名称”属性和一组“标签”属性,则会绘制“标签”属性。
> gt <- graph.tree(24, children = 4, mode=c("out", "in", "undirected"))
> V(gt)$name <- letters[1:24]
> plot(gt) # So 'name's get displayed if no label is present
> V(gt)$label <- LETTERS[1:24]
> plot(gt) # Labels get displayed
> V(gt)$name <- letters[1:24] # see if then get overwritten
> plot(gt) # Still plots with 'label's