forestgeo/fgeo.plot

Map distribution of quadrats in the field

Opened this issue · 8 comments

Map distribution of quadrats in the field

@

Basically, the “LINES” run perpendicular to the main valley/stream. And, LINE number is the y-coordinate of the quadrat coordinates: LINE “0” includes quadrats: 2400, 2300, 2200, to 0000 (running from the ridge top down the hill).

Sisira, I will print 5-10 hectares (LINE 0-9), and send them to you.

library(fgeo.tool)
library(fgeo.map)
library(bciex)
library(dplyr)
library(ggplot2)

elevation <- restructure_elev(bci_elevation)
census <- tibble::as.tibble(bci12s7mini)

# Map columns and lines from elevation data only

col_row <- elevation %>% 
  add_col_row() %>% 
  select(col, row, elev) %>% 
  filter(!is.na(col) & !is.na(row)) %>% 
  group_by(col, row) %>% 
  summarize(elev = mean(elev))

ggplot(col_row, aes(x = col, y = row, z = elev)) +
  geom_raster(aes(fill = elev)) +
  geom_hline(yintercept = seq(1.5, 24.5, 1)) +
  geom_vline(xintercept = seq(1.5, 24.5, 1)) +
  coord_fixed()



# Map columns and lines from viewfulltable

col_row <- sinharaja::sinh_vft %>% 
  purrr::set_names(tolower) %>% 
  select(px, py) %>% 
  rename(gx = px, gy = py) %>% 
  add_col_row() %>% 
  filter(!is.na(col) & !is.na(row))

ggplot(col_row, aes(x = col, y = row)) +
  geom_hline(yintercept = seq(1.5, 24.5, 1)) +
  geom_vline(xintercept = seq(1.5, 24.5, 1)) +
  scale_x_continuous(breaks = 1:25) +
  scale_y_continuous(breaks = 1:25) +
  coord_fixed()



# Map columns and lines from census

col_row <- yosemite::yosemite_f1_lao %>% 
  purrr::set_names(tolower) %>% 
  select(gx, gy) %>% 
  filter(!is.na(gx) & !is.na(gy)) %>% 
  filter(gx > 0, gy > 0) %>% 
  add_col_row() %>% 
  filter(!is.na(col) & !is.na(row))

ggplot(col_row, aes(x = col, y = row)) +
  geom_hline(yintercept = seq(1.5, 24.5, 1)) +
  geom_vline(xintercept = seq(1.5, 24.5, 1)) +
  scale_x_continuous(breaks = 1:25) +
  scale_y_continuous(breaks = 1:25) +
  coord_fixed()

Consider mapping col and row, and in opposite axes gx and gy.

This might be an even simpler approach

Inputs:

  • Max. number of columns
  • Max. number of rows

Use complete or expand (in base or tidyr) to find all the combinations of col and row.
Convert col row to gx gy at the center of each quadrat -- such a function seems not to exist yet*.
Map gx gy and layer text of col row at the top and right of the plot.

*

  • If it is a particular col, then the center of the entire col has a unique value of gx.
  • If it is a particular row, then the center of the entire col has a unique value of gy.
  • The intersection of each col and row has a unique value of gx and gy that gives the center of each quadrat.

Shameema's model

image

Draft: tibble gx and gy

library(tibble)
library(ggplot2)

gridsize = 20
plotdim = c(500, 500)
by = 20
xyjust = -0.5
size = 4


tibble_gx_gy <- function(plotdim = c(1000, 500), by = 20) {
  gx <- seq(0, plotdim[[1]], by = by)
  gy <- seq(0, plotdim[[2]], by = by)
  
  if (length(gx) > length(gy)) {
    gy <- rep_len(gy, length.out = length(gx))
  } else {
    gx <- rep_len(gx, length.out = length(gy))
  }
  tibble::tibble(gx = gx, gy = gy)
}

Draft: Map col and row

col_row <- tibble_gx_gy(plotdim = plotdim, by = by) %>% 
  fgeo.tool::add_col_row(gridsize = gridsize, plotdim = plotdim) %>% 
  dplyr::filter(!is.na(col) & !is.na(row))


max_x <- max0(col_row$gx)
max_y <- max0(col_row$gy)

ggplot(col_row, aes(x = gx, y = gy)) +
  geom_hline(yintercept = seq(0, max_y + gridsize, gridsize)) +
  geom_vline(xintercept = seq(0, max_x + gridsize, gridsize)) +
  scale_x_continuous(limits = c(0, max_x + gridsize)) +
  scale_y_continuous(limits = c(0, max_y + gridsize)) +
  coord_fixed() +
  geom_text(
    aes(y = max_y + gridsize, x = gx + gridsize/2, label = col), vjust = xyjust, size = size
  ) +
  geom_text(
    aes(x = max_x + gridsize, y = gy + gridsize/2, label = row), hjust = xyjust, size = size
  ) +
  theme_bw()