knitr::opts_chunk$set(echo = FALSE, message = FALSE)
knitr::opts_knit$set(root.dir = "../")
#load packages
library("tidyverse")
#library("furrr")#for parallel processing
library("DBI")# also needs RMySQL installed
#plan(multiprocess, workers = 2)
source("start_here.R")
#merge cover and subturf
subturf_cover_thin <- full_join(cover.thin, subturf.thin) %>% 
    mutate(problems = case_when(
      is.na(cover) ~ "no cover",
      is.na(subturf) ~ "no subturf",
      TRUE ~ "OK"
    ))

subturf_cover_thin %>% count(problems)
tibble(subturf = 1:25) %>% 
ggplot(aes(x = (subturf - 1) %% 5, y = 5 - ((subturf - 1) %/% 5), label = subturf)) +
    geom_tile(colour = "grey60", fill = "grey90", show.legend = FALSE, alpha = .8) +
  geom_text() +
  scale_x_continuous(expand = c(0, 0)) +  
  scale_y_continuous(expand = c(0, 0)) +
  coord_equal() +
  theme(axis.text = element_blank(), axis.ticks = element_blank())

Subturf maps

x <- subturf_cover_thin %>% 
  arrange(destSiteID, TTtreat, turfID) %>% 
  group_by(turfID) %>% 
  nest(.key = "data") %>% 
  {pmap(
    .l = list(d = .$data, turfID = .$turfID),
    .f = function(d, turfID){
  g <- ggplot(d, aes(x = (subturf - 1) %% 5, y = 5 - ((subturf - 1) %/% 5), fill = cover)) +
    geom_tile(colour = "grey60") +
    facet_grid(species ~ year) +
    ggtitle(paste0("Plot ", turfID, "; destination ", d$destSiteID)) +
    scale_x_continuous(expand = c(0, 0)) +
    scale_y_continuous(expand = c(0, 0)) +
    scale_fill_distiller(type = "seq", palette = "Greens", direction = 1) + 
    theme_bw() +
    theme(
      axis.text = element_blank(), 
      axis.title = element_blank(), 
      axis.ticks = element_blank(),
      strip.text.y = element_text(angle = 0), 
      panel.spacing = unit(2, units = "pt")
      )
    })} %>% 
  walk(print)


richardjtelford/seedclimComm documentation built on March 5, 2023, 11:38 p.m.