Learn R Programming

inlmisc (version 0.2.4)

PlotCrossSection: Plot Method for Cross Sections

Description

This function creates 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 = "#E1E1E1", wt.col = "#FFFFFFD8", file = NULL)

Arguments

transect
SpatialLines. Piecewise linear transect line.
rs
RasterStack. Collection of RasterLayer objects with the same extent and resolution.
geo.lays
character. Vector of 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 of 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. The name in rs that specifies the water-table raster layer (optional).
asp
numeric. The 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 giving the minimum and maximum values for the y-axis.
max.dev.dim
numeric. Vector of length 2 giving the maximum width and height for the graphics device in picas, respectively. Suggested dimensions for single-column, double-column, and sidetitle 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. Desired number of intervals to partition the range of raster values (optional).
breaks
numeric. Vector of 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, rainbow by default.
col
character. Vector of 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. Label for the y axis.
unit
character. Label for the measurement unit of the x- and y-axes.
id
character. Vector of length 2 giving the labels for the end points of the transect line, defaults to A--A'.
labels
list. Describes the location and values of labels in the color key. This list may include components at and labels.
explanation
character. Label explaining the raster cell value.
features
SpatialGridDataFrame. Point features adjacent to the transect line that are used as reference labels for the upper geometry layer.
max.feature.dist
numeric. Maximum distance from a point feature to the transect line, specified in the units of the rs projection.
draw.key
logical. If true, a color key should be drawn.
draw.sep
logical. If true, lines separating geometry layers are drawn.
is.categorical
logical. 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 contour. Passed arguments include "drawlables", "method", and "col".
bg.col
character. Color used for the background of the area below the upper geometry raster layer.
wt.col
character. Color used for the water-table line.
file
character. 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

Used for the side-effect of a new plot generated. Returns a list object 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.

See Also

AddScaleBar, AddColorKey, ExtractAlongTransect

Examples

Run this code
data(volcano, package = "datasets")
x <- seq(from = 2667405, length.out = 61, by = 10)
y <- seq(from = 6478705, length.out = 87, by = 10)
r1 <- raster::raster(volcano, xmn = min(x), xmx = max(x), ymn = min(y),
                     ymx = max(y), crs = sp::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::SpatialLines(list(sp::Lines(list(sp::Line(xy)), ID = "Transect")),
                             proj4string = raster::crs(rs))

raster::plot(r1)
lines(transect)
raster::text(as(transect, "SpatialPoints"), labels = c("A", "BEND", "A'"),
             cex = 0.7, pos = c(3, 4, 1), offset = 0.1, font = 4)

explanation <- "Vertical thickness between layers, in meters."
PlotCrossSection(transect, rs, geo.lays = c("r1", "r2"), val.lays = "r3",
                 ylab="Elevation", asp = 5, unit = "METERS", explanation = explanation)

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)

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

Run the code above in your browser using DataLab