BarplotUpstreamClasses: Bar plots of upstream-averaged classes of HYPE sub-basins

BarplotUpstreamClassesR Documentation

Bar plots of upstream-averaged classes of HYPE sub-basins

Description

Function to plot upstream-averaged landscape property classes of one or several sub-basins as bar plots, e.g. land use or soils. Builds on barplot.

Usage

BarplotUpstreamClasses(
  x,
  type = c("custom", "landuse", "soil", "crop"),
  desc = NULL,
  class.names = NULL,
  xlab = NULL,
  ylab = "Area fraction (%)",
  ylim = c(-0.05, max(x[, -1] * 150)),
  names.arg = rep("", ncol(x) - 1),
  cex.axis = 1,
  cex.names = 0.9,
  col = NULL,
  border = NA,
  legend.text = NULL,
  legend.pos = "left",
  pars = list(mar = c(1.5, 3, 0.5, 0.5) + 0.1, mgp = c(1.5, 0.3, 0), tcl = NA, xaxs =
    "i")
)

Arguments

x

Data frame, containing column-wise class group fractions with SUBIDs in first column. Typically a result from UpstreamGroupSLCClasses. Column names of class group fractions must end with _x, with x giving the class group ID, see details.

type

Character string keyword for class group labeling, used in combination with desc. Type of class groups, either "landuse", "soil", or "crop" (abbreviations allowed). If "custom" (default), labeling can be fine- tuned with argument class.names.

desc

List for use with type. Class description labels imported from a 'description.txt' file, for labeling of standard class groups. See ReadDescription for formatting details.

class.names

Character vector of class group names, with same length as number of class group fractions in x. Specification of bar labels, alternative to arguments type and desc, in particular for cases where a non-standard grouping was used for x.

xlab

Character string, x-axis label, with defaults for standard groups land use, soil, and crops.

ylab

Character string, y-axis label.

ylim

Numeric, two element vector with limits for the y-axis. Defaults to values which give ample space for bar labels.

names.arg

Character vector, see barplot. Defaults to no labeling below bars (text labels within plot through arguments above).

cex.axis

Numeric, character expansion factor for axis annotation and labels.

cex.names

Numeric, character expansion factor for class group labels.

col

Colors for bars. Defaults to type-specific pre-defined color.

border

Colors for bar borders. Defaults to no borders.

legend.text

Character, if provided, a legend will be plotted. Defaults to none if one sub-basin is plotted, and SUBIDs if several sub-basins are plotted. Set to NA to prevent legend plotting in any case.

legend.pos

Character keyword for legend positioning, most likely "left" or "right". For details, see legend.

pars

List of tagged values which are passed to par.

Details

BarplotUpstreamClasses is a wrapper for barplot, with vertical labels plotted over the class group bars. Most arguments have sensible defaults, but can be adapted for fine-tuning if necessary.

Column names of x are used to link class groups to class IDs in desc. HYPE has no formal requirements on how class IDs are numbered and when one of the standard groups land use, soil, or crop are provided in x, there might be missing class IDs. Class names in desc are matched against column name endings '_x' in x. If manual names are provided in class.names, the column name endings must be a consecutive sequence from 1 to number of elements in class.names.

Value

The function returns bar midpoints, see description in barplot.

See Also

UpstreamGroupSLCClasses barplot

Examples

# Import source data
te1 <- ReadGeoData(filename = system.file("demo_model", "GeoData.txt", package = "HYPEtools"))
te2 <- ReadGeoClass(filename = system.file("demo_model", "GeoClass.txt", package = "HYPEtools"))
te3 <- ReadDescription(filename = system.file("demo_model", "description.txt", 
                       package = "HYPEtools"))
# Calculate plot data, upstream soil fractions
te4 <- UpstreamGroupSLCClasses(subid = 63794, gd = te1, gcl = te2, type = "soil")
# Function call
BarplotUpstreamClasses(x = te4, type = "s", desc = te4, ylim = c(0,100))


rcapell/RHYPE documentation built on Feb. 28, 2024, 3:11 p.m.