Creating Variables with Group in R igraph

早过忘川 提交于 2019-12-02 19:31:27

问题


below are my reproductive sample codes.

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 

I want to connect each sender to the each receiver and then colour code them based on their country like the this graph:

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

Problem is I do not know what function on igraph that can create that kind of graph base on my data.

Thanks in advance


回答1:


Try this for a start:

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

More info under ?plot.igraph.



来源:https://stackoverflow.com/questions/28625245/creating-variables-with-group-in-r-igraph

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!