Google Maps and ggmap

December 22, 2013
By

(This article was first published on Software for Exploratory Data Analysis and Statistical Modelling » R Environment, and kindly contributed to R-bloggers)

The ggmap package can be used to access maps from the Google Maps API and there are a number of examples on various statistics related blogs. These include here, here and here.

The ggmap package has a function get_map that can download maps from various sources including Google Maps.

require(ggmap)

The first example specifies the longitude and latitude close to the London 2012 Olympic park from Google and selects the satellite map type. The extent=”device” argument stretches the map to fill the whole graphics device.

mapImageData1 <- get_map(location = c(lon = -0.016179, lat = 51.538525),
    color = "color",
    source = "google",
    maptype = "satellite",
    zoom = 17)
 
ggmap(mapImageData1,
    extent = "device",
    ylab = "Latitude",
    xlab = "Longitude")
London 2012 Olympic Stadium Google Map Example 1

London 2012 Olympic Stadium Google Map Example 1

The second example is based on the terrain map type which looks slightly odd.

mapImageData2 <- get_map(location = c(lon = -0.016179, lat = 51.538525),
    color = "color",
    source = "google",
    maptype = "terrain",
    zoom = 16)
 
ggmap(mapImageData2,
    extent = "device",
    ylab = "Latitude",
    xlab = "Longitude")
London 2012 Olympic Stadium Google Map Example 2

London 2012 Olympic Stadium Google Map Example 2

The third example is roadmap and is uncluttered and provides an overview of the surroundings.

mapImageData3 <- get_map(location = c(lon = -0.016179, lat = 51.538525),
    color = "color",
    source = "google",
    maptype = "roadmap",
    zoom = 16)
 
ggmap(mapImageData3,
    extent = "device",
    ylab = "Latitude",
    xlab = "Longitude")
London 2012 Olympic Stadium Google Map Example 3

London 2012 Olympic Stadium Google Map Example 3

The final example is a combination of the satellite image and some road and location names.

mapImageData4 <- get_map(location = c(lon = -0.016179, lat = 51.538525),
    color = "color",
    source = "google",
    maptype = "hybrid",
    zoom = 15)
 
ggmap(mapImageData4,
    extent = "device",
    ylab = "Latitude",
    xlab = "Longitude")
London 2012 Olympic Stadium Google Map Example 4

London 2012 Olympic Stadium Google Map Example 4

To leave a comment for the author, please follow the link and comment on their blog: Software for Exploratory Data Analysis and Statistical Modelling » R Environment.

R-bloggers.com offers daily e-mail updates about R news and tutorials on topics such as: Data science, Big Data, R jobs, visualization (ggplot2, Boxplots, maps, animation), programming (RStudio, Sweave, LaTeX, SQL, Eclipse, git, hadoop, Web Scraping) statistics (regression, PCA, time series, trading) and more...



If you got this far, why not subscribe for updates from the site? Choose your flavor: e-mail, twitter, RSS, or facebook...

Comments are closed.

Sponsors

Mango solutions



RStudio homepage



Zero Inflated Models and Generalized Linear Mixed Models with R

Dommino data lab

Quantide: statistical consulting and training



http://www.eoda.de







ODSC

ODSC

CRC R books series





Six Sigma Online Training





Contact us if you wish to help support R-bloggers, and place your banner here.

Never miss an update!
Subscribe to R-bloggers to receive
e-mails with the latest R posts.
(You will not see this message again.)

Click here to close (This popup will not appear again)