Compiled 2020-12-17 13:07:30

knitr::opts_chunk$set(echo = TRUE, warning = F, message = F, fig.path = 'figs/')

library(tidyverse)
library(lubridate)
library(gghalves)
library(patchwork)
library(colorspace)
library(extrafont)

data(oysdat)
data(sitdat)

# fml <- "CMU Serif"
fml <- "serif"
col <- scales::alpha('grey', 0.2)
colfct <- sequential_hcl(3, 'Batlow')

dat <- oysdat %>% 
  left_join(sitdat, by = 'id') %>% 
  mutate(
    age = case_when(
      inst_year >= 2018 ~ 'young', 
      inst_year < 2018 & inst_year >= 2015 ~ 'moderate', 
      inst_year < 2015 ~ 'old'
    ), 
    age = factor(age, levels = c('young', 'moderate', 'old')), 
    inst_year = case_when(
      is.na(inst_year) ~ 'unk', 
      T ~ as.character(inst_year)
    )
  ) %>% 
  filter(!is.na(site)) %>% 
  filter(!is.na(type))

# base theme
pthm <- theme_bw(base_family = fml) + 
  theme(
    legend.position = 'top',  
    panel.grid.major.x = element_blank(), 
    panel.grid.minor.x = element_blank(), 
    panel.grid.minor.y = element_blank(), 
    strip.placement = 'outside', 
    strip.background = element_blank(), 
    axis.title.x = element_blank(), 
    axis.ticks.x = element_line(), 
    axis.text.x = element_text(angle = 45, size = 8, hjust = 1), 
    legend.title = element_blank()
  )
# base theme
pthm2 <- theme_bw(base_family = fml) + 
  theme(
    legend.position = 'top',
    strip.placement = 'outside', 
    strip.background = element_blank(),  
    legend.title = element_blank()
  )

1 Figures

1.1 % live oysters

yval <- 'live_per'
ylab <- '% live oysters'
cplab <- 'Percent live oysters'
flnm <- yval

p <- ggplot(dat, aes_string(x = 'site', y = yval)) + 
  geom_half_point_panel(aes(fill = age), transformation = position_jitter(width = 1, height = 0), alpha = 0.7, pch = 21, size = 2) + 
  geom_half_violin(colour = 'black', draw_quantiles = 0.5, fill = col) +
  scale_fill_manual(values = colfct) +
  facet_grid(~type, scales = 'free_x', space = 'free_x') + 
  pthm + 
  labs(
    y = ylab
  ) + 
  guides(fill = guide_legend(nrow = 1))
  
jpeg(paste0('figs/', flnm, '1.jpg'), height = 4, width = 9, units = 'in', res = 300, family = fml)
print(p)
dev.off()
knitr::include_graphics(paste0('figs/', flnm, '1.jpg'))
Percent live oysters __within reef type and between site__. The left half of values show a density histogram and the right half shows percent live oysters for a plot at each site.

Figure 1.1: Percent live oysters within reef type and between site. The left half of values show a density histogram and the right half shows percent live oysters for a plot at each site.

p <- ggplot(dat, aes_string(x = 'type', y = yval)) + 
  geom_half_point_panel(aes(fill = age), transformation = position_jitter(width = 1, height = 0), alpha = 0.7, pch = 21, size = 2) + 
  geom_half_violin(colour = 'black', draw_quantiles = 0.5, fill = col) +
  scale_fill_manual(values = colfct) +
  facet_grid(~site, scales = 'free_x', space = 'free_x') + 
  pthm + 
  labs(
    y = ylab
  ) + 
  guides(fill = guide_legend(nrow = 1))
  
jpeg(paste0('figs/', flnm, '2.jpg'), height = 4, width = 9, units = 'in', res = 300, family = fml)
print(p)
dev.off()
knitr::include_graphics(paste0('figs/', flnm, '2.jpg'))