O'Reilly logo

R Data Analysis Cookbook - Second Edition by Kuntal Ganguly

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

How to do it...

To overlay data on the downloaded Google map, follow these steps:

  1. Load RgoogleMaps and read the data file:
> library(RgoogleMaps) 
> wages <- read.csv("nj-wages.csv") 
  1. Convert wages to quantiles for ease of plotting:
> wages$wgclass <- cut(wages$Avgwg, quantile(wages$Avgwg,     probs=seq(0,1,0.2)), labels=FALSE, include.lowest=TRUE) 
  1. Create a color palette:
> pal <- palette(rainbow(5)) 
  1. Attach the data frame:
> attach(wages)
  1. Get the Google map for the area covered by the data:
> MyMap <- MapBackground(lat=Lat, lon=Long) 
 
[1] "http://maps.google.com/maps/api/staticmap?center=40.115,-74.715&zoom=8&size=640x640&maptype=mobile&format=png32&sensor=true" 
center, zoom:  40.115 -74.715 8 
  1. Plot the map with the average wages overlaid ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required