在 R igraph 中使用组创建变量

Creating Variables with Group in R igraph

以下是我的再生示例代码。

sender_code <- c(12  ,1  ,6 ,19  ,7  ,8  ,3 ,17 ,13 ,10  ,4  ,9  ,2  ,5 

,15 ,11 ,16 ,20 ,14 ,18)
receiver_code <- c( 20 ,16  ,7  ,3  ,4 ,11  ,8  ,2 ,10 ,12 ,17  ,5  ,1 ,18 ,13  ,9  ,6 ,15 ,19 ,14)

sender_country <- ifelse(sender_code<6,"Phil",
                      ifelse(sender_code<10,"Japan",
                             ifelse(sender_code<16,"Brazil",
                                    "Norway"
                                    )
                             )
                      )



receiver_country <- ifelse(receiver_code<6,"Phil",
                     ifelse(receiver_code<10,"Japan",
                            ifelse(receiver_code<16,"Brazil",
                                   "Norway"
                            )
                     )
)



message<- data.frame(sender_code,receiver_code,sender_country,receiver_country 

我想将每个发送者连接到每个接收者,然后根据他们的国家对他们进行颜色编码,如下图所示:

http://revolution-computing.typepad.com/.a/6a010534b1db25970b017c379af59c970b-pi

问题是我不知道 igraph 上的什么函数可以根据我的数据创建那种图表。

提前致谢

试试这个作为开始:

library(igraph)
with(message, 
  plot(graph.data.frame(message), 
       vertex.color = sender_country,
       vertex.label.color = "white",
       edge.color = sender_country)
)

?plot.igraph 下的更多信息。