[英]R igraph rename vertices
是否有可能重命名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個節點的圖形
您可以使用
ay <- set.vertex.attribute(az, "name", value=paste("y",1:27,sep=""))
也適用於"label"
而不是"name"
。
如果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
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.