3

I am having an issue with the R package Rgooglemaps. I can retrieve a map from google maps or open street map but the PlotOnStaticMap function does not overlap the data I want to plot to the map. Instead it opens a new graphical device where it plots the data. So I end up with:

  • an image saved in my working dir which contains only the retrieved google map
  • a R graphic device window with my data plotted over a white background.

I am on windows, using R version 2.13.1 and RGUI. The issue appears also when I run the code via command line. I remember I used Rgooglemaps a few months ago and it worked properly for me. Meanwhile I upgraded my R version, so it could be a version related issue.

Can someone give it a try and see if you have the same issue (and a way to solve it)?

Here an example to reproduce the issue (taken from http://www.r-bloggers.com/visualizing-gis-data-with-r-and-open-street-map/). The example is using Open Street Map instead of googlemaps but the behavior is the same. The code:
require(RgoogleMaps)
lat_c<-51.47393
lon_c<-7.22667
bb<-qbbox(lat = c(lat_c[1]+0.01, lat_c[1]-0.01), lon = c(lon_c[1]+0.03, lon_c[1]-0.03))
OSM.map<-GetMap.OSM(lonR=bb$lonR, latR=bb$latR, scale = 20000, destfile="bochum.png")
image(OSM.map)
lat<- c(51.47393, 51.479021)
lon<- c(7.22667, 7.222526)
val <- c(0, 255)
lat_adj<-function(lat, map){(map$BBOX$ll[1]-lat)/(map$BBOX$ll[1]-map$BBOX$ur[1])}
lon_adj<-function(lon, map){(map$BBOX$ll[2]-lon)/(map$BBOX$ll[2]-map$BBOX$ur[2])}
PlotOnStaticMap(OSM.map, lat = lat_adj(lat, OSM.map), lon = lon_adj(lon, OSM.map),       
col=rgb(255,0, val,90,maxColorValue=255),pch=16,cex=4)
dev.print(jpeg,"test.jpeg", width=1204, height=644, units="px")
Tomas
  • 57,621
  • 49
  • 238
  • 373

2 Answers2

0

I've only re-run your code, and not looked into the problems and get the error message:

dev.print(jpeg,"test.jpeg", width=1204, height=644, units="px") windows 2 Error: REAL() can only be applied to a 'numeric', not a 'NULL'

Mike Pearmain
  • 423
  • 4
  • 10
0

I ran the above code on R2.14.0 and everything appears to work.

Greg Snow
  • 48,497
  • 6
  • 83
  • 110
  • I just tried with R2.14 and I have the same issue... by "everything appears to work" you mean you can really see a plot with the colored dots superimposed on the open street map? Or just that you don't get an error running the code? – user1073012 Dec 01 '11 at 08:11
  • I saw the map and 2 colored points on the map, I changed the cex and reran and the points changed size (just wanted to make sure that what I thought were the points were not part of the map). – Greg Snow Dec 01 '11 at 18:15