1.2.GoogleMap.and.geoplotting.tools {loa} | R Documentation |
Plotting georeferenced data on maps using lattice and RgoogleMaps
GoogleMap(x, data = NULL, panel = panel.loaPlot, map = NULL, map.panel = panel.GoogleMapsRaster, recolor.map = FALSE, ..., lon.lat = FALSE) GoogleMap.old(x, data = NULL, map = NULL, map.panel = panel.GoogleMapsRaster, panel = panel.xyplot, recolor.map = FALSE, ...) googleMap(...) quickMap(lat, lon, show.data = FALSE, ...) #map handlers makeMapArg(ylim, xlim, aspect = NULL, recolor.map = FALSE, ...) getMapArg(object = trellis.last.object()) #map panel handlers panel.GoogleMapsRaster(map) panel.GoogleMaps(map) #axis handlers xscale.components.GoogleMaps(lim, ..., map = map) yscale.components.GoogleMaps(lim, ..., map = map) axis.components.GoogleMaps(map, xlim = NULL, ylim = NULL, ...)
x |
For |
data |
For |
panel, map.panel |
For |
map |
For |
recolor.map |
For |
lon.lat |
For |
lat,lon |
For |
ylim, xlim, lim |
The latitude and longitude plot ranges. |
aspect |
The aspect ratio of the plot. If not supplied (recommended), this
is determined based on |
show.data |
For |
object |
For |
... |
Additional arguments are passed on to related functions. For, For
By default both data point colour and size are Similarly, argument passing to
|
NOTE: GoogleMap
and related panel and axis handling functions
are currently in development functions and may be subject to changes.
GoogleMap
provides lattice-style conditioning/handling for
RgoogleMaps
outputs. This uses loaPlot
and the latest version of panelPal
to manage default
panel and key settings.
GoogleMap.old
is the previous version of the GoogleMap
which uses the previous version of panelPal
googleMap
is a GoogleMap
wrapper, included because this
alternative form of the plot name was used in earlier versions of the
package.
quickMap
is crude map plotter intended to demonstrate the use
of the other 'handler' functions when building dedicated mapping
functions.
makeMapArg
accepts latitude and longitude ranges and
RgoogleMaps
function GetMap
arguments,
and produces an output suitable for use with the
panel.GoogleMapsRaster
and panel.GoogleMaps
panel
functions or in subsequent GoogleMap
calls if, e.g., the users
wishes to reuse an existing map.
panel.GoogleMapsRaster
and panel.GoogleMaps
are lattice
panel functions that generate map layers for a lattice plot using
makeMapArg
outputs.
yscale.components.GoogleMaps
and xscale.components.GoogleMaps
are y- and x-axis handlers for use with the above panels.
axis.components.GoogleMaps
is a wrapper that combines
yscale.components.GoogleMaps
and xscale.components.GoogleMaps
and allows both axis to be set from the lattice
function
argument axis
rather than each individually, via
yscale.components
and xscale.components
.
GoogleMap
and quickMap
return trellis objects,
much like conventional lattice
plot functions.
makeMapArg
returns a modified form of the
RgoogleMaps
function GetMap
output suitable for use as the map
argument with
the above functions. Note: the automatic assignment of the
RgoogleMaps
function argument size
getMapArg
recovers the map
from an existing
GoogleMap
output.
panel.GoogleMapsRaster
and panel.GoogleMaps
generate panel outputs suitable for use in standard lattice
panel functions.
yscale.components.GoogleMaps
, xscale.components.GoogleMaps
generate suitable latitude, longitude scales for use with map layers.
axis.components.GoogleMaps
is a wrapper for their routine use.
Google Maps outputs are 2D projections of curve sections of the Earth's surface. Therefore, the assignment of points within panels and the annotation of latitudes and longitudes along axis needs to be locally handled to account for this.
GoogleMap
and quickMaps
use RgoogleMaps
functions LatLon2XY
, LatLon2XY.centered
and XY2LatLon
to locally scale both axis and data.
Important: Users wanting to add data to these plots, e.g. using
update
or layers
in latticeExtra
,
should first rescale the data. Likewise, users wanting to add
maps to other plots will need to rescale plotted data to use these
maps. See Example 1 below.
Important: The Google API returns a map panel larger than the
data (latitude, longitude) range requested. However, it does this
using a limited number of panel sizes. This means you may get back
a map that is large than necessary. As xlim
and ylim
are passed to the API when they are called reseting these can
produce similar effects (so you may not get exactly the map range
you ask for! If you want to manually optimise the map ranges, the
best option is currently to start with:
GoogleMap(..., size=c(640,640))
...and then reduce either or both of these values until you generate an appropriate map size.
Karl Ropkins
This function makes extensive use of code developed by others.
lattice: Sarkar, Deepayan (2008) Lattice: Multivariate Data Visualization with R. Springer, New York. ISBN 978-0-387-75968-5
RColorBrewer: Erich Neuwirth <erich.neuwirth@univie.ac.at> (2011). RColorBrewer: ColorBrewer palettes. R package version 1.0-5. http://CRAN.R-project.org/package=RColorBrewer
RgoogleMaps: Markus Loecher and Sense Networks (2011). RgoogleMaps: Overlays on Google map tiles in R. R package version 1.1.9.6. http://CRAN.R-project.org/package=RgoogleMaps
In other packages, see
RgoogleMaps
: GetMap
; LatLon2XY
;
LatLon2XY.centered
; and, XY2LatLon
.
lattice
: xyplot
; panel.xyplot
; and
panel.levelplot
.
## Example 1 ## quickMap code ## as example of third-party use of functions quickMap <- function(lat, lon, show.data = FALSE, ...){ #get map map <- makeMapArg(lat, lon, ...) #scale axis for map projection map.axis.comps <- axis.components.GoogleMaps(map) map.axis <- function(components, ...) axis.default(components = map.axis.comps, ...) #scale data for map projection #see ?Rgooglemaps:::LatLon2XY temp <- LatLon2XY.centered(map, lat, lon) lat <- temp$newY lon <- temp$newX #plot data on map xyplot(lat~lon, xlim = map$xlim, ylim = map$ylim, aspect = map$aspect, axis = map.axis, panel = function(...){ panel.GoogleMapsRaster(map) if(show.data) panel.xyplot(...) }, ...) } ## Example 2 ## Off-line GoogleMap examples # Use a subsample of lat.lon.meuse temp <- lat.lon.meuse[sample(1:155, 15),] GoogleMap(zinc~latitude*longitude, col.regions=c("grey", "darkred"), data=temp, map=roadmap.meuse) GoogleMap(zinc~latitude*longitude, col.regions=c("grey", "darkred"), panel=panel.binPlot, data=temp, map=roadmap.meuse) GoogleMap(cadmium*50+copper*10+lead*2+zinc~latitude*longitude, col.regions=c("grey", "darkred"), key.z.main="Concentrations", panel.zcases = TRUE, data=temp, map=roadmap.meuse) GoogleMap(cadmium*50+copper*10+lead*2+zinc~latitude*longitude, col.regions=c("grey", "darkred"), panel=panel.zcasePiePlot, data=temp, map=roadmap.meuse) # Note 1: # Here, the map argument is supplied so example works off-line. # If not supplied and R is on-line, GoogleMap will get map # from the Google API. Repeat any of above without map argument # when on-line. For example: ## Not run: GoogleMap(zinc~latitude*longitude, col.regions=c("grey", "darkred"), data=lat.lon.meuse) ## End(Not run) # (The map will appear slightly different because non-default # size and maptype settings were used to make roadmap.meuse. See # ?roadmap.meuse for details.) # Note 2: # To make a map for use with panel.GoogleMaps or panel.GoogleMapsRaster # without plotting use makeMapArg(). To recover a map from a previously # plotted loa GoogleMap use getMapArg().