public
Created

CaPReT (great circles) map

  • Download Gist
gistfile1.r
R
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
# Based on Nathan Yau's How to map connections with great circles
# http://flowingdata.com/2011/05/11/how-to-map-connections-with-great-circles/
 
 
# Prelim stages
library(maps)
library(geosphere)
 
# Google Spreadsheet key (must be published to the web)
key='0AqGkLMU9sHmLdDd5UXFGdEJGUjEyN3M5clU1X2R5V0E'
# Sheet gid name
gid=2
 
# Read data from spreadsheet
dataset = read.csv(paste('https://docs.google.com/spreadsheet/pub?hl=en_US&hl=en_US&key=', key ,'&single=true&gid=', gid, '&output=csv', sep=""), header = T)
 
# Colors
pdf("capret.pdf", width=11, height=7)
map("world", col="#F2F2F2", fill=TRUE, bg="#ffffff", lwd=0.05)
pal <- colorRampPalette(c("#333333", "white", "#1292db"))
colors <- pal(100)
 
# get a domain frquency table of text source domains
sourceFreq <- as.data.frame(table(dataset$domain))
# get the maximum frquency
maxcnt <- max(sourceFreq$Freq)
#order by domain frequency - most last
dataset <- [order(dataset$domain),]
 
for (j in 1:nrow(dataset)) {
inter <- gcIntermediate(c(dataset[j,]$source_long, dataset[j,]$source_lat), c(dataset[j,]$target_long, dataset[j,]$target_lat), n=100, addStartEnd=TRUE)
colindex <- round( (subset(sourceFreq,Var1==dataset[j,]$domain)$Freq / maxcnt) * length(colors) )
lines(inter, col=colors[colindex], lwd=0.8)
}
dev.off()

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.