2015-10-14 5 views
6

मैं the one below from this page के समान आर में एक विश्व नेटवर्क मानचित्र बनाना चाहता हूं।आर: एक विश्व नेटवर्क मानचित्र बनाना

enter image description here

मैं एक आर पैकेज है कि मुझे ऐसा करने की अनुमति देगा की तलाश में था लेकिन मैं एक ढूँढने में सक्षम नहीं किया गया है। D3 JavaScript Network Graphs from R है लेकिन मुझे विश्व नेटवर्क मानचित्र उदाहरण नहीं मिला।
मैं आर में कुछ समान कैसे बना सकता हूं?

+0

कुछ समय पहले से यह पोस्ट कुछ ऐसा ही करता है: http://stackoverflow.com/a/19695755/1718356 – Andy

+0

इस पर सहायता के लिए पोस्ट करने के लिए सबसे अच्छी जगह कहां होगी? –

उत्तर

3

खैर, FWIW: यहाँ एक त्वरित & गंदा तीर के साथ एक नक्शे पर कोने ("शहरों") साजिश और कोने के बीच किनारों से संपर्क कर सकते है:

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 फ़ंक्शन का उपयोग करके आप "महान सर्कल को परिभाषित करने के लिए उपयोग किए गए दो बिंदुओं के बीच एक महान सर्कल पर मध्यवर्ती बिंदु" कर सकते हैं।

यहाँ (nycflights13 पैकेज dplyr साथ फ़िल्टर्ड से नमूना डेटा) JKF हवाई अड्डे से उड़ान 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

संबंधित मुद्दे