0

So I have got the following problem: I have got a rather large network which contains information about the personal connection between people. One of the vertex attributes is their town of residence. I now want to see if there is a connection between people from different towns. The kind of result I would like to get is a plot which represents these linkages. It might be the easiest to show an example of what I was looking for:

Example image

So in this case, the x-axis would represent the people from different towns, whereas the y-axis represents their friendship. So if a person from New York is friends with a person from Tokyo, a dot would be drawn at [New York, Tokyo]. This would be able tp give me additional information on top of the assortativity coefficient.

I have seen similar representations before in articles, but I am completely clueless how to create them using igraph on R. I was looking at the neighbors or neighborhood commands, but I haven't been able to figure out how to create something like this yet. Help would be highly appreciated.

Edit: Sample code that could be used to reproduce:

g <- erdos.renyi.game(25, 1/10)
V(g)$location <- c("NY", "Tokyo", "Madrid", "Berlin", "NY", "Tokyo", "Madrid", "Berlin", "NY", "Tokyo", "Madrid", "Berlin", "NY", "Tokyo", "Madrid", "Berlin", "NY", "Tokyo", "Madrid", "Berlin", "Berlin", "NY", "Tokyo", "Madrid", "Berlin")

suedbaden
  • 3
  • 2
  • 2
    It's easier to help you if you provide a [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) with sample input data that can be used to test possible solutions. – MrFlick Jun 19 '17 at 18:03
  • Thank you for the reply. I guess you could just use a random sample graph like this: `g <- erdos.renyi.game(25, 1/10)` `V(g)$location <- c("NY", "Tokyo", "Madrid", "Berlin", "NY", "Tokyo", "Madrid", "Berlin", "NY", "Tokyo", "Madrid", "Berlin", "NY", "Tokyo", "Madrid", "Berlin", "NY", "Tokyo", "Madrid", "Berlin", "Berlin", "NY", "Tokyo", "Madrid", "Berlin")` – suedbaden Jun 19 '17 at 20:51

1 Answers1

2

Here's what you could do using as_long_data_frame:

df<- apply(as_long_data_frame(g),2,as.character)
colnames(df) <- c("from","to","from_city","to_city")
df <- as.data.frame(df)
ggplot(df,aes(x=from_city,y=to_city))+
  geom_jitter(position = position_jitter(width = 0.1, height = 0.1))

enter image description here

Pierre Lapointe
  • 16,017
  • 2
  • 43
  • 56