0

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

jbest
  • 640
  • 1
  • 10
  • 28

1 Answers1

2

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.

enter image description here

lukeA
  • 53,097
  • 5
  • 97
  • 100
  • Hi there, I used your code on my sample data set and notice that my arrow heads and the lines connected to it are a lot thicker than yours. It is not very useful for big dataset. Any way I can edit the size of the arrow heads I am using Mac. – jbest Feb 23 '15 at 03:40
  • 1
    Have a look at the 1st example in `?igraph.plotting`. You should be able to adjust the arrow sizes using the attributes `edge.arrow.size` and `edge.arrow.width`. – lukeA Feb 24 '15 at 11:07