PlotCrossSection: Plot Cross Section

View source: R/PlotCrossSection.R

PlotCrossSectionR Documentation

Plot Cross Section

Description

Draw a cross-section view of raster data. A key showing how the colors map to raster values is shown below the map. The width and height of the graphics region will be automagically determined in some cases.

Usage

PlotCrossSection(
  transect,
  rs,
  geo.lays = names(rs),
  val.lays = NULL,
  wt.lay = NULL,
  asp = 1,
  ylim = NULL,
  max.dev.dim = c(43, 56),
  n = NULL,
  breaks = NULL,
  pal = NULL,
  col = NULL,
  ylab = NULL,
  unit = NULL,
  id = c("A", "A'"),
  labels = NULL,
  explanation = NULL,
  features = NULL,
  max.feature.dist = Inf,
  draw.key = TRUE,
  draw.sep = TRUE,
  is.categorical = FALSE,
  contour.lines = NULL,
  bg.col = NULL,
  wt.col = "#FFFFFFD8",
  bend.label = "BEND",
  scale.loc = NULL,
  file = NULL
)

Arguments

transect

'SpatialLines'. Piecewise linear transect line.

rs

'RasterStack' or 'RasterBrick'. Collection of raster layers with the same extent and resolution.

geo.lays

'character' vector. Names in rs that specify the geometry-raster layers; these must be given in decreasing order, that is, from the upper most (such as land surface) to the lowest (such as a bedrock surface).

val.lays

'character' vector. Names in rs that specify the value-raster layers (optional). Values from the first layer are mapped as colors to the area between the first and second geometry layers; the second layer mapped between the second and third geometry layers, and so on.

wt.lay

'character' string. Name in rs that specifies the water-table-raster layer (optional).

asp

'numeric' number. y/x aspect ratio for spatial axes. Defaults to 1 (one unit on the x-axis equals one unit on the y-axis) when r is projected, otherwise, a calculated value based on axes limits is used.

ylim

'numeric' vector of length 2. Minimum and maximum values for the y-axis.

max.dev.dim

'numeric' vector of length 2, value is recycled as necessary. Maximum width and height for the graphics device in picas, respectively. Where 1 pica is equal to 1/6 of an inch, 4.2333 of a millimeter, or 12 points. Suggested dimensions for single-column, double-column, and side title figures are c(21, 56), c(43, 56), and c(56, 43), respectively. This argument is only applicable when the file argument is specified.

n

'integer' count. Desired number of intervals to partition the range of raster values (optional).

breaks

'numeric' vector. Break points used to partition the colors representing numeric raster values (optional).

pal

'function'. Color palette to be used to assign colors in the plot.

col

'character' vector. Colors to be used in the plot. This argument requires breaks specification for numeric raster values and overrides any palette function specification. For numeric values there should be one less color than breaks. Categorical data require a color for each category.

ylab

'character' string. Label for the y axis.

unit

'character' string. Label for the measurement unit of the x- and y-axes.

id

'character' vector of length 2. Labels for the end points of the transect line, defaults to A–A'.

labels

'list'. Location and values of labels in the color key. This list may include components at and labels.

explanation

'character' string. Label explaining the raster cell value.

features

'SpatialPointsDataFrame'. Point features adjacent to the transect line that are used as reference labels for the upper geometry layer. Labels taken from first column of embedded data table.

max.feature.dist

'numeric' number. Maximum distance from a point feature to the transect line, specified in the units of the rs projection.

draw.key

'logical' flag. Whether a color key should be drawn.

draw.sep

'logical' flag. Whether lines separating geometry layers are drawn.

is.categorical

'logical' flag. If true, cell values in val.lays represent categorical data; otherwise, these data values are assumed continuous.

contour.lines

'list'. If specified, contour lines are drawn. The contours are described using a list of arguments supplied to the contour function. Passed arguments include drawlables, method, and col.

bg.col

'character' string. Color used for the background of the area below the top geometry-raster layer.

