user1073012
user1073012

Reputation: 31

Rgooglemaps not plotting data over the map

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:

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")

Upvotes: 3

Views: 1750

Answers (2)

Greg Snow
Greg Snow

Reputation: 49640

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

Upvotes: 0

Mike Pearmain
Mike Pearmain

Reputation: 423

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'

Upvotes: 0

Related Questions