|
1 | | -#' Display modeled tree crowns vertically projected on subplot boundaries |
| 1 | +#' Display modeled tree crowns projected vertically on subplot boundaries |
2 | 2 | #' |
3 | 3 | #' `plot_crowns()` draws vertically projected tree crowns as discs overlaid on |
4 | 4 | #' subplot or microplot boundaries. The full four-subplot cluster, or |
5 | 5 | #' individual subplots, can be displayed with trees `>= 5.0` in. (`12.7` cm) |
6 | | -#' diameter, or individual microplots can be display with saplings (i.e., trees |
7 | | -#' `< 5` in. diameter). |
| 6 | +#' diameter. Individual microplots can also be displayed with saplings (i.e., |
| 7 | +#' trees `< 5` in. diameter). |
8 | 8 | #' |
9 | 9 | #' @param tree_list A data frame with tree records for one FIA plot. Must have |
10 | 10 | #' columns `SUBP` (FIA subplot number), `STATUSCD` (FIA integer tree status, |
11 | 11 | #' `1` = live), `DIA` (tree diameter), `HT` (tree height), `ACTUALHT` (tree |
12 | 12 | #' actual height, `ACTUALHT < HT` indicating a broken top), `DIST` (stem |
13 | 13 | #' distance from subplot/microplot center), `AZIMUTH` (horizontal angle from |
14 | | -#' subplot/microplot center to the stem location, in the range `0:359`), and |
| 14 | +#' subplot/microplot center to the stem location, in range `0:359`), and |
15 | 15 | #' `CRWIDTH` (tree crown width). |
16 | 16 | #' @param subplot Optional integer subplot number in the range `1:4` indicating |
17 | | -#' a specific subplot for display. May be `NULL` or `NA` to display the full |
18 | | -#' four-point cluster. |
| 17 | +#' a specific subplot for display. May be `NULL` or `NA` to display the whole |
| 18 | +#' four-point cluster plot. |
19 | 19 | #' @param microplot A logical value, `TRUE` to display the modeled crowns of |
20 | 20 | #' saplings overlaid of the microplot boundary of `subplot = n`. The default is |
21 | 21 | #' `FALSE`. Ignored if `subplot` is not specified. |
|
26 | 26 | #' given in meters, and tree diameters are assumed to be given in centimeters. |
27 | 27 | #' **TODO: not currently implemented** |
28 | 28 | #' @param main Character string giving the main plot title (on top). |
| 29 | +#' @param crown_col The color of tree crowns. |
| 30 | +#' @param stem_col The color of tree stems when plotting an individual subplot |
| 31 | +#' or microplot. |
| 32 | +#' @param subp_border_lwd The line width of subplot boundaries, a _positive_ |
| 33 | +#' number, defaulting to `3`. |
29 | 34 | #' @return |
30 | 35 | #' The input, invisibly. |
31 | 36 | #' |
|
40 | 45 | #' main = "plantation microplot 4") |
41 | 46 | #' @export |
42 | 47 | plot_crowns <- function(tree_list, subplot = NULL, microplot = FALSE, |
43 | | - linear_unit = "ft", main = "") { |
| 48 | + linear_unit = "ft", main = "", crown_col = "#328e13", |
| 49 | + stem_col = "#b85e00", subp_border_lwd = 3){ |
| 50 | + |
| 51 | + if (missing(tree_list) || is.null(tree_list)) |
| 52 | + stop("'tree_list' is required", call. = FALSE) |
| 53 | + |
| 54 | + if (!is.data.frame(tree_list)) |
| 55 | + stop("'tree_list' must be a data frame", call. = FALSE) |
| 56 | + |
| 57 | + required_cols <- c("SUBP", "STATUSCD", "DIA", "HT", "ACTUALHT", "AZIMUTH", |
| 58 | + "DIST", "CRWIDTH") |
| 59 | + |
| 60 | + if (!all(required_cols %in% colnames(tree_list))) |
| 61 | + stop("'tree_list' is missing required columns", call. = FALSE) |
| 62 | + |
| 63 | + if (!all(unique(tree_list$SUBP) %in% c(1, 2, 3, 4))) |
| 64 | + stop("'tree_list$SUBP' contains invalid subplot numbers", call. = FALSE) |
| 65 | + |
| 66 | + if (any(tree_list$AZIMUTH < 0) || any(tree_list$AZIMUTH > 360)) |
| 67 | + stop("'tree_list$AZIMUTH' contains values out of range", call. = FALSE) |
44 | 68 |
|
45 | 69 | if (is.null(linear_unit)) |
46 | 70 | linear_unit <- "ft" |
@@ -113,23 +137,23 @@ plot_crowns <- function(tree_list, subplot = NULL, microplot = FALSE, |
113 | 137 | gdalraster::g_envelope()) |
114 | 138 | names(rct) <- c("xmin", "xmax", "ymin", "ymax") |
115 | 139 |
|
116 | | - xlab <- paste0("x (", linear_unit, ")") |
117 | | - ylab <- paste0("y (", linear_unit, ")") |
| 140 | + xlab <- sprintf("x (%s)", linear_unit) |
| 141 | + ylab <- sprintf("y (%s)", linear_unit) |
118 | 142 | gdalraster::plot_geom(fia_poly, xlab, ylab, main, border = "gray62", |
119 | | - lwd = 3, bbox = rct) |
| 143 | + lwd = subp_border_lwd, bbox = rct) |
120 | 144 |
|
121 | 145 | for (i in seq_len(nrow(trees_in))) { |
122 | | - # alternate green: #40c945 |
123 | | - gdalraster::plot_geom(crowns[[i]], col = "#328e13", border = NA, |
| 146 | + gdalraster::plot_geom(crowns[[i]], col = crown_col, border = NA, |
124 | 147 | add = TRUE) |
125 | 148 | if (subplot) { |
126 | | - gdalraster::plot_geom(stems[[i]], col = "#b85e00", border = NA, |
| 149 | + gdalraster::plot_geom(stems[[i]], col = stem_col, border = NA, |
127 | 150 | add = TRUE) |
128 | 151 | } |
129 | 152 | } |
130 | 153 |
|
131 | 154 | border_col <- grDevices::adjustcolor("gray62", alpha.f = 0.2) |
132 | | - gdalraster::plot_geom(fia_poly, border = border_col, lwd = 3, add = TRUE) |
| 155 | + gdalraster::plot_geom(fia_poly, border = border_col, lwd = subp_border_lwd, |
| 156 | + add = TRUE) |
133 | 157 |
|
134 | 158 | invisible(tree_list) |
135 | 159 | } |
0 commit comments