draw_thematic_OCN {OCNet} | R Documentation |
Draw thematic map on an Optimal Channel Network
Description
Function that draws OCNs with color of RN or AG nodes depending on an arbitrary theme.
Usage
draw_thematic_OCN(OCN,theme=NA*numeric(OCN$AG$nNodes),
chooseAggregation = NULL,
discreteLevels = FALSE,
colLevels = NULL, cutoff = FALSE,
colPalette = colorRampPalette(c("yellow","red","black")),
exactDraw = FALSE, chooseCM = FALSE, drawNodes = FALSE,
nodeType = "upstream", nanColor = "#00BFFF",
riverColor = "#00BFFF", backgroundColor = "#999999",
addLegend = TRUE, min_lwd = 0.5, max_lwd = 5,
add = FALSE, args_imagePlot = list(), args_legend = list(),
...)
Arguments
OCN |
A |
theme |
Vector (of length |
chooseAggregation |
Only effective if |
discreteLevels |
Logical. If |
colLevels |
Number of colors in the palette. If |
cutoff |
Logical. If |
colPalette |
Color palette used to display theme values. |
chooseCM |
Index of catchment to display (only effective if |
exactDraw |
Logical. If |
drawNodes |
Logical. If |
nodeType |
Only effective if |
nanColor |
Color attributed to RN or AG nodes whose theme value is |
riverColor |
Only effective if |
backgroundColor |
Color used in the background of the figure. It can be either a single value, or a vector with number of components
equal to |
addLegend |
Logical. If |
min_lwd , max_lwd |
Minimum and maximum values of line width used to display the OCN (actual line width is proportional to the square root of drainage area). |
add |
Logical. If |
args_imagePlot |
Only effective if |
args_legend |
Only effective if |
... |
Further arguments to be passed to |
Details
This function can be used to show how a certain spatial field varies along the river network.
Default plot options. By default, it is set asp = 1
, xlab = ""
, ylab = ""
. If at least one between xlim
and ylim
is specified by the user, the default for axes
is TRUE
, and is FALSE
if not. Specifying xlim
and ylim
helps zoom into a portion of the river network; however, due to the default asp = 1
, the displayed region might be larger than what is expected if the ranges of xlim
and ylim
are different. To avoid this, set asp = NA
(at the cost of producing a deformed river network).
Adding scale bar and north arrow. Scale bar and north arrow can be added via terra
's functions sbar
and north
, respectively. However, note that arguments d
and xy
must be specified by the user (because no rast
object is plotted). See example 5.
Value
No output is returned.
Examples
# 1a) Six different ways to display contributing area at the AG level
OCN <- aggregate_OCN(landscape_OCN(OCN_20), thrA = 4)
old.par <- par(no.readonly = TRUE)
par(mfrow=c(2,3), oma = c(0, 0, 3, 0))
draw_thematic_OCN(OCN$AG$A, OCN, colPalette = hcl.colors)
title("Continuous levels \n Colors on edges")
draw_thematic_OCN(OCN$AG$A, OCN, discreteLevels = TRUE,
colPalette = hcl.colors)
title("Discrete, unique levels \n Colors on edges")
draw_thematic_OCN(OCN$AG$A, OCN, discreteLevels = TRUE,
colLevels = c(1, 10, 50, 100, 500),
colPalette = hcl.colors)
title("Discrete, user-defined levels \n Colors on edges")
draw_thematic_OCN(OCN$AG$A, OCN, drawNodes = TRUE,
colPalette = hcl.colors)
title("Continuous levels \n Colors on edges")
draw_thematic_OCN(OCN$AG$A, OCN, discreteLevels = TRUE,
drawNodes = TRUE, colPalette = hcl.colors)
title("Discrete, unique levels \n Colors on nodes")
draw_thematic_OCN(OCN$AG$A, OCN, discreteLevels = TRUE,
drawNodes = TRUE, colLevels = c(1, 10, 50, 100, 500),
colPalette = hcl.colors)
title("Discrete, user-defined levels \n Colors on nodes")
mtext("Six different ways to display contributing area [no. pixels]", outer = TRUE, cex = 1.5)
par(old.par)
# 1b) Same as above, but use different colLevels, cutoff combinations
# with DiscreteLevels = FALSE
old.par <- par(no.readonly = TRUE)
par(mfrow=c(1,2))
draw_thematic_OCN(OCN$AG$A, OCN, drawNodes = TRUE,
colLevels = c(0, 200, 1000), colPalette = hcl.colors)
title("All nodes with A > 200 pixels \n are displayed in yellow")
draw_thematic_OCN(OCN$AG$A, OCN, drawNodes = TRUE,
nanColor = "#00000000", colLevels = c(0, 200, 1000),
cutoff = TRUE, colPalette = hcl.colors)
title("All nodes with A > 200 pixels \n are treated as NaN")
par(old.par)
## Not run:
# 2) Display distance to outlet (at the RN level) along the main stem
# of an OCN
OCN <- aggregate_OCN(landscape_OCN(OCN_250_T)) # this takes some seconds
OCN <- paths_OCN(OCN, includePaths = TRUE) # this takes some seconds
distanceToOutlet <- OCN$RN$downstreamPathLength[,OCN$RN$outlet]
farthestNode <- which(distanceToOutlet == max(distanceToOutlet))
mainStem <- OCN$RN$downstreamPath[[farthestNode]][[OCN$RN$outlet]]
theme <- rep(NaN, OCN$RN$nNodes)
theme[mainStem] <- distanceToOutlet[mainStem]
draw_thematic_OCN(theme, OCN)
title("Distance to outlet along the main stem [pixel units]")
## End(Not run)
# 3) Show an OCN without a theme
OCN <- aggregate_OCN(landscape_OCN(OCN_20), thrA = 4)
draw_thematic_OCN(OCN)
draw_thematic_OCN(OCN, xlim=c(3,8), ylim=c(0,5)) # zoom closer at the outlet
# 4) Adjust legend location
draw_thematic_OCN(OCN, OCN$AG$A,
args_imagePlot = list(smallplot = c(0.1, 0.11, 0.1, 0.3)))
draw_thematic_OCN(OCN, OCN$AG$streamOrder,
discreteLevels = TRUE, args_legend = list(x = -2, y = 1))
# 5) add thematic OCN on top of map and show scale bar and north arrow
draw_elev2D_OCN(OCN)
draw_thematic_OCN(OCN, OCN$AG$slope, backgroundColor = NULL,
add = TRUE, colPalette = hcl.colors(1000, "Grays", rev = TRUE),
args_imagePlot = list(smallplot=c(0.05,0.07,0.1,0.9)))
# now add scale bar and north arrow
library(terra)
# sbar() # this would throw an error
# north()# this would throw an error
sbar(d=1, xy=c(min(OCN$FD$X), min(OCN$FD$Y)-1)) # this works
north(d=1, xy=c(max(OCN$FD$X)+1, max(OCN$FD$Y))) # this works