Reputation: 3
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:
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")
Upvotes: 0
Views: 103
Reputation: 16277
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))
Upvotes: 2