wt.col

'character' string. Color used for the water-table line.

bend.label

'character' vector. Labels to place at top of the bend-in-section lines, values are recycled as necessary to the number of bends.

scale.loc

'character' string. Position of the scale bar in the main plot region; see GetInsetLocation function for keyword descriptions.

file

'character' string. Name of the output file. Specifying this argument will start a graphics device driver for producing a PDF or PNG file format—the file extension determines the format type. The width and height of the graphics region will be automagically determined and included with the function's returned values, see "Value" section for details; these device dimensions can be useful when creating similar map layouts in dynamic reports.

Value

A 'list' with the following graphical parameters:

din

device dimensions (width, height), in inches.

usr

extremes of the coordinates of the plotting region (x1, x2, y1, y2).

heights

relative heights on the device (upper, lower) for the map and color-key plots.

Author(s)

J.C. Fisher, U.S. Geological Survey, Idaho Water Science Center

See Also

AddScaleBar, AddColorKey, ExtractAlongTransect

Examples

m <- datasets::volcano
m <- m[nrow(m):1, ncol(m):1]
x <- seq(from = 2667405, length.out = ncol(m), by = 10)
y <- seq(from = 6478705, length.out = nrow(m), by = 10)
r1 <- raster::raster(m, xmn = min(x), xmx = max(x), ymn = min(y),
                     ymx = max(y), crs = "+init=epsg:27200")
r2 <- min(r1[]) - r1 / 10
r3 <- r1 - r2
rs <- raster::stack(r1, r2, r3)
names(rs) <- c("r1", "r2", "r3")
xy <- rbind(c(2667508, 6479501),
            c(2667803, 6479214),
            c(2667508, 6478749))
transect <- sp::Lines(list(sp::Line(xy)), ID = "Transect")
transect <- sp::SpatialLines(list(transect),
                             proj4string = raster::crs(rs))
xy <- rbind(c(2667705, 6478897),
            c(2667430, 6479178))
p <- sp::SpatialPoints(xy, proj4string = raster::crs(rs))
d <-  data.frame("label" = c("Peak", "Random"), stringsAsFactors = TRUE)
features <- sp::SpatialPointsDataFrame(p, d, match.ID = TRUE)
bg.image <- raster::hillShade(raster::terrain(r1, "slope"),
                              raster::terrain(r1, "aspect"))
PlotMap(r1, bg.image = bg.image,
        pal = GetColors(scheme = "DEM screen", alpha = 0.8),
        scale.loc = "top", arrow.loc = "topright",
        contour.lines = list("col" = "#1F1F1FA6"),
        useRaster = TRUE)
lines(transect)
raster::text(as(transect, "SpatialPoints"),
             labels = c("A", "BEND", "A'"),
             halo = TRUE, cex = 0.7, pos = c(3, 4, 1),
             offset = 0.1, font = 4)
points(features, pch = 19)
raster::text(features, labels = features@data$label, halo = TRUE,
             cex = 0.7, pos = 4, offset = 0.5, font = 4)

dev.new()
asp <- 5
unit <- "METERS"
explanation <- "Vertical thickness between layers, in meters."
PlotCrossSection(transect, rs, geo.lays = c("r1", "r2"),
                 val.lays = "r3", ylab = "Elevation", asp = asp,
                 unit = unit, explanation = explanation,
                 features = features, max.feature.dist = 100,
                 bg.col = "#E1E1E1", bend.label = "BEND IN\nSECTION",
                 scale.loc = NULL)
AddScaleBar(unit = unit, vert.exag = asp, inset = 0.05)

val <- PlotCrossSection(transect, rs, geo.lays = c("r1", "r2"),
                        val.lays = "r3", ylab = "Elevation", asp = 5,
                        unit = "METERS", explanation = explanation,
                        file = "Rplots.png")
print(val)

graphics.off()
file.remove("Rplots.png")


USGS-R/inlmisc documentation built on Sept. 17, 2022, 2:38 a.m.