mapImage | R Documentation |
Plot an image on an existing map that was created with mapPlot()
.
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 |
numeric vector of longitudes corresponding to |
latitude |
numeric vector of latitudes corresponding to |
z |
numeric matrix to be represented as an image. |
zlim |
limit for z (color). |
zclip |
A logical value, |
breaks |
The z values for breaks in the color scheme. If this
is of length 1, the value indicates the desired number of breaks,
which is supplied to |
col |
Either a vector of colors corresponding to the breaks,
of length 1 plus the number of breaks, or a function specifying
colors, e.g. |
colormap |
optional colormap, as created by |
border |
Color 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 color to be used to indicate missing data, or
|
filledContour |
an indication of whether to use filled
contours. This may be FALSE (the default), TRUE, or a positive
numerical value. If FALSE, then polygons are used. Otherwise, the
longitude-latitude values are transformed to x-y values, which will
not be on a grid and thus will require gridding so that
|
gridder |
specification of how gridding is to be done, used
only if |
debug |
an integer specifying whether debugging information is
to be printed during the processing. This is a general parameter that
is used by many |
Image 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 drawn with
polygon()
. This can be prohibitively slow for fine grids.
However, if filledContour
is TRUE
, 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 in
accordance with the gridder
parameter. If gridder
values of
"binMean2D"
and "interp"
do not produce satisfactory results,
advanced users might wish to supply a function to do the gridding
according to their own criteria. The function must have as its
first 5 arguments (1) an x vector, (2) a y vector, (3) a z matrix
that corresponds to x and y in the usual way, (4) a vector holding
the desired x grid, and (5) a vector holding the desired y grid.
The return value must be a list containing items named xmids
,
ymids
and result
. To understand the meaning of the parameters
and return values, consult the documentation for binMean2D()
.
Here is an example of a scheme that will fill data gaps of 1 or 2
cells:
g <- function(...) binMean2D(..., fill = TRUE, fillgap = 2) mapImage(..., gridder = g, ...)
Until oce 1.7.4, the gridder
argument could be set to "akima"
,
which used the akima
package. However, that package is not
released with a FOSS license, so CRAN requested a change to
interp. Note that drawImage()
intercepts the errors
that sometimes get reported by interp::interp()
.
library(oce) data(coastlineWorld) data(topoWorld) # Northern polar region, with color-coded bathymetry par(mfrow = c(1, 1), mar = c(2, 2, 1, 1)) cm <- colormap(zlim = c(-5000, 0), col = oceColorsGebco) drawPalette(colormap = cm) mapPlot(coastlineWorld, projection = "+proj=stere +lat_0=90", longitudelim = c(-180, 180), latitudelim = c(70, 110) ) # Uncomment one of the next four blocks. See # https://dankelley.github.io/dek_blog/2024/03/07/mapimage.html # for illustrations. # Method 1: the default, using polygons for lon-lat patches mapImage(topoWorld, colormap = cm) # Method 2: filled contours, with ugly missing-data traces # mapImage(topoWorld, colormap = cm, filledContour = TRUE) # Method 3: filled contours, with a double-sized grid cells # mapImage(topoWorld, colormap = cm, filledContour = 2) # Method 4: filled contours, with a gap-filling gridder) # g <- function(...) binMean2D(..., fill = TRUE, fillgap = 2) # mapImage(topoWorld, colormap = cm, filledContour = TRUE, gridder = g) mapGrid(15, 15, polarCircle = 1, col = gray(0.2)) mapPolygon(coastlineWorld[["longitude"]], coastlineWorld[["latitude"]], col = "tan" )
Dan Kelley
A map must first have been created with mapPlot()
.
Other functions related to maps:
formatPosition()
,
lonlat2map()
,
lonlat2utm()
,
map2lonlat()
,
mapArrows()
,
mapAxis()
,
mapContour()
,
mapCoordinateSystem()
,
mapDirectionField()
,
mapGrid()
,
mapLines()
,
mapLocator()
,
mapLongitudeLatitudeXY()
,
mapPlot()
,
mapPoints()
,
mapPolygon()
,
mapScalebar()
,
mapText()
,
mapTissot()
,
oceCRS()
,
oceProject()
,
shiftLongitude()
,
usrLonLat()
,
utm2lonlat()
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.