These functions add columns to position trees in a forest plot. They work
with ViewFullTable, tree and stem tables. From the input table, most
functions use only the gx
and gy
columns (or equivalent columns). The
exception is the function add_gxgy()
which inputs quadrat information. If
your data lacks some important column, an error message will inform you which
column is missing.
add_lxly(data, gridsize = 20, plotdim = NULL)
add_qxqy(data, gridsize = 20, plotdim = NULL)
add_index(data, gridsize = 20, plotdim = NULL)
add_col_row(data, gridsize = 20, plotdim = NULL)
add_hectindex(data, gridsize = 20, plotdim = NULL)
add_quad(data, gridsize = 20, plotdim = NULL, start = NULL, width = 2)
add_gxgy(data, gridsize = 20, start = 0)
A ForestGEO-like dataframe: A ViewFullTable, tree or stem table.
The gridsize of the census plot (commonly 20 m).
The global dimensions of the census plot (i.e. the
maximum possible values of gx
and gy
).
Defaults to label the first quadrat as "0101". Use 0
to
label it as "0000" instead.
Number; width to pad the labels of plot-columns and -rows.
For any given var
, a function add_var()
returns a modified
version of the input dataframe, with the additional variable(s) var
.
These functions are adapted from the CTFS R Package.
Other functions to add columns to dataframes:
add_status_tree()
,
add_subquad()
Other functions for ForestGEO data:
add_status_tree()
,
add_subquad()
Other functions for fgeo census:
add_status_tree()
,
guess_plotdim()
,
pick_drop
Other functions for fgeo vft:
add_status_tree()
,
add_subquad()
,
guess_plotdim()
,
pick_drop
# styler: off
x <- tribble(
~gx, ~gy,
0, 0,
50, 25,
999.9, 499.95,
1000, 500
)
# styler: on
# `gridsize` has a common default; `plotdim` is guessed from the data
add_lxly(x)
#> Guessing: plotdim = c(1000, 500)
#> * If guess is wrong, provide the correct argument `plotdim`
#> # A tibble: 4 × 4
#> gx gy lx ly
#> <dbl> <dbl> <dbl> <dbl>
#> 1 0 0 0 0
#> 2 50 25 10 5
#> 3 1000. 500. 19.9 19.9
#> 4 1000 500 NA NA
gridsize <- 20
plotdim <- c(1000, 500)
add_qxqy(x, gridsize, plotdim)
#> # A tibble: 4 × 4
#> gx gy QX QY
#> <dbl> <dbl> <dbl> <dbl>
#> 1 0 0 0 0
#> 2 50 25 10 5
#> 3 1000. 500. 19.9 19.9
#> 4 1000 500 NA NA
add_index(x, gridsize, plotdim)
#> # A tibble: 4 × 3
#> gx gy index
#> <dbl> <dbl> <dbl>
#> 1 0 0 1
#> 2 50 25 52
#> 3 1000. 500. 1250
#> 4 1000 500 NA
add_hectindex(x, gridsize, plotdim)
#> Warning: Some values of `gx` and/or `gy` lay at or beyond plot limits
#> # A tibble: 4 × 3
#> gx gy hectindex
#> <dbl> <dbl> <dbl>
#> 1 0 0 1
#> 2 50 25 1
#> 3 1000. 500. 50
#> 4 1000 500 56
add_quad(x, gridsize, plotdim)
#> # A tibble: 4 × 3
#> gx gy quad
#> <dbl> <dbl> <chr>
#> 1 0 0 0101
#> 2 50 25 0302
#> 3 1000. 500. 5025
#> 4 1000 500 NA
add_quad(x, gridsize, plotdim, start = 0)
#> # A tibble: 4 × 3
#> gx gy quad
#> <dbl> <dbl> <chr>
#> 1 0 0 0000
#> 2 50 25 0201
#> 3 1000. 500. 4924
#> 4 1000 500 NA
# `width` gives the nuber of digits to pad the label of plot-rows and
# plot-columns, e.g. 3 pads plot-rows with three zeros and plot-columns with
# an extra trhree zeros, resulting in a total of 6 zeros.
add_quad(x, gridsize, plotdim, start = 0, width = 3)
#> # A tibble: 4 × 3
#> gx gy quad
#> <dbl> <dbl> <chr>
#> 1 0 0 000000
#> 2 50 25 002001
#> 3 1000. 500. 049024
#> 4 1000 500 NA
add_col_row(x, gridsize, plotdim)
#> # A tibble: 4 × 4
#> gx gy col row
#> <dbl> <dbl> <chr> <chr>
#> 1 0 0 01 01
#> 2 50 25 03 02
#> 3 1000. 500. 50 25
#> 4 1000 500 NA NA
# From `quadrat` or `QuadratName` --------------------------------------
# styler: off
x <- tribble(
~QuadratName,
"0001",
"0011",
"0101",
"1001"
)
# styler: on
# Output `gx` and `gy` ---------------
add_gxgy(x)
#> QuadratName gx gy
#> 1 0001 0 20
#> 2 0011 0 220
#> 3 0101 20 20
#> 4 1001 200 20
assert_is_installed("fgeo.x")
# Warning: The data may already have `gx` and `gx` columns
gxgy <- add_gxgy(fgeo.x::tree5)
select(gxgy, matches("gx|gy"))
#> gx gy gx1 gy1
#> 1 138.68 425.26 140 440
#> 2 94.76 424.41 100 440
#> 3 61.31 495.73 80 500
#> 4 100.27 328.01 120 340
#> 5 53.84 73.81 60 80
#> 6 202.64 109.86 220 120
#> 7 172.45 14.73 180 20
#> 8 183.50 194.22 200 200
#> 9 191.04 131.80 200 140
#> 10 273.93 278.68 280 280
#> 11 216.39 261.34 220 280
#> 12 8.83 189.63 20 200
#> 13 267.28 370.88 280 380
#> 14 137.64 355.95 140 360
#> 15 120.05 216.51 140 220
#> 16 165.95 410.29 180 420
#> 17 56.67 267.22 60 280
#> 18 315.77 230.64 320 240
#> 19 79.74 22.76 80 40
#> 20 278.00 40.62 280 60
#> 21 113.97 182.33 120 200
#> 22 23.96 496.57 40 500
#> 23 145.93 217.68 160 220
#> 24 84.17 285.45 100 300
#> 25 246.90 354.20 260 360
#> 26 279.02 209.98 280 220
#> 27 152.55 425.55 160 440
#> 28 89.78 407.99 100 420
#> 29 112.79 426.00 120 440
#> 30 47.00 479.81 60 480
# Output `col` and `row` -------------
# Create columns `col` and `row` from `QuadratName` with `tidyr::separate()`
# The argument `sep` lets you separate `QuadratName` at any positon
if (FALSE) {
tidyr_is_installed <- requireNamespace("tidyr", quietly = TRUE)
stringr_is_installed <- requireNamespace("stringr", quietly = TRUE)
if (tidyr_is_installed && stringr_is_installed) {
library(tidyr)
library(stringr)
vft <- tibble(QuadratName = c("0001", "0011"))
vft
separate(
vft,
QuadratName,
into = c("col", "row"),
sep = 2
)
census <- select(fgeo.x::tree5, quadrat)
census
census$quadrat <- str_pad(census$quadrat, width = 4, pad = 0)
separate(
census,
quadrat,
into = c("col", "row"),
sep = 2,
remove = FALSE
)
}
}