我试图将igraph绘制到地理地图上,每次运行代码时,igraph都会完全覆盖地图,而我真的不知道问题是否与缩放有关。
下面是我的代码:
库(光栅)
图书馆(igraph)
ncd <- getData('GADM',country='PNG',level=1)
plot(ncd)
names(ncd)
unique(ncd$NAME_1)
ncd1<-subset(ncd,NAME_1=="National Capital District")
plot(ncd1)
df<-data.frame("from" = c("MIW", "MIW", "GM", "GM", "GM", "GM", "GM", "GM", "GM", "GM", "GM", "GM", "GM", "GM", "GM", "GM"
, "TM", "TM", "TM", "TM", "TM", "TM", "TM", "TM", "TM", "TM", "TM", "TM", "TM", "TM"),
"to"= c("GM", "TM", "BM", "WM", "EB", "SM", "GM1", "TM1", "SMM", "HM", "RM", "NMM", "KM", "ATSM", "GYard"
, "GRdM", "BM", "WM", "EB", "SM", "GM1", "TM1", "SM", "HM", "RM", "NMM", "KM", "ATSM", "GYard", "GRdM"))
meta <- data.frame("names"=c("MIW","GM","TM","BM", "WM", "EB", "SM", "GM1", "TM1", "SMM", "HM", "RM", "NMM", "KM", "ATSM", "GYard", "GRdM"),
"lon"=c(147.112271,147.160540,147.154022,147.195838,147.179687,147.193114,147.193115,147.160317,147.167903,147.215164,147.175887,
147.160262,147.225968,147.170184,147.226608,147.154022,147.195077),
"lat"=c(-9.417550,-9.391543,-9.389203,-9.468712,-9.423927,-9.469747,-9.488941,-9.390482,-9.43083,-9.465426,-9.452757,-9.400154,
-9.408481,-9.480321,-9.437668,-9.389203,-9.441922))
g <- graph.data.frame(df, directed=T, vertices=meta)
lo <- as.matrix(meta[,2:3])
plot(ncd1)
plot(g,layout=lo,add=TRUE,rescale = FALSE)
我希望igraph在地图上绘制坐标,并清楚显示不同位置之间的链接,但不会显示该链接。the map shows the igraph being plotted onto a geographic map