I want to plot email from and to in world. For example, I received the following number of emails from the following countries and I live in USA.
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)
This what I tried but I do not know how to conect with lines:
require(fields)
world(xlim=c(-90,90),ylim=c(-180,180), xaxt = "s", yaxt = "s")
grid()
The following is my hypothesize model:
This has been thought before. Look at this blog entry, it describes how to construct such a map very carefully.
http://flowingdata.com/2011/05/11/how-to-map-connections-with-great-circles/
Based on AdresT (thanks !) link provided above I could answer my own question except, line thinkness proportional to number of emails
Here is code: I used random data without searching exact longitude and latitude for each location.
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"])
}
The output map:
If somebody can help to thickness of line proportional to number of emails will be great !
After fixing following line size suggestion from Roman Luštrik,
Line size to broad may be need to reclass into smaller numbers !
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With