我试图通过在R中使用网络来可视化国家之间文化距离的数据。距离存储在矩阵中,例如:
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
使用igraph
包后,我得到的图像如下:
我使用的代码:
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)
现在,问题是如果相应的重量很大,我希望线条很薄。但是,igraph
则相反,并且线条越粗,重量就越大。
有没有办法扭转这种局面?