我想在世界范围内绘制电子邮件。例如,我从以下国家收到以下电子邮件,我住在美国。
recievedcountry <- c("India", "China", "France", "Chile", "Australia", "Chad",
"Nepal", "Burma")
rfrequency <- c(12, 20, 5, 2, 12, 1, 3, 2) # frequency of emails
sendcountry <- c("Canda", "USA", "France", "India", "China", "Japan")
sfrequency <- c(14, 108, 12, 15, 18, 4)
这是我尝试但我不知道如何与线条相吻合:
require(fields)
world(xlim=c(-90,90),ylim=c(-180,180), xaxt = "s", yaxt = "s")
grid()
以下是我的假设模型:
答案 0 :(得分:6)
之前曾有过这样的想法。看看这篇博客文章,它描述了如何非常仔细地构建这样的地图。
http://flowingdata.com/2011/05/11/how-to-map-connections-with-great-circles/
答案 1 :(得分:6)
根据上面提供的 AdresT (谢谢!)链接,我可以回答我自己的问题,除了与电子邮件数量成比例的线路思考
这是代码:我使用随机数据而不搜索每个位置的精确经度和纬度。
library(maps)
library(geosphere)
map("world", col = "green4", bg="#F5FFFA", lwd=0.05)
myposition <- c(-74, 40) # my position (where I am opening emails)
rlong <- c(75, 105, 135, - 10.2, 45.2, -30.4, 105, 35, -150,
10.2, 145.2, 30.4) # received lat
rlat <- c(30, 43, 23, 12, 68, 55.6, 30, 43, 23, 12, 68, 55.6) # received long
nrecived <- c(4, 10, 5, 2, 4, 10, 4, 10, 5, 2, 4, 10 ) # number of email received
slong <- c(85, 85, 55, -40.2, 45.2, -30.4,45, 95, 55, 40.2, 55.2, 60.4 ) # send lat
slat <- c(10, 43, 13, 12, 68, 55.6,10, 43, 13, 12, 68, 55.6 ) # send long
nsend <- c(4, 10, 5, 2, 4, 10, 4, 10, 5, 2, 4, 10 ) # number of email send
mydf <- data.frame (rlat, rlong, nrecived, slat, slong, nsend)
for (i in 1: length (mydf) ) {
send <- gcIntermediate(c(mydf[i,]$slong, mydf[i,]$slat), c(-74, 40),
n=100, addStartEnd=TRUE)
lines (send, col = "blue", lwd = mydf[i, "nsend"]) # edited
following suggestion
received <- gcIntermediate(c(mydf[i,]$rlong, mydf[i,]$rlat), c(-74, 40),
n=100, addStartEnd=TRUE)
lines (received , col = "red", lwd = mydf[i, "nrecived"])
}
输出图:
如果有人可以帮助与电子邮件数量成比例的线的厚度将是伟大的!
修正了RomanLuštrik的线尺寸建议后,
线宽到宽可能需要重新分成更小的数字!
答案 2 :(得分:0)
以下是how to make flow maps in R using ggplot2
的解决方案。您可以制作平面或球形地图: