Skip to content

Instantly share code, notes, and snippets.

@miguelrios
Last active December 18, 2015 23:39
Show Gist options
  • Save miguelrios/5862819 to your computer and use it in GitHub Desktop.
Save miguelrios/5862819 to your computer and use it in GitHub Desktop.
Script used to draw Twitter's "Billion Strokes" maps. http://www.flickr.com/photos/twitteroffice/sets/72157633647745984/
library("ggmap")
city <- "istanbul,tr" #city,country. see list in filenames.
map <- get_map(city, zoom=11)
bb <- attr(map, "bb")
filename <- paste("/Users/miguel/data/geo_series/250cities/",city,".txt", sep="") # directory with city files
output <- paste("/Users/miguel/design/geoseries/",city,"_black.png", sep="") # director where you want the output
data = read.table(filename, sep='\t', col.names=c("lat", "lon","city","count", "density"))
sorted <- data[with(data, order(count)), ]
points <- geom_point(aes(x=lon, y=lat, alpha=density, size = count, colour = count), data = sorted, shape=15)
ppi <- 300
png(output, width=25*ppi, height=25*ppi, res=ppi)
print(
ggmap(map,expand=T) + theme_nothing() +
annotate("rect", xmin=bb$ll.lon, ymin=bb$ll.lat,
xmax=bb$ur.lon, ymax=bb$ur.lat,
fill="black", alpha=1) +
points +
scale_alpha(trans = "log", limits=c(1,50), range=c(0.75,0.95), na.value=1) +
# scale_alpha()
scale_size(trans = "log", limits=c(1,50), range=c(0.60,0.40), na.value=0.25) +
scale_colour_gradient(trans = "log", limits=c(1,50), na.value='#a5cbef')
)
print("Turning off device")
dev.off()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment