R:创建世界网络 map

标签 r rworldmap

关闭。这个问题不符合 Stack Overflow guidelines 。它目前不接受答案。












想改善这个问题吗?更新问题,使其成为 Stack Overflow 的 on-topic

5年前关闭。




Improve this question




我想在 R 中生成类似于 the one below from this page 的世界网络 map 。

enter image description here

我一直在寻找一个 R 包,它可以让我做到这一点,但我一直找不到。有 D3 JavaScript Network Graphs from R 但我找不到世界网络 map 示例。
如何在 R 中创建类似的东西?

最佳答案

好吧,FWIW:这是在 map 上绘制顶点(“城市”)并用箭头连接顶点之间的边缘的一种快速而肮脏的方法:

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

关于R:创建世界网络 map ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33122456/

相关文章:

regex - 在正则表达式中转义管道 ("|")

r - RStudio 中的更新包不起作用

R:rworldmap map 问题和传单应用程序

r - 使用 ggplot2 绘制多条正态曲线,无需硬编码均值和标准差

r - 在ggplot中为glue命令添加小数位

r - 带有 rworldmap 的图上的国家名称

r - 在 R 中绘制 1990 年前的世界地图

r - 使用 ggplot2 绘制彩色编码的世界地图

rworldmap 包 - 将较低的 xlim 保留在一系列 map 中,但左侧区域正在变化

r - 高于给定阈值的向量值的快速求和