mapImage {oce} | R Documentation |
Plot an image on an existing map.
mapImage(longitude, latitude, z, zlim, zclip = FALSE, breaks, col, colormap, border = NA, lwd = par("lwd"), lty = par("lty"), missingColor = NA, filledContour = FALSE, gridder = "binMean2D", debug = getOption("oceDebug"))
longitude |
vector of longitudes corresponding to |
latitude |
vector of latitudes corresponding to |
z |
matrix to be represented as an image. |
zlim |
limit for z (colour). |
zclip |
A logical value, |
breaks |
The z values for breaks in the colour scheme. If this is of
length 1, the value indicates the desired number of breaks, which is
supplied to |
col |
Either a vector of colours corresponding to the breaks, of length
1 plus the number of breaks, or a function specifying colours,
e.g. |
colormap |
optional colormap, as created by |
border |
Colour used for borders of patches (passed to
|
lwd |
line width, used if borders are drawn. |
lty |
line type, used if borders are drawn. |
missingColor |
a colour to be used to indicate missing data, or
|
filledContour |
either a logical value indicating whether to use
filled contours to plot the image, or a numerical value indicating the
resampling rate to be used in interpolating from lon-lat coordinates to
x-y coordinates. See “Details” for how this interacts with
|
gridder |
Name of gridding function used if |
debug |
A flag that turns on debugging. Set to 1 to get a moderate amount of debugging information, or to 2 to get more. |
Adds an image to an existing map, by analogy to image
.
The data are on a regular grid in lon-lat space, but not in the projected
x-y space. This means that image
cannot be used. Instead,
there are two approaches, depending on the value of filledContour
.
If filledContour
is FALSE
, the image “pixels” are with
polygon
, which can be prohibitively slow for fine grids.
However, if filledContour
is TRUE
or a numerical value, then the
“pixels” are remapped into a regular grid and then displayed with
.filled.contour
. The remapping starts by converting the
regular lon-lat grid to an irregular x-y grid using
lonlat2map
. This irregular grid is then interpolated onto a
regular x-y grid with binMean2D
or with
interp
from the akima
package, as determined by
the gridder
argument. If filledContour
is TRUE
, the
dimensions of the regular x-y grid is the same as that of the original
lon-lat grid; otherwise, the number of rows and columns are multiplied by
the numerical value of filledContour
, e.g. the value 2 means to make
the grid twice as fine.
Filling contours can produce aesthetically-pleasing results, but the method involves interpolation, so the data are not represented exactly and analysts are advised to compare the results from the two methods (and perhaps various grid refinement values) to guard against misinterpretation.
If a png
device is to be used, it is advised to supply
arguments type="cairo"
and antialias="none"
; see [1].
Dan Kelley
1. http://codedocean.wordpress.com/2014/02/03/anti-aliasing-and-image-plots/
A map must first have been created with mapPlot
.
Other functions related to maps: lonlat2map
,
lonlat2utm
, map2lonlat
,
mapArrows
, mapAxis
,
mapContour
,
mapDirectionField
, mapGrid
,
mapLines
, mapLocator
,
mapLongitudeLatitudeXY
,
mapPlot
, mapPoints
,
mapPolygon
, mapScalebar
,
mapText
, mapTissot
,
oceCRS
, shiftLongitude
,
utm2lonlat
## Not run: library(oce) data(coastlineWorld) data(topoWorld) par(mfrow=c(2, 1), mar=c(2, 2, 1, 1)) lonlim <- c(-70, -50) latlim <- c(40, 50) topo <- decimate(topoWorld, by=2) # coarse to illustrate filled contours topo <- subset(topo, latlim[1] < latitude & latitude < latlim[2]) topo <- subset(topo, lonlim[1] < longitude & longitude < lonlim[2]) mapPlot(coastlineWorld, type='l', longitudelim=lonlim, latitudelim=latlim, projection="+proj=lcc +lat_1=40 +lat_2=50 +lon_0=-60") breaks <- seq(-5000, 1000, 500) mapImage(topo, col=oce.colorsGebco, breaks=breaks) mapLines(coastlineWorld) box() mapPlot(coastlineWorld, type='l', longitudelim=lonlim, latitudelim=latlim, projection="+proj=lcc +lat_1=40 +lat_2=50 +lon_0=-60") mapImage(topo, filledContour=TRUE, col=oce.colorsGebco, breaks=breaks) box() mapLines(coastlineWorld) ## Northern polar region, with colour-coded bathymetry par(mfrow=c(1,1)) drawPalette(c(-5000, 0), zlim=c(-5000, 0), col=oce.colorsJet) mapPlot(coastlineWorld, projection="+proj=stere +lat_0=90", longitudelim=c(-180,180), latitudelim=c(60,120)) mapImage(topoWorld, zlim=c(-5000, 0), col=oce.colorsJet) mapLines(coastlineWorld[['longitude']], coastlineWorld[['latitude']]) # Levitus SST par(mfrow=c(1,1)) data(levitus, package='ocedata') lon <- levitus$longitude lat <- levitus$latitude SST <- levitus$SST par(mar=rep(1, 4)) Tlim <- c(-2, 30) drawPalette(Tlim, col=oce.colorsJet) mapPlot(coastlineWorld, projection="+proj=moll", grid=FALSE) mapImage(lon, lat, SST, col=oce.colorsJet, zlim=Tlim) mapPolygon(coastlineWorld, col='gray') ## End(Not run)