Title: | Draw Images of Raster Data and Related Adornments |
---|---|
Description: | Draw images easily and as if doing that was considered desirable or even essential to be able to do. 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 (or will be) supported. A little bit like 'image()' and 'rasterImage()' from the 'graphics' package but with the good features celebrated and made easier to use. |
Authors: | Michael D. Sumner [aut, cre], Chris Toney [ctb] |
Maintainer: | Michael D. Sumner <[email protected]> |
License: | MIT + file LICENSE |
Version: | 0.0.0.9014 |
Built: | 2024-12-24 02:41:22 UTC |
Source: | https://github.com/hypertidy/ximage |
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)
To work with ximage()
xcontour(x, extent = NULL, ..., add = FALSE)
xcontour(x, extent = NULL, ..., add = FALSE)
x |
something we can contour |
extent |
optional, numeric xmin,xmax,ymin,ymax |
... |
Arguments passed on to
|
add |
add to plot, or start afresh |
Input may be a matrix or a list from gdal_raster_data() in the vapour package.
nothing, called for its side effect of creating or adding to a plot
ex <- c(2667394, 2668004, 6478902, 6479772) v <- volcano[nrow(volcano):1, ncol(volcano):1] ximage(v, extent = ex, asp = 1) #im <- whatarelief::imagery(extent = ex, projection = "+proj=nzmg +datum=WGS84") #ximage(im, add = TRUE, extent = ex) xcontour(v, add = TRUE, extent = ex, col = "white") xrect(ex, add = TRUE, border = "hotpink", lwd = 5)
ex <- c(2667394, 2668004, 6478902, 6479772) v <- volcano[nrow(volcano):1, ncol(volcano):1] ximage(v, extent = ex, asp = 1) #im <- whatarelief::imagery(extent = ex, projection = "+proj=nzmg +datum=WGS84") #ximage(im, add = TRUE, extent = ex) xcontour(v, add = TRUE, extent = ex, col = "white") xrect(ex, add = TRUE, border = "hotpink", lwd = 5)
ximage combines the best of image() and rasterImage().
ximage( x, extent = NULL, zlim = NULL, add = FALSE, ..., xlab = NULL, ylab = NULL, col = hcl.colors(96, "YlOrRd", rev = TRUE), breaks = NULL )
ximage( x, extent = NULL, zlim = NULL, add = FALSE, ..., xlab = NULL, ylab = NULL, col = hcl.colors(96, "YlOrRd", rev = TRUE), breaks = NULL )
x |
matrix, array, or native raster (nativeRaster, or raster) |
extent |
optional, numeric xmin,xmax,ymin,ymax |
zlim |
optional, range of data to set colour map (to maintain absolute colours across multiple plots) |
add |
add to plot, or start afresh |
... |
passed to plot when |
xlab |
x axis label, empty by default |
ylab |
y axis lable, empty by default |
col |
optional colours to map matrix/array data to |
breaks |
a set of finite numeric breakpoints for the colours: |
ximage()
is designed like graphics function with the following limitations removed,
image()
1:4, rasterImage()
5:7.
Allow arrays with RGB/A.
Allow matrix with character (named colours, or hex) or raw (Byte) values
Allow list output from vapour, 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.
ximage uses the GIS raster default used by rasterImage. WIP: There is a similar function 'image0?' that provides the same features but assumes that orientation is like image...
Colours by 'col' are only mapped for numeric data, this may change (to remap RGB or raw imagery via greyscale conversion)
a list with 'x' and 'extent' invisibly (extent is the 0,ncol 0,nrow space of the array if not supplied)
ximage(volcano) ximage(as.raster(matrix(0:1, 49, 56)))
ximage(volcano) ximage(as.raster(matrix(0:1, 49, 56)))
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
.
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))) #example(xcontour, ask = FALSE) 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))) #example(xcontour, ask = FALSE) ex <- c(0.2, 0.8, .2, .6) xrect(ex, add = TRUE, lwd = 5, lty = 2)