如何在igraph中将分类属性设置为顶点

时间:2019-05-23 18:02:28

标签: r igraph

我试图将一堆分类属性设置为顶点的属性,然后根据其类型为节点着色。当我尝试将属性传递给图形时,出现警告提示

"In vattrs[[name]][index] <- value :
  number of items to replace is not a multiple of replacement length"

我什至将属性设置为字符,但警告仍然显示。

V(g4)$affiliation<-as.character(join4$Affiliation)

我有4种类别,但是当我尝试将它们作为属性传递时,它们仅转换为两种类型。

head(join4)
   Source Destination      Affiliation
2       2          25          Liberal
3       2          25          Liberal
4       2          25          Liberal
25     23          23 Slightly liberal
26     23          23 Slightly liberal
27     24          58          Liberal

tail(join4)

      Source      Destination    Affiliation
100     46          44           Extremely liberal
101     46          44           Extremely liberal
102     46          32           Extremely liberal
107     51          51 Moderate middle of the road
108     51          51 Moderate middle of the road
113     57          57                     Liberal

如您所见,所有节点都变得自由或稍微自由

g4<-graph.data.frame(join4,directed=F)
V(g)$affiliation<-as.character(join4$Affiliation)

 V(g4)$affiliation
 [1] "Liberal"          "Liberal"         
 [3] "Liberal"          "Slightly liberal"
 [5] "Slightly liberal" "Liberal"         
 [7] "Liberal"          "Liberal"         
 [9] "Liberal"          "Liberal"         
[11] "Liberal"          "Liberal"         
[13] "Liberal"          "Liberal"         
[15] "Liberal"          "Liberal"         
[17] "Liberal"          "Liberal"         
[19] "Liberal"          "Liberal"         
[21] "Liberal"          "Liberal"         
[23] "Liberal"

我希望将相应的类别与相应的名称相关联。我该怎么办?

0 个答案:

没有答案