Skip to contents

After applying the divide_plot() function, this function summarises with any defined function the desired tree metric by sub-plot and displays the plot representation.

Usage

subplot_summary(
  subplots,
  value = NULL,
  AGB_simu = NULL,
  draw_plot = TRUE,
  per_ha = TRUE,
  fun = sum,
  ref_raster = NULL,
  raster_fun = mean,
  ...
)

Arguments

subplots

output of the divide_plot() function

value

(if AGB_simu is not provided) a character indicating the column in subplots$tree_data to be summarised (or character vector to summarise several metrics at once)

AGB_simu

(if value is not provided) a n x m matrix containing individual AGB where n is the number of tree and m is the number of monte carlo simulation. Typically, the output '$AGB_simu' of the AGBmonteCarlo() function.

draw_plot

a logical indicating whether the plot design should be displayed

per_ha

a logical indicating whether the metric summary should be per hectare (or, if summarising several metrics at once: a logical vector corresponding to each metric (see examples))

fun

the function to be applied on tree metric of each subplot (or, if summarising several metrics at once: a list of functions named according to each metric (see examples))

ref_raster

A SpatRaster object from terra package, typically a chm raster created from LiDAR data. Note that in the case of a multiple attributes raster, only the first variable "z" will be summarised.

raster_fun

the function (or a list of functions) to be applied on raster values of each subplot.

...

optional arguments to fun

Value

If 'value' is provided, a list containing the following elements:

  • tree_summary : a summary of the metric per subplot

  • polygon : an sf object : simple feature collection of the subplot's polygon

  • plot_design : a ggplot object (or a list of ggplot objects) that can easily be modified

If 'AGB_simu' is provided, a data.table containing a summary of the metric(s) per subplot and per simulation.

Author

Arthur Bailly

Examples

# One plot with repeated measurements of each corner
data("NouraguesPlot201")
data("NouraguesTrees")
check_plot201 <- check_plot_coord(
  corner_data = NouraguesPlot201,
  proj_coord = c("Xutm","Yutm"), rel_coord = c("Xfield","Yfield"),
  trust_GPS_corners = TRUE, draw_plot = FALSE)
subplots_201 <- suppressWarnings(
  divide_plot(
    corner_data = check_plot201$corner_coord, 
    rel_coord = c("x_rel","y_rel"), proj_coord = c("x_proj","y_proj"),
    grid_size = 50,
    tree_data =  NouraguesTrees[NouraguesTrees$Plot == 201,],
    tree_coords = c("Xfield","Yfield")))
# Sum summary (by default) of diameter
subplots_201_sum <- subplot_summary(subplots_201 , value = "D", draw_plot = FALSE)
#> [1] "Creating sf_polygons for each subplot..."
subplots_201_sum$tree_summary
#>    subplot_ID D_sum_per_ha
#> 1 subplot_0_0     10656.19
#> 2 subplot_0_1     10708.82
#> 3 subplot_1_0     12103.82
#> 4 subplot_1_1     12972.33
subplots_201_sum$polygon
#> Key: <subplot_ID>
#>     subplot_ID D_sum_per_ha             sf_subplot_polygon
#>         <char>        <num>                  <sfc_POLYGON>
#> 1: subplot_0_0     10656.19 POLYGON ((313005.7 451723.2...
#> 2: subplot_0_1     10708.82 POLYGON ((313053.1 451694.5...
#> 3: subplot_1_0     12103.82 POLYGON ((312981.3 451676.7...
#> 4: subplot_1_1     12972.33 POLYGON ((313028.4 451650.5...
# \donttest{
  subplots_201_sum$plot_design

# }
# 9th quantile summary (for example) of diameter
subplots_201_quant <- subplot_summary(subplots_201 , value = "D", draw_plot = FALSE,
                                      fun = quantile, probs=0.9)
#> [1] "Creating sf_polygons for each subplot..."
  

# Dealing with multiple plots
if (FALSE) { # \dontrun{
  data("NouraguesCoords")
  nouragues_subplots <- suppressWarnings(
  divide_plot(
     corner_data = NouraguesCoords,
    rel_coord = c("Xfield","Yfield"), proj_coord = c("Xutm","Yutm"),
    corner_plot_ID = "Plot",
    grid_size = 50,
    tree_data = NouraguesTrees, tree_coords =  c("Xfield","Yfield"),
    tree_plot_ID = "Plot"))
  # Sum summary (by default)
  nouragues_sum <- subplot_summary(nouragues_subplots , value = "D", draw_plot = FALSE)
  nouragues_sum$tree_summary
  nouragues_sum$plot_design
} # }

if (FALSE) { # \dontrun{
  data("NouraguesCoords")
  nouragues_subplots <- suppressWarnings(
  divide_plot(
     corner_data = NouraguesCoords,
    rel_coord = c("Xfield","Yfield"), proj_coord = c("Xutm","Yutm"),
    corner_plot_ID = "Plot",
    grid_size = 50,
    tree_data = NouraguesTrees, tree_coords =  c("Xfield","Yfield"),
    tree_plot_ID = "Plot"))
  # Sum summary (by default)
  nouragues_mult <- subplot_summary(nouragues_subplots , 
                                   value = c("D","D","x_rel"),
                                   fun = list(D=sum,D=mean,x_rel=mean),
                                   per_ha = c(T,F,F),
                                   draw_plot = FALSE)
  nouragues_mult$tree_summary
  nouragues_mult$plot_design$`201`[[1]]
  nouragues_mult$plot_design$`201`[[2]]
  nouragues_mult$plot_design$`201`[[3]]
} # }