Skip to content

Instantly share code, notes, and snippets.

@djhurio
Last active March 12, 2016 23:55
Show Gist options
  • Save djhurio/9288cf9e20a194a79d51 to your computer and use it in GitHub Desktop.
Save djhurio/9288cf9e20a194a79d51 to your computer and use it in GitHub Desktop.
Plotting in R on Google Maps
### Plotting in R on Google Maps
require(ggmap)
require(data.table)
### 1 ###
# If you have coordinates available, go to 2
# This is a way how to get some coordinates
# Check how many queries you can do
geocodeQueryCheck()
# Some test data
dat <- data.table(address = c("Riga", "Vilnius", "Tallinn",
"Valmiera", "Palanga", "Tartu"))
# Geo coding
dat[, c("lat", "lon") := geocode(address), with = F]
dat
### 2 ###
# Ploting on Google Map
# Get a picture
# Change the f to modify the zoom
bbox <- make_bbox(dat[, lat], dat[, lon], f = 1)
map <- get_map(location = bbox, maptype = 'roadmap')
# Plot on picture
ggm1 <- ggmap(map) +
geom_point(data = dat, aes(lat, lon), colour = "red") +
ggtitle("BNU workshops")
ggm1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment