Last active
March 12, 2016 23:55
-
-
Save djhurio/9288cf9e20a194a79d51 to your computer and use it in GitHub Desktop.
Plotting in R on Google Maps
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
### 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