Plots cell values along a vertical transect

transectPlot(
  rast = NULL,
  sampleAxis = "lon",
  axisValue = NA,
  scaleRange = NA,
  plotLegend = TRUE,
  depthLim = as.numeric(max(names(rast))),
  transRange = c(-90, 90),
  transTicks = 20,
  verbose = FALSE,
  ...
)

Arguments

rast

A multilayer SpatRaster object, with names corresponding to the z coordinate represented by the layer. These names must be interpretable by as.numeric.

sampleAxis

Specifies whether a latitudinal ("lat") or longitudinal ("long") transect is desired.

axisValue

Numeric value specifying transect postion.

scaleRange

A numeric vector of length 2, specifying the range that should be used for the plot color scale.

plotLegend

logical, controls whether legend is plotted.

depthLim

A single vector of class numeric. How deep should the plot go?

transRange

A numeric vector of lenghth 2. How far along the transect should be plotted?

transTicks

numeric, spacing between breaks on x axis.

verbose

logical. Switching to FALSE mutes message alerting user if input rast values exceed specified scaleRange.

...

Additional optional arguments to pass to viridis.

Value

A ggplot showing a vertical slice through the SpatRaster.

Note

Only unprojected SpatRaster files are supported.

Examples

library(terra)

rast1 <- rast(ncol=10, nrow=10)
values(rast1) <- rep(0:3, 50)
#> Warning: [setValues] values is larger than the size of cells

rast2 <- rast(ncol=10, nrow=10)
values(rast2) <- c(rep(0, 50), rep(1,25), rep(2,25))

rast3 <- rast(ncol=10, nrow=10)
values(rast3) <- rep(c(1,3,2,1), 25)

distBrick <- c(rast1, rast2, rast3)
names(distBrick) <- c(0:2)

transectPlot(distBrick, depthLim = 3)
#> Scale for y is already present.
#> Adding another scale for y, which will replace the existing scale.
#> Scale for x is already present.
#> Adding another scale for x, which will replace the existing scale.