【问题标题】:plotting email flow in map using R使用 R 在地图中绘制电子邮件流
【发布时间】:2012-03-26 13:07:31
【问题描述】:

我想在世界上绘制电子邮件。例如,我收到了来自以下国家/地区的以下数量的电子邮件,并且我住在美国。

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()

以下是我的假设模型:

【问题讨论】:

    标签: r email map plot


    【解决方案1】:

    这是以前想过的。看看这篇博文,它非常仔细地描述了如何构建这样的地图。

    http://flowingdata.com/2011/05/11/how-to-map-connections-with-great-circles/

    【讨论】:

      【解决方案2】:

      根据上面提供的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"])
                  }
      

      输出地图:

      如果有人可以帮助将线条粗细与电子邮件数量成正比,那就太好了!

      在修复 Roman Luštrik 提出的以下行号建议后,

      线宽可能需要重新分类为更小的数字!

      【讨论】:

      • 如果你把lwd=1.2改成lwd = mydf[i, "nsend"],能解决你的线粗问题吗?
      • 您可以将当前的 lwd 重新调整为更实用的东西。你可以除以 0.8 或其他东西。
      【解决方案3】:

      这是how to make flow maps in R using ggplot2的解决方案。您可以制作平面地图或球形地图:

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2017-03-31
        • 2015-08-14
        • 2019-04-30
        • 2020-08-27
        • 2012-11-15
        • 1970-01-01
        • 2012-03-28
        相关资源
        最近更新 更多