Create a gist now

Instantly share code, notes, and snippets.

CaPReT (great circles) map
# Based on Nathan Yau's How to map connections with great circles
# Prelim stages
# Google Spreadsheet key (must be published to the web)
# Sheet gid name
# Read data from spreadsheet
dataset = read.csv(paste('', 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 <-$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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment