Skip to content

Instantly share code, notes, and snippets.

@mattbaggott
Last active December 16, 2015 14:09
Show Gist options
  • Save mattbaggott/5447161 to your computer and use it in GitHub Desktop.
Save mattbaggott/5447161 to your computer and use it in GitHub Desktop.
library(ggplot2)
library(ggmap)
# blue bottle coffee shops in SF area
latitude <- c(37.782375,37.795933,37.776327,37.762033,37.795966,37.785936)
longitude <- c(-122.407567,-122.273128,-122.42328,-122.411603,-122.394025,-122.400761)
df2 <- data.frame(longitude=longitude,latitude=latitude)
# df to make map title on the water
dflabels <- data.frame(longitude=-122.678,
latitude=37.8,
text="Blue Bottle\nCoffee\nLocations")
# make a new font family
# (windows only, other os should omit this and the 'family = "newfam"' argument in the plot
windowsFonts(newfam = windowsFont('Garamond'))
# get map info
map <- get_map(location = c(-122.7,37.7,-122.1,37.9), # bounding box for location
maptype = "watercolor",
source = "stamen")
# build map
p <- ggmap(map, extent = "device")
# add coffee locations; use two different sized dots so there is a white outline
p <- p + geom_point(data=df2, aes(x=longitude, y=latitude),size = 5,colour="white")
p <- p + geom_point(data=df2, aes(x=longitude, y=latitude),size = 3,colour="blue")
# add 'title' on the water
p <- p + geom_text(data = dflabels, aes(x=longitude, y=latitude, label = text),
size=10,colour="white",vjust=1,hjust=0,
family="newfam", fontface="bold", lineheight=.8)
# display
p
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment