2014-12-04 62 views
1

我希望創建聯網弧形圖。我的問題是弧是正確的,節點的順序也是如此。但是,節點(度)和填充以及邊框顏色(vfill,vborder)的大小不匹配頂點的屬性。R:頂點屬性與弧形圖中的頂點名稱不匹配

我.gml文件可以在https://dl.dropboxusercontent.com/u/42761499/myarc.gml

代碼下載:

library(igraph) 
library(arcdiagram) 
dat.g2 = read.graph("myarc.gml", format = "gml") 
vlabels<-get.vertex.attribute(dat.g2, "name") 
vfill<-get.vertex.attribute(dat.g2, "vfill") 
vborder<-get.vertex.attribute(dat.g2, "vborder") 
vgroups<-get.vertex.attribute(dat.g2, "group") 
degrees<-get.vertex.attribute(dat.g2,"degree") 
edgelist<-get.edgelist(dat.g2) 
values<-as.numeric(get.edge.attribute(dat.g2, "value")) 
par(mai=c(2.25,.25,.25,.25)) 
arc.p<-arcplot(edgelist, cex.labels = 0.8, 
      ordering = vlabels, 
      show.nodes = TRUE, 
      col.nodes = vborder, 
      bg.nodes = vfill, 
      cex.nodes = sqrt(degrees)/20, 
      pch.nodes = 21, 
      lwd.nodes = 2, 
      line = 0.3, 
      col.arcs = hsv(0, 0, 0.1, 0.4), 
      lwd.arcs = sqrt(values)/2, 
      horizontal=TRUE, 
      axes=FALSE) 

在情節的顏色和大小的節點,有時是錯誤的。 「其他投訴」應該是紫色的,CHPAIN黃色。至少CHPAIN和CARDOTH的大小是錯誤的(CHPAIN大於CARDOTH,請參閱myarc.gml)。我認爲這個問題是因爲在邊緣列表中,每個節點的名稱首先以與頂點順序略有不同的順序出現。 通過邊緣列表順序我的意思是當一個人看着整個行然後沿着列向下看時節點名稱的唯一外觀。 iethe前5行邊緣列表的讀取:

  • 從到
  • 1胸痛,MI,CA,VF AF
  • 2胸痛,MI,CA,VF暈厥
  • 3胸疼痛,MI,CA,VF SOB
  • 4胸痛,MI,CA,VF CHPAIN
  • 5胸痛,MI,CA,VF CARDOTH

所以電子dge列表順序爲「胸痛,MI,CA,VF」,「AF」,「暈厥」,「SOB」,「CHPAIN」,「CARDOTH」...頂點順序爲「胸痛,MI,CA,如何獲得頂點屬性(vfill,vborder,degrees)與頂點匹配圖上的名字?

+0

的'arcdiagram'包是在這裏:https://github.com/gastonstat/arcdiagram如果有人想知道.... – 2014-12-04 18:49:45

回答

2

您只需要明確設置vertices=參數。這是函數如何知道保留每個*.nodes屬性分配給哪些值。您可以使用它來代替您現在設置的ordering=參數,因爲您根本沒有重新排序節點。

arc.p<-arcplot(edgelist, vlabels, cex.labels = 0.8, 
    show.nodes = TRUE, 
    col.nodes = vborder, 
    bg.nodes = vfill, 
    cex.nodes = sqrt(degrees)/20, 
    pch.nodes = 21, 
    lwd.nodes = 2, 
    line = 0.3, 
    col.arcs = hsv(0, 0, 0.1, 0.4), 
    lwd.arcs = sqrt(values)/2, 
    horizontal=TRUE, 
    axes=FALSE) 

enter image description here