I need to plot on a Google Map some values (i downloaded the map using RgoogleMap package)
So i have latitude and longitude points ( X
and Y
), and a value for every point in the grid ( evalmat
)
GoogleMap(evalmat~Y*X,map=MapVeneto)
is an error because evalmat
is a matrix. What is the correct usage of this command?
I thought that filling a vector with evalmat
values could be an idea, and i created also two vectors lat
and lon
long as the new vector, with corrispondent vaues, but it didn't work. I found this error
Error using packet 1
X and units must have length >0
What is the correct usage of these vectors in this command?
I downloaded example files ( http://www.jstatsoft.org/v63/i04 ) and tried to recreate "FIG02_MeuseLoa01.R" with my data and encountered similar problem.
require(loa)
require(RgoogleMaps)
GoogleMap(zinc~latitude*longitude, data=lat.lon.meuse, map=roadmap.meuse)
This example works nicely, but when I've tried to load different map apply on my data (okay I am still using the example data but it has no effect on pointing out the problem):
map <- GetMap(center=c(lat=50.97494,lon=5.743606), zoom=13,size=c(480,480))
this is from "FIG01_Meuse.R" example code (=not my own code).
GoogleMap(zinc~latitude*longitude, data=lat.lon.meuse, map=map)
Warning messages:
1: In update.trellis(ans, panel = panel.with.map, aspect = map$aspect, :
Invalid value of 'aspect'
2: In is.na(x) : is.na() applied to non-(list or vector) of type 'NULL'
....
+ the same (as yours) error message inside a plot (I need some magical internet points to post pictures here so):
Error using packet 1
X and units must have length >0
I looked in ?roadmap.meuse
and followed:
GoogleMap(zinc~latitude*longitude, data=lat.lon.meuse, size=c(480,480))
map <- getMapArg()
GoogleMap(zinc~latitude*longitude, data=lat.lon.meuse, map=map)
working again! and it is working for any dataframe.
So this is a workaround not a proper answer (but your question is little vague), hope it will help. Something is not correct with GetMap(center=c(lat=50.97494,lon=5.743606), zoom=13,size=c(480,480))
, if anyone could point out what, I will be appreciative
To answer your question : Your error message is probably not connected to evalmat
being matrix, and I have no idea if GoogleMap()
will work with matrix. lat.lon.meuse
is definetly a data.frame.
EDIT: This works too:
GoogleMap(~-6.8*37.6, data=dfm, size=c(640,500), zoom=9, SCALE=1, maptype="roadmap")
Sorry for only seeing this now/replying late.
First a quick suggestion: Just be helpful to know where Y and X are coming from and how you made map for...
GoogleMap(evalmat~Y*X,map=MapVeneto)
# not ...map=MapVeneto
Meantime, GoogleMap assumes x (long), y (lat) and z when supplied as a formula are supplied as vectors, so meant for data sources like data.frames.
I did some work on loaPlot so that can handle some matrices, but if they were supplied instead of formula (or formula and data)...
loaPlot(volcano)
loaPlot(volcano, panel=panel.binPlot)
# etc
But that has not yet made it to into other plots in package, and I am not sure if it is going to.
So, sorry not matrices at moment...
Next
GoogleMap(zinc~latitude*longitude, data=lat.lon.meuse, size=c(480,480))
map <- getMapArg()
GoogleMap(zinc~latitude*longitude, data=lat.lon.meuse, map=map)
...works, but
map <- GetMap(center=c(lat=50.97494,lon=5.743606), zoom=13,size=c(480,480))
GoogleMap(zinc~latitude*longitude, data=lat.lon.meuse, map=map)
...does not because of changes to the RgoogleMaps package and GetMap since that paper that example comes from was published. I have not caught up with in CRAN releases.
But developers version at:
install.packages("loa", repos="http://R-Forge.R-project.org")
Meantime, if you did not just want to use in form:
GoogleMap(zinc~latitude*longitude, data=lat.lon.meuse, size=c(480,480))
... and let GoogleMap make the map itself, you could make map using makeMapArg in loa, eg
lat <- lat.lon.meuse$latitude
lon <- lat.lon.meuse$longtitude
map <- makeMapArg(y=lat, x=lon, size=c(480, 480))
GoogleMap(zinc~latitude*longitude, data=lat.lon.meuse, map=map)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.