Draw contour lines to an existing map, using mapLines()
.
Note that label placement in mapContour
is handled differently
than in contour()
.
Arguments
- longitude
numeric vector of longitudes of points to be plotted, or an object of class
topo
(see topo), in which caselongitude
,latitude
andz
are inferred from that object. Importantly, thelongitude
system must match that of themapPlot()
call that made the underlying plot. If not, the contours can have spurious lines that run across the plot. See “Dealing with longitude conventions” for a method of handling conflicting longitude conventions betweenmapPlot()
andmapContour()
.- latitude
numeric vector of latitudes of points to be plotted.
- z
matrix to be contoured. The number of rows and columns in
z
must equal the lengths oflongitude
andlatitude
, respectively.- nlevels
number of contour levels, if and only if
levels
is not supplied.- levels
vector of contour levels.
- labcex
cex
value used for contour labelling. As withcontour()
, this is an absolute size, not a multiple ofpar
("cex")
.- drawlabels
logical value or vector indicating whether to draw contour labels. If the length of
drawlabels
is less than the number of levels specified, thenrep()
is used to increase the length, providing a value for each contour line. For those levels that are thus indicated, labels are added, at a spot where the contour line is closest to horizontal on the page. First, though, the region underneath the label is filled with the colour given bypar
("bg")
. See “Limitations” for notes on the status of contour labelling, and its limitations.- underlay
character value relating to handling labels. If this equals
"erase"
(which is the default), then the contour line is drawn first, then the area under the label is erased (filled with white 'ink'), and then the label is drawn. This can be useful in drawing coarsely-spaced labelled contours on top of finely-spaced unlabelled contours. On the other hand, ifunderlay
equals"interrupt"
, then the contour line is interrupted in the region of the label, which is closer to the scheme used by the basecontour()
function.- col
colour of the contour line, as for
par
("col")
, except herecol
gets lengthened by callingrep()
, so that individual contours can be coloured distinctly.- lty
type of the contour line, as for
par
("lty")
, except for lengthening, as described forcol
.- lwd
width of the contour line, as for
par
("lwd")
, except for lengthening, as described forcol
andlty
.- debug
an integer specifying whether debugging information is to be printed during the processing. This is a general parameter that is used by many
oce
functions. Generally, settingdebug=0
turns off the printing, while higher values suggest that more information be printed. If one function calls another, it usually reduces the value ofdebug
first, so that a user can often obtain deeper debugging by specifying higherdebug
values.
Sample of Usage
library(oce)
data(coastlineWorld)
if (requireNamespace("ocedata", quietly=TRUE)) {
data(levitus, package = "ocedata")
par(mar = rep(1, 4))
mapPlot(coastlineWorld, projection = "+proj=robin", col = "lightgray")
mapContour(levitus$longitude, levitus$latitude, levitus$SST)
}
Dealing with longitude conventions
Suppose a map has been plotted using longitudes that are bound between -180
and 180. To overlay contours defined with longitude bound between 0 and 360
(as for the built-in coastlineWorld
dataset), try Clark Richards' method
(https://github.com/dankelley/oce/issues/2217, as below.
# Start with z=z(lon,lat), with lon bound by 0 and 360
z2 <- rbind(z[lon > 180, ], z[lon <= 180, ])
lon2 <- lon + 180
mapContour(lon2, lat, z2)
See also
A map must first have been created with mapPlot()
.
Other functions related to maps:
formatPosition()
,
lonlat2map()
,
lonlat2utm()
,
map2lonlat()
,
mapArrows()
,
mapAxis()
,
mapCoordinateSystem()
,
mapDirectionField()
,
mapGrid()
,
mapImage()
,
mapLines()
,
mapLocator()
,
mapLongitudeLatitudeXY()
,
mapPlot()
,
mapPoints()
,
mapPolygon()
,
mapScalebar()
,
mapText()
,
mapTissot()
,
oceCRS()
,
oceProject()
,
shiftLongitude()
,
usrLonLat()
,
utm2lonlat()