ggmap in R

It is a package interfacing ggplot2 and RGoogleMaps.

For details read this article and here is the cheatsheet.

There are two steps in making a map.

  • download raster data for the map with get_map()
  • plot with the ggmap() and overlay with layers

Raster data is downloaded with:

  • location of center
  • zoom factor: 3=continent, 10=city, 21=building

Location specification can be done with:

  • address OR
  • lon/lat longitude and latitude

maptype in ggmap:

  • satellite
  • roadmap
  • hybrid

Geographic coordinates can be obtained with geocode() function.

Example:

library(ggmap)

## Loading required package: ggplot2

site <- geocode("Pokhara")

## Information from URL : http://maps.googleapis.com/maps/api/geocode/json?address=Pokhara&sensor=false

Pokhara<- ggmap(get_map(location=site, source="google", zoom=10), extent="panel")

## Map from URL : http://maps.googleapis.com/maps/api/staticmap?center=28.237987,83.995588&zoom=10&size=640x640&scale=2&maptype=terrain&language=en-EN&sensor=false

Pokhara

unnamed-chunk-1-1
Fig 1. Pokhara

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s