Reputation: 105
I try to visualize data on cultural distances between countries with the use of networks in R. The distances are stored in matrices, e.g.:
AT BE CH CZ
AT 0 0.00276 0.148 0.109
BE 0.00276 0 0.145 0.112
CH 0.148 0.145 0 0.257
CZ 0.109 0.112 0.257 0
With the use of igraph
package I get an image like:
The code I use:
library(maps)
library(igraph)
df<-data.frame(from = c("at", "be", "ch", "cz"), to= c("be", "ch", "cz", "at"),
weight=c(0.003,0.145,0.257,0.109))
meta <- data.frame("name"=c("at", "be", "ch", "cz"),
"lon"=c(14.55,4.46,8.227,14.4738), "lat"=c(47.51,50.5,46.818,50.0755))
g <- graph.data.frame(df, directed=F, vertices=meta)
E(g)$color <- "brown"
# since weights are small, multiplying by 10
E(g)$width <- E(g)$weight*10
lo <- as.matrix(meta[,2:3])
map("world", xlim = c(-8, 30),
ylim = c(35, 55), asp=1)
plot(g, layout=lo, add = TRUE, rescale = FALSE)
Now, the problem is that I want lines to be thin, if the corresponding weight is big. However, igraph
does the opposite, and draws lines the thicker the bigger the weight is.
Is there any means to reverse this?
Upvotes: 2
Views: 95
Reputation: 48211
Why not to define the width as inversely related to the weight in some way? For instance, using
E(g)$width <- 3 - E(g)$weight * 10
gives
You may experiment further and replace 3 and/or 10 with some other coefficients to achieve the desired result.
Upvotes: 1