2015-10-14 17 views
6

the one below from this pageに似たRの世界ネットワークマップを作成したいと思います。R:世界ネットワークマップの作成

enter image description here

私は私がこれを行うことができますRパッケージを探してきたが、私は1つを見つけることができませんでした。 D3 JavaScript Network Graphs from Rがありますが、世界のネットワークマップの例が見つかりませんでした。
Rで同様のものを作成するにはどうすればよいですか?

+0

この投稿は以前と同じようなことをしています:http://stackoverflow.com/a/19695755/1718356 – Andy

+0

これについての助けを募るのに最適な場所はどこですか? –

答えて

3

まあ、FWIW:ここでは地図上の頂点(「都市」)をプロットし、矢印の付いた頂点間の辺を接続するための1つのすばやく&汚い方法です。ここで

library(maps) 
library(diagram) 
library(plotrix) 
palette(rainbow(20)) 
data("world.cities") 

pdf(tf <- tempfile(fileext = ".pdf"), width = 40, height = 20) 

map('world', fill = TRUE, col = "lightgray", mar = rep(0, 4)) 

nodes <- transform(with(world.cities, world.cities[pop > 5e6,]), country.etc = as.factor(country.etc)) 
with(nodes, points(long, lat, col=country.etc, pch=19, cex=rescale(pop, c(1, 8)))) 

set.seed(1) 
edges <- subset(data.frame(from = sample(nodes$name, 20, replace = TRUE), to = sample(nodes$name, 20, replace = TRUE), stringsAsFactors = F), from != to) 
edges <- merge(merge(edges, nodes[, c("name", "long", "lat")], by.x = "from", by.y = "name"), nodes[, c("name", "long", "lat")], by.x = "to", by.y = "name") 
edges$col <- as.integer(nodes$country.etc[match(edges$from, nodes$name)]) 

apply(edges[, -(1:2)], 1, function(x) curvedarrow(to=x[3:4], from=x[1:2], lcol=x[5], curve=.1, arr.pos = 1, lwd=.5)) 

dev.off()   
shell.exec(tf) 

enter image description here

3

は溶液でgeosphereおよびmapsパッケージを使用します。 gcIntermediate関数を使用すると、「大きな円を定義するために使用された2つの点の間の大きな円の点を中間にする」ことができます。ここで

はJKF空港(dplyrでろ過nycflights13パッケージからサンプルデータ)から飛行conncetionsを示す一例である:

library(maps) 
library(geosphere) 
library(dplyr) 
library(nycflights13) 


usairports <- filter(airports, lat < 48.5) 
usairports <- filter(usairports, lon > -130) 
usairports <- filter(usairports, faa!="JFK") 
jfk <- filter(airports, faa=="JFK") 

map("world", regions=c("usa"), fill=T, col="grey8", bg="grey15", ylim=c(21.0,50.0), xlim=c(-130.0,-65.0)) 


for (i in (1:dim(usairports)[1])) { 

inter <- gcIntermediate(c(jfk$lon[1], jfk$lat[1]), c(usairports$lon[i], usairports$lat[i]), n=200) 

lines(inter, lwd=0.1, col="turquoise2")  
} 

points(usairports$lon,usairports$lat, pch=3, cex=0.1, col="chocolate1") 

enter image description here

これは私に掲載のチュートリアルに基づいていますblog

関連する問題