| Title: | Draw Images of Raster Data and Related Adornments |
|---|---|
| Description: | Draw images easily, set up a plot with an image, specify where that image should be placed. Image plot by default reflects the index of the image data itself, or can be specified in simple extent terms 'xmin,xmax,ymin,ymax'. Numeric matrices, integer arrays, byte arrays, character arrays, and native rasters are supported. Flat vectors are supported in a limited sense with a heuristic to guess at the likely dimensionality and some helpers. Arrays with more than two dimensions are drawn a slice at a time, placed by coordinates that may be irregular or curvilinear, and triangle and quad meshes are drawn with the same colour mapping. A combination of image() and rasterImage() from the 'graphics' package with their good features in one place. |
| Authors: | Michael D. Sumner [aut, cre, cph], Chris Toney [ctb] |
| Maintainer: | Michael D. Sumner <[email protected]> |
| License: | MIT + file LICENSE |
| Version: | 0.1.0.9002 |
| Built: | 2026-11-18 19:27:33 UTC |
| Source: | https://github.com/hypertidy/ximage |
as_ximage() is the shared input decoder behind ximage(), xcontour(),
xtext() and xpanels(). It turns any supported input into a matrix (or
a colour array) in raster order, with its placement, and for arrays with
more than two dimensions it chooses the slice to draw.
as_ximage( x, extent = NULL, ..., slice = NULL, xy = NULL, coords = NULL, force = FALSE, bands = TRUE, verbose = getOption("ximage.verbose", TRUE) )as_ximage( x, extent = NULL, ..., slice = NULL, xy = NULL, coords = NULL, force = FALSE, bands = TRUE, verbose = getOption("ximage.verbose", TRUE) )
x |
input data, anything |
extent |
optional, numeric xmin,xmax,ymin,ymax, overrides any
placement from the input or from |
... |
arguments for methods |
slice |
index of the slice to draw for arrays with more than two
dimensions: a named list or vector, e.g. |
xy |
the two spatial dimensions, x then y, as names or positions |
coords |
optional coordinates of the spatial dimensions,
|
force |
proceed with a guessed dimension for very long bare vectors
(see |
bands |
allow a band-like dimension to be drawn as a colour composite,
default |
verbose |
report the slice drawn and possible fill values, default
|
a list of class "ximage_data" with
the matrix (or nrow x ncol x bands array, nativeRaster, or colour matrix) in raster order
xmin, xmax, ymin, ymax
NULL, or list(x, y) of (nrow + 1) x (ncol + 1) cell
corner matrices for data that can't be placed by an extent
NULL, or list(x, y) of nrow x ncol cell centre
matrices when they were given as coordinates (with corners)
named dimension sizes of the input array
names of the x and y dimensions
named list of the indices drawn for the other dimensions
named character, the coordinate value of each slice index where known
An array with more than two dimensions (or two named dimensions) is drawn one 2D slice at a time. The two spatial dimensions are found in this order:
the xy argument, dimension names or positions, x first
dimension names, from names(dim(x)) (as zaro::zaro_read()
gives) or names(dimnames(x)) (as zaro::zaro_array() gives), or the
gis attribute of gdalraster::mdim_read() output, matched against
common names ("x", "lon", "longitude", "nav_lon", "xi_rho", ...)
position: the first two dimensions, as rows (y) then columns (x) for an R array, or as x then y for GDAL reader output
Every other dimension takes the index given by slice, or 1. A message
reports the slice drawn and how to ask for the others. Set
options(ximage.verbose = FALSE) to silence it. Selecting 3 or 4 indices
along one dimension draws them as an RGB(A) composite, e.g.
slice = list(band = c(4, 3, 2)). A dimension named like a band ("band",
"channel", "rgb", ...) with 3 or 4 entries is drawn as a composite by
default, and so is the third dimension of an unnamed 3D array with 2 to 4
entries (grey-alpha, RGB, RGBA, unchanged from earlier versions).
Only the selected slice is read, by [, so lazy arrays (such as
zaro::zaro_array() output) fetch just the chunks that slice needs.
The drawn slice is put in raster order: first row at the top. When the y coordinates are known and increase with the row index (most CF, NetCDF and Zarr data, latitude south to north), the rows are reversed so that north is up, and decreasing x coordinates reverse the columns.
Coordinates come from the input's metadata (the gis attribute of
gdalraster multidimensional reads, ndr coordinates and affine indexes) or
from the coords argument, list(x = , y = ):
a vector with one value per cell gives cell centres
a vector with one more value than cells gives cell edges (as CF bounds do)
matrices give curvilinear coordinates, cell centres (one per cell) or corners (one more in each direction), in the same layout as the data
Regularly spaced coordinates give an extent and the image is drawn with
graphics::rasterImage(). Irregular spacing, curvilinear coordinates and
rotated or sheared affine transforms are drawn cell by cell as quads (see
xmesh()). Corners are found from centres by averaging the four
neighbours and extrapolating at the edges (longitudes that wrap need to be
made continuous first).
Physical values: scale and offset in gdalraster multidimensional output
are applied. Values of magnitude 1e30 or more are reported as a likely
fill value, set them to NA (zaro::zaro_array(cf = TRUE) does this).
## an array (lat, lon, time) with time last, lat south to north a <- array(rep(volcano[87:1, ], 3) * rep(1:3, each = length(volcano)), c(lat = 87, lon = 61, time = 3)) d <- as_ximage(a, coords = list(x = 100 + 1:61, y = -60 + 1:87)) d$extent ximage(a, slice = list(time = 2), coords = list(x = 100 + 1:61, y = -60 + 1:87)) xslices(a)## an array (lat, lon, time) with time last, lat south to north a <- array(rep(volcano[87:1, ], 3) * rep(1:3, each = length(volcano)), c(lat = 87, lon = 61, time = 3)) d <- as_ximage(a, coords = list(x = 100 + 1:61, y = -60 + 1:87)) d$extent ximage(a, slice = list(time = 2), coords = list(x = 100 + 1:61, y = -60 + 1:87)) xslices(a)
Data obtained from png package.
logo_n A matrix of colour values in native raster form.
logo_a An array of RGB colour values.
ximage(logo_n, asp = .3) ximage(logo_a, extent = c(8, 18, 60, 80), add = TRUE) rect(8, 60, 18, 80)ximage(logo_n, asp = .3) ximage(logo_a, extent = c(8, 18, 60, 80), add = TRUE) rect(8, 60, 18, 80)
Data obtained from GEBCO 2019, via whatarelief package from AAD COG (GeoTIFF).
A matrix of global elevation values in a smallish matrix, extent is -180,180,-90,90, crs is "OGC:CRS84".
ximage(topo, extent = c(-180, 180, -90, 90)) ximage(logo_n, extent = c(135, 155, -48, -30), add = TRUE)ximage(topo, extent = c(-180, 180, -90, 90)) ximage(logo_n, extent = c(135, 155, -48, -30), add = TRUE)
Like contour() but to work with ximage()
xcontour( x, extent = NULL, ..., add = FALSE, slice = NULL, xy = NULL, coords = NULL )xcontour( x, extent = NULL, ..., add = FALSE, slice = NULL, xy = NULL, coords = NULL )
x |
something we can contour |
extent |
optional, numeric xmin,xmax,ymin,ymax |
... |
Arguments passed on to
|
add |
add to plot, or start afresh |
slice |
index of the slice to draw for arrays with more than two
dimensions: a named list or vector, e.g. |
xy |
the two spatial dimensions, x then y, as names or positions |
coords |
optional coordinates of the spatial dimensions,
|
Input may be anything ximage() accepts that holds data values: a matrix,
a list from gdal_raster_data() in the vapour package or from read_ds()
in the gdalraster package, or an array (one slice is drawn, see
as_ximage()).
With irregular or curvilinear coords the contours are traced in the
index space of the matrix and placed by interpolating the cell centre
coordinates. Curvilinear contours are drawn with graphics::lines()
without labels ('levels' and 'nlevels' are used, other arguments go to
lines()).
nothing, called for its side effect of creating or adding to a plot
#EPSG:27200 see https://github.com/mdsumner/volcano ex <- c(2667400, 2668010, 6478700, 6479570) v <- volcano[nrow(volcano):1, ncol(volcano):1] ximage(v, extent = ex, asp = 1) xcontour(v, add = TRUE, extent = ex, col = "white") xrect(ex, add = TRUE, border = "hotpink", lwd = 5) ## curvilinear lon <- outer(1:87, 1:61, function(i, j) j + i / 10) lat <- outer(1:87, 1:61, function(i, j) -i + j / 20) ximage(volcano, coords = list(x = lon, y = lat), asp = 1) xcontour(volcano, coords = list(x = lon, y = lat), add = TRUE)#EPSG:27200 see https://github.com/mdsumner/volcano ex <- c(2667400, 2668010, 6478700, 6479570) v <- volcano[nrow(volcano):1, ncol(volcano):1] ximage(v, extent = ex, asp = 1) xcontour(v, add = TRUE, extent = ex, col = "white") xrect(ex, add = TRUE, border = "hotpink", lwd = 5) ## curvilinear lon <- outer(1:87, 1:61, function(i, j) j + i / 10) lat <- outer(1:87, 1:61, function(i, j) -i + j / 20) ximage(volcano, coords = list(x = lon, y = lat), asp = 1) xcontour(volcano, coords = list(x = lon, y = lat), add = TRUE)
ximage combines the best of graphics::image() and graphics::rasterImage().
ximage( x, extent = NULL, zlim = NULL, add = FALSE, ..., xlab = NULL, ylab = NULL, col = hcl.colors(96, "YlOrRd", rev = TRUE), breaks = NULL, alpha = NULL, na.col = "transparent", force = FALSE, slice = NULL, xy = NULL, coords = NULL )ximage( x, extent = NULL, zlim = NULL, add = FALSE, ..., xlab = NULL, ylab = NULL, col = hcl.colors(96, "YlOrRd", rev = TRUE), breaks = NULL, alpha = NULL, na.col = "transparent", force = FALSE, slice = NULL, xy = NULL, coords = NULL )
x |
matrix, array, raw or character matrix, native raster
(nativeRaster, or raster), or list as output by GDAL reader functions,
array from zaro, gdalraster |
extent |
optional, numeric xmin,xmax,ymin,ymax |
zlim |
optional, absolute range of data to map colours to (maintains comparable colours across plots); values outside display as 'na.col'; single-band numeric data only |
add |
add to plot, or start afresh |
... |
passed to plot when |
xlab |
x axis label, empty by default |
ylab |
y axis label, empty by default |
col |
colours to map single-band data to |
breaks |
a set of finite numeric breakpoints for the colours, one more break than colour (if not, colours are interpolated to fit) |
alpha |
optional constant opacity in |
na.col |
colour for missing values, default "transparent" |
force |
proceed with a guessed dimension for very long bare vectors
(see Details), default |
slice |
index of the slice to draw for arrays with more than two
dimensions: a named list or vector, e.g. |
xy |
the two spatial dimensions, x then y, as names or positions |
coords |
optional coordinates of the spatial dimensions,
|
ximage() is a combination those graphics function with the the best features in one.
Allow arrays with RGB/A.
Allow matrix with character (named colours, or hex) or raw (Byte) values
Allow list output from vapour or gdalraster, a list with numeric values, hex character, or nativeRaster
Plot in 0,ncol 0,nrow by default
Override default with extent (xmin, xmax, ymin, ymax)
Allow general numeric values.
Start a plot from scratch without setting up a plot to paint to.
Plot by default in 0,ncol,0,nrow if unspecified.
Draw one slice of arrays with more dimensions, such as Zarr and
NetCDF reads from zaro, gdalraster mdim_read() or ndr.
Place the image by coordinates, including irregular and curvilinear grids.
Data orientation is "raster order", the first cell is the top-left of the displayed image, following scan lines down the page (see the package vignette on orientation).
Arrays with more than two dimensions are drawn one slice at a time,
the spatial dimensions are found by name (or set with xy), the slice
with slice, and a message says which slice was drawn and how to get the
others. Coordinates from the input's metadata or from coords orient and
place the image, irregular or curvilinear coordinates are drawn cell by
cell. See as_ximage() for the details, and xslices() and xpanels()
for working through slices.
Bare atomic vectors (no dim, no 'gis' attribute from gdalraster, no
width/height/depth attributes) are accepted and a dimension is guessed
by integer-division detection of the vector length. The most nearly
square factorization is chosen (preferring landscape, ncol >= nrow) and
the data is assumed to be in raster scanline order, i.e. flat output
from GDAL readers such as vapour::gdal_raster_data() or
gdalraster::read_ds(), built as matrix(x, ncol = NC, byrow = TRUE);
column-major R data needs dim(x) <- c(NR, NC) instead. A message
reports the guess and the candidate factorizations from 1xN through
Nx1, in GDAL dimension order (ncol x nrow, xsize x ysize). Raw
vectors also consider 3-plane (RGB) and 4-plane (RGBA) scanline
pixel-interleaved interpretations; numeric data never gets a plane
interpretation (whole numbers in 0..255 are too common as ordinary
data to imply an image, a much narrower opt-in detection may come
later). For very long vectors (more than
getOption("ximage.guess_max", 2^24) elements) the guess stops with
an error unless force = TRUE, or set the dimension explicitly.
Colour mapping via 'col', 'breaks', and 'zlim' applies to single-band numeric data only. Multi-band (grey/alpha, RGB, RGBA) data is scaled automatically: values within 0,1 are used as-is, within 0,255 are divided by 255, and anything else is rescaled by the finite range of the colour bands. Missing values (NA, NaN) display as 'na.col' in all cases.
invisibly, a list with 'x' (the colour data as plotted), 'extent'
(xmin, xmax, ymin, ymax used, the 0,ncol 0,nrow index space of the input
if not supplied), 'zlim' (the data range the colours were mapped to, use
it to draw other slices with the same colours), and for arrays 'dims',
'slice' and 'labels' (see as_ximage())
ximage(volcano) ximage(as.raster(matrix(0:1, 49, 56))) v <- volcano v[v > 180] <- NA ximage(v, na.col = "hotpink") ## bare vectors in GDAL scanline order get a guessed dimension, with a ## message listing candidate shapes (ncol x nrow); here the guess 87x61 ## is the mirror of the true 61x87, so pick from the candidates ximage(as.vector(t(volcano))) ## we don't get the right shape because our image is vertically tall ## set manually ximage(matrix(as.vector(t(volcano)), ncol = 61, byrow = TRUE)) ## see that with the transpose form (landscape orientation) our guess is corrrect ## but is that what was intended? (impossible to determine completely automatically) ximage(as.vector(volcano)) ## arrays: (lon, lat, time) as zaro::zaro_array() gives, latitude south ## to north, the first slice is drawn north up with a message a <- array(c(t(volcano[87:1, ]), t(volcano[87:1, ]) * 0.8), c(lon = 61, lat = 87, time = 2)) lonlat <- list(x = seq(140, 150, length.out = 61), y = seq(-45, -30, length.out = 87)) o <- ximage(a, coords = lonlat) ximage(a, coords = lonlat, slice = list(time = 2), zlim = o$zlim) ## curvilinear coordinates, drawn cell by cell lon <- outer(1:87, 1:61, function(i, j) j + i / 10) lat <- outer(1:87, 1:61, function(i, j) -i + j / 20) ximage(volcano, coords = list(x = lon, y = lat), asp = 1)ximage(volcano) ximage(as.raster(matrix(0:1, 49, 56))) v <- volcano v[v > 180] <- NA ximage(v, na.col = "hotpink") ## bare vectors in GDAL scanline order get a guessed dimension, with a ## message listing candidate shapes (ncol x nrow); here the guess 87x61 ## is the mirror of the true 61x87, so pick from the candidates ximage(as.vector(t(volcano))) ## we don't get the right shape because our image is vertically tall ## set manually ximage(matrix(as.vector(t(volcano)), ncol = 61, byrow = TRUE)) ## see that with the transpose form (landscape orientation) our guess is corrrect ## but is that what was intended? (impossible to determine completely automatically) ximage(as.vector(volcano)) ## arrays: (lon, lat, time) as zaro::zaro_array() gives, latitude south ## to north, the first slice is drawn north up with a message a <- array(c(t(volcano[87:1, ]), t(volcano[87:1, ]) * 0.8), c(lon = 61, lat = 87, time = 2)) lonlat <- list(x = seq(140, 150, length.out = 61), y = seq(-45, -30, length.out = 87)) o <- ximage(a, coords = lonlat) ximage(a, coords = lonlat, slice = list(time = 2), zlim = o$zlim) ## curvilinear coordinates, drawn cell by cell lon <- outer(1:87, 1:61, function(i, j) j + i / 10) lat <- outer(1:87, 1:61, function(i, j) -i + j / 20) ximage(volcano, coords = list(x = lon, y = lat), asp = 1)
Draw the faces of a mesh, filled by a value on its vertices or faces, with
the same colour mapping as ximage() ('col', 'breaks', 'zlim', 'alpha',
'na.col'), so a mesh and an image can share a colour scale.
xmesh( x, value = NULL, index = NULL, add = FALSE, ..., col = hcl.colors(96, "YlOrRd", rev = TRUE), breaks = NULL, zlim = NULL, alpha = NULL, na.col = "transparent", border = NULL, method = c("polygon", "raster"), segments = FALSE, dimension = NULL, xlab = NULL, ylab = NULL )xmesh( x, value = NULL, index = NULL, add = FALSE, ..., col = hcl.colors(96, "YlOrRd", rev = TRUE), breaks = NULL, zlim = NULL, alpha = NULL, na.col = "transparent", border = NULL, method = c("polygon", "raster"), segments = FALSE, dimension = NULL, xlab = NULL, ylab = NULL )
x |
a mesh, see Details |
value |
values to fill by, see Details |
index |
faces when |
add |
add to plot, or start afresh |
... |
passed to plot when |
col |
colours to map single-band data to |
breaks |
a set of finite numeric breakpoints for the colours, one more break than colour (if not, colours are interpolated to fit) |
zlim |
optional, absolute range of data to map colours to (maintains comparable colours across plots); values outside display as 'na.col'; single-band numeric data only |
alpha |
optional constant opacity in |
na.col |
colour for missing values, default "transparent" |
border |
outline colour of the faces, default none when filled and the foreground colour when not |
method |
"polygon" (default) or "raster", see Details |
segments |
draw the mesh's constraint edges (cdtr |
dimension |
for |
xlab |
x axis label, empty by default |
ylab |
y axis label, empty by default |
A mesh is vertices (x, y), faces (triangles or quads, 1-based vertex indices) and optionally values. These inputs are recognised by their structure, no extra packages are needed to draw them:
cdtr::cdt_triangulate() output (and RTriangle): P, T, with
per-vertex attributes PA and per-triangle depth, and constraint
edges S
laridae::lari_triangulate() or laridae::lari_tables() output:
vertices (x, y and attribute columns), triangles (v0, v1, v2, depth)
and segments (a live laridae_mesh handle is drawn with
xmesh(laridae::lari_tables(m)))
rgl 'mesh3d' objects (from quadmesh, anglr, textures): vb, it,
ib, with material$color and the z coordinate as values
vertices as a two-column matrix, a data frame with x and y, or
list(x, y), with faces in index (3 or 4 columns)
value can be a vector with one value per vertex or one per face (when
the counts are equal it is taken per vertex), the name of a vertex or face
attribute (e.g. "depth" for cdtr and laridae, and "x" and "y" for any
mesh), colours, or a single fill colour. With no value the mesh is drawn as outlines.
The "polygon" method draws every face as a polygon in one call, vertex
values are averaged to their faces (flat shading). The "raster" method
locates each pixel centre of the plot in the mesh and interpolates vertex
values linearly across its triangle (quads are split in two), then draws
the result with ximage(): smooth shading, and the cost is in pixels
not faces, so it suits big meshes. Face values are constant on each face,
pixels outside the mesh are 'na.col'. It needs the cdtr package (>= 0.2.0,
for cdtr::cdt_locate()), and falls back to "polygon" with a message.
Faces with a vertex that is not finite are dropped, so a projected mesh
can mark vertices that fail (or faces to remove, such as those crossing
the dateline) with NA.
invisibly, a list with 'vertices', 'faces', 'col' (face colours, or the colour matrix drawn by the "raster" method) and 'zlim'
## a quad mesh of volcano's cells, as bare vertices and index nr <- nrow(volcano); nc <- ncol(volcano) xy <- cbind(rep(0:nc, each = nr + 1), rep(nr:0, nc + 1)) i <- rep(seq_len(nc), each = nr); j <- rep(seq_len(nr), nc) quads <- cbind((i - 1) * (nr + 1) + j, i * (nr + 1) + j, i * (nr + 1) + j + 1, (i - 1) * (nr + 1) + j + 1) xmesh(xy, index = quads, value = as.vector(volcano), asp = 1) ## a triangulation, coloured by a per-vertex value if (requireNamespace("cdtr", quietly = TRUE)) { set.seed(1) pts <- cbind(runif(300), runif(300)) tri <- cdtr::cdt_triangulate(pts[, 1], pts[, 2]) z <- sin(tri$P[, 1] * 6) + cos(tri$P[, 2] * 6) xmesh(tri, value = z, border = "grey40", asp = 1) xmesh(tri, value = z, method = "raster", asp = 1) }## a quad mesh of volcano's cells, as bare vertices and index nr <- nrow(volcano); nc <- ncol(volcano) xy <- cbind(rep(0:nc, each = nr + 1), rep(nr:0, nc + 1)) i <- rep(seq_len(nc), each = nr); j <- rep(seq_len(nr), nc) quads <- cbind((i - 1) * (nr + 1) + j, i * (nr + 1) + j, i * (nr + 1) + j + 1, (i - 1) * (nr + 1) + j + 1) xmesh(xy, index = quads, value = as.vector(volcano), asp = 1) ## a triangulation, coloured by a per-vertex value if (requireNamespace("cdtr", quietly = TRUE)) { set.seed(1) pts <- cbind(runif(300), runif(300)) tri <- cdtr::cdt_triangulate(pts[, 1], pts[, 2]) z <- sin(tri$P[, 1] * 6) + cos(tri$P[, 2] * 6) xmesh(tri, value = z, border = "grey40", asp = 1) xmesh(tri, value = z, method = "raster", asp = 1) }
Draw rectangles from four colummns xmin,xmax,ymin,ymax
xrect(x, add = FALSE, ..., asp = 1L)xrect(x, add = FALSE, ..., asp = 1L)
x |
four columns worth of rectangles |
add |
instantiate a plot or add to existing (default is |
... |
arguments passed to |
asp |
aspect ratio, defaults to 1 |
Calls rect(), but will instantiate a plot if add = FALSE.
A way of generating input to this function is to use extent_from_cell in the
vaster package, vapour_read_extent in the vapour package, or various tiling logic tools
in spatial packages.
nothing, called for side effect of creating or adding to a plot
xrect(runif(100)) xrect(sort(runif(100))) xrect(runif(100), col = hcl.colors(25, alpha = seq(.2, .8, length.out = 25))) ex <- c(0.2, 0.8, .2, .6) xrect(ex, add = TRUE, lwd = 5, lty = 2)xrect(runif(100)) xrect(sort(runif(100))) xrect(runif(100), col = hcl.colors(25, alpha = seq(.2, .8, length.out = 25))) ex <- c(0.2, 0.8, .2, .6) xrect(ex, add = TRUE, lwd = 5, lty = 2)
xslices() lists the slices of an array that ximage() can draw: one
row per combination of the non-spatial dimensions, with a column of
indices for each and a "_label" column with its coordinate value where
known. Only metadata is read. A row can be given to slice in ximage()
and friends.
xslices(x, xy = NULL) xpanels( x, slice = NULL, ..., zlim = NULL, xy = NULL, coords = NULL, col = hcl.colors(96, "YlOrRd", rev = TRUE), breaks = NULL, alpha = NULL, na.col = "transparent", main = NULL, mfrow = NULL, max_panels = 16L )xslices(x, xy = NULL) xpanels( x, slice = NULL, ..., zlim = NULL, xy = NULL, coords = NULL, col = hcl.colors(96, "YlOrRd", rev = TRUE), breaks = NULL, alpha = NULL, na.col = "transparent", main = NULL, mfrow = NULL, max_panels = 16L )
x |
an array, or anything |
xy |
the two spatial dimensions, x then y, as names or positions |
slice |
slices to draw, see Details |
... |
passed to plot for each panel |
zlim |
optional, absolute range of data to map colours to (maintains comparable colours across plots); values outside display as 'na.col'; single-band numeric data only |
coords |
optional coordinates of the spatial dimensions,
|
col |
colours to map single-band data to |
breaks |
a set of finite numeric breakpoints for the colours, one more break than colour (if not, colours are interpolated to fit) |
alpha |
optional constant opacity in |
na.col |
colour for missing values, default "transparent" |
main |
panel titles, default from the slice and its label |
mfrow |
panel layout, default from |
max_panels |
the most panels drawn by default |
xpanels() draws several slices side by side with one colour scale (the
range of all the slices drawn, unless 'zlim' or 'breaks' is given), each
titled by its slice. Give the slices as a list with several indices along
one dimension, e.g. list(time = 1:6), or as rows of xslices() output.
The default is the first slices along the first non-spatial dimension.
xslices() a data frame (with zero columns for data with no
dimensions to slice); xpanels() invisibly, a list of what ximage()
returns for each panel and the 'zlim' used
a <- array(c(volcano, volcano * 0.9, volcano * 0.8, volcano * 0.7), c(y = 87, x = 61, time = 4)) xslices(a) xpanels(a) xpanels(a, slice = list(time = c(1, 4)))a <- array(c(volcano, volcano * 0.9, volcano * 0.8, volcano * 0.7), c(y = 87, x = 61, time = 4)) xslices(a) xpanels(a) xpanels(a, slice = list(time = c(1, 4)))
Draw the values of a matrix as text labels, each at the centre of its cell
in the same layout used by ximage(). The first cell of the matrix is the
top-left label, and each row of the matrix is a line of labels reading
left to right down the page ("raster order").
xtext( x, extent = NULL, add = FALSE, cex = NULL, fit = 0.9, ..., slice = NULL, xy = NULL, coords = NULL )xtext( x, extent = NULL, add = FALSE, cex = NULL, fit = 0.9, ..., slice = NULL, xy = NULL, coords = NULL )
x |
a matrix of values to draw as labels, or a reader-output list |
extent |
optional, numeric xmin,xmax,ymin,ymax (defaults to the 0,ncol 0,nrow index space of the matrix) |
add |
add to plot, or start afresh |
cex |
text size, computed to fit the cells if not supplied |
fit |
fraction of the cell the largest label should occupy when 'cex' is computed, default 0.9 |
... |
arguments passed to |
slice |
index of the slice to draw for arrays with more than two
dimensions: a named list or vector, e.g. |
xy |
the two spatial dimensions, x then y, as names or positions |
coords |
optional coordinates of the spatial dimensions,
|
Text size is chosen automatically to fit the largest label within a cell, scaled by 'fit' (use 'cex' to override). Labels that are NA are not drawn.
Input may be a matrix (values are used as labels via format()), a
list in the style of vapour or gdalraster reader output (a row-major
vector with 'dimension'/'extent' attributes, or a 'gis' attribute), or an
array (one slice is labelled, see as_ximage()). With irregular or
curvilinear coords each label sits at the centre of its cell's corners.
invisibly, a list with 'x', 'y' (label positions), 'labels', and 'cex' as used
m <- matrix(1:12, 3, byrow = TRUE) ximage(m) xtext(m, add = TRUE) ## the label positions are cell centres in the extent ximage(volcano, extent = c(0, 1, 0, 1)) xtext(volcano[seq(1, 87, by = 8), seq(1, 61, by = 6)], extent = c(0, 1, 0, 1), add = TRUE, col = "white")m <- matrix(1:12, 3, byrow = TRUE) ximage(m) xtext(m, add = TRUE) ## the label positions are cell centres in the extent ximage(volcano, extent = c(0, 1, 0, 1)) xtext(volcano[seq(1, 87, by = 8), seq(1, 61, by = 6)], extent = c(0, 1, 0, 1), add = TRUE, col = "white")