Compiled 2023-02-24 14:25:13
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()
)
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'))
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'))
p <- ggplot(dat, aes_string(x = 'age', y = yval)) +
geom_half_point_panel(aes(fill = site), 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) +
facet_grid(~type, scales = 'free_x', space = 'free_x') +
pthm +
labs(
y = ylab
) +
guides(fill = guide_legend(nrow = 1))
jpeg(paste0('figs/', flnm, '3.jpg'), height = 4, width = 9, units = 'in', res = 300, family = fml)
print(p)
dev.off()
knitr::include_graphics(paste0('figs/', flnm, '3.jpg'))
p <- ggplot(dat, aes_string(x = 'type', y = yval)) +
geom_half_point_panel(aes(fill = site), 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) +
facet_grid(~age, scales = 'free_x', space = 'free_x') +
pthm +
labs(
y = ylab
) +
guides(fill = guide_legend(nrow = 1))
jpeg(paste0('figs/', flnm, '4.jpg'), height = 4, width = 9, units = 'in', res = 300, family = fml)
print(p)
dev.off()
knitr::include_graphics(paste0('figs/', flnm, '4.jpg'))
yval <- 'shell_total'
ylab <- 'Shell total (count)'
cplab <- 'Shell total (count)'
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'))
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'))
p <- ggplot(dat, aes_string(x = 'age', y = yval)) +
geom_half_point_panel(aes(fill = site), 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) +
facet_grid(~type, scales = 'free_x', space = 'free_x') +
pthm +
labs(
y = ylab
) +
guides(fill = guide_legend(nrow = 1))
jpeg(paste0('figs/', flnm, '3.jpg'), height = 4, width = 9, units = 'in', res = 300, family = fml)
print(p)
dev.off()
knitr::include_graphics(paste0('figs/', flnm, '3.jpg'))
p <- ggplot(dat, aes_string(x = 'type', y = yval)) +
geom_half_point_panel(aes(fill = site), 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) +
facet_grid(~age, scales = 'free_x', space = 'free_x') +
pthm +
labs(
y = ylab
) +
guides(fill = guide_legend(nrow = 1))
jpeg(paste0('figs/', flnm, '4.jpg'), height = 4, width = 9, units = 'in', res = 300, family = fml)
print(p)
dev.off()
knitr::include_graphics(paste0('figs/', flnm, '4.jpg'))
yval <- 'aveshell_mm'
ylab <- 'Shell length (mm)'
cplab <- 'Shell length (mm, average across plots)'
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'))
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'))
p <- ggplot(dat, aes_string(x = 'age', y = yval)) +
geom_half_point_panel(aes(fill = site), 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) +
facet_grid(~type, scales = 'free_x', space = 'free_x') +
pthm +
labs(
y = ylab
) +
guides(fill = guide_legend(nrow = 1))
jpeg(paste0('figs/', flnm, '3.jpg'), height = 4, width = 9, units = 'in', res = 300, family = fml)
print(p)
dev.off()
knitr::include_graphics(paste0('figs/', flnm, '3.jpg'))
p <- ggplot(dat, aes_string(x = 'type', y = yval)) +
geom_half_point_panel(aes(fill = site), 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) +
facet_grid(~age, scales = 'free_x', space = 'free_x') +
pthm +
labs(
y = ylab
) +
guides(fill = guide_legend(nrow = 1))
jpeg(paste0('figs/', flnm, '4.jpg'), height = 4, width = 9, units = 'in', res = 300, family = fml)
print(p)
dev.off()
knitr::include_graphics(paste0('figs/', flnm, '4.jpg'))
xvar <- 'shell_total'
yvar <- 'live_per'
xlab <- 'Shell total (count)'
ylab <- '% live oysters'
flnm <- 'livvstot'
cplab <- 'Percent live oysters vs total shell count'
p <- ggplot(dat, aes_string(x = xvar, y = yvar)) +
geom_point(aes(fill = age), alpha = 0.7, pch = 21, size = 2) +
scale_fill_manual(values = colfct) +
# stat_smooth() +
facet_grid(~type, scales = 'free_x') +
pthm2 +
labs(
y = ylab,
x = xlab
) +
guides(fill = guide_legend(nrow = 1))
jpeg(paste0('figs/', flnm, '1.jpg'), height = 3.5, width = 9, units = 'in', res = 300, family = fml)
print(p)
dev.off()
knitr::include_graphics(paste0('figs/', flnm, '1.jpg'))
p <- ggplot(dat, aes_string(x = xvar, y = yvar)) +
geom_point(aes(fill = type), alpha = 0.7, pch = 21, size = 2) +
# stat_smooth() +
facet_grid(~age, scales = 'free_x') +
pthm2 +
labs(
y = ylab,
x = xlab
) +
guides(fill = guide_legend(nrow = 1))
jpeg(paste0('figs/', flnm, '2.jpg'), height = 3.5, width = 9, units = 'in', res = 300, family = fml)
print(p)
dev.off()
knitr::include_graphics(paste0('figs/', flnm, '2.jpg'))
p <- ggplot(dat, aes_string(x = xvar, y = yvar)) +
geom_point(aes(fill = site), alpha = 0.7, pch = 21, size = 2) +
# stat_smooth() +
facet_grid(~type, scales = 'free_x') +
pthm2 +
labs(
y = ylab,
x = xlab
) +
guides(fill = guide_legend(nrow = 1))
jpeg(paste0('figs/', flnm, '3.jpg'), height = 3.5, width = 9, units = 'in', res = 300, family = fml)
print(p)
dev.off()
knitr::include_graphics(paste0('figs/', flnm, '3.jpg'))
p <- ggplot(dat, aes_string(x = xvar, y = yvar)) +
geom_point(aes(fill = type), alpha = 0.7, pch = 21, size = 2) +
# stat_smooth() +
facet_grid(~site, scales = 'free_x') +
pthm2 +
labs(
y = ylab,
x = xlab
) +
guides(fill = guide_legend(nrow = 1))
jpeg(paste0('figs/', flnm, '4.jpg'), height = 3.5, width = 9, units = 'in', res = 300, family = fml)
print(p)
dev.off()
knitr::include_graphics(paste0('figs/', flnm, '4.jpg'))
p <- ggplot(dat, aes_string(x = xvar, y = yvar)) +
geom_point(aes(fill = age), alpha = 0.7, pch = 21, size = 2) +
# stat_smooth() +
scale_fill_manual(values = colfct) +
facet_grid(~site, scales = 'free_x') +
pthm2 +
labs(
y = ylab,
x = xlab
) +
guides(fill = guide_legend(nrow = 1))
jpeg(paste0('figs/', flnm, '5.jpg'), height = 3.5, width = 9, units = 'in', res = 300, family = fml)
print(p)
dev.off()
knitr::include_graphics(paste0('figs/', flnm, '5.jpg'))
p <- ggplot(dat, aes_string(x = xvar, y = yvar)) +
geom_point(aes(fill = site), alpha = 0.7, pch = 21, size = 2) +
# stat_smooth() +
facet_grid(~age, scales = 'free_x') +
pthm2 +
labs(
y = ylab,
x = xlab
) +
guides(fill = guide_legend(nrow = 1))
jpeg(paste0('figs/', flnm, '6.jpg'), height = 3.5, width = 9, units = 'in', res = 300, family = fml)
print(p)
dev.off()
knitr::include_graphics(paste0('figs/', flnm, '6.jpg'))
xvar <- 'aveshell_mm'
yvar <- 'live_per'
xlab <- 'Shell length (mm)'
ylab <- '% live oysters'
flnm <- 'livvslen'
cplab <- 'Percent live oysters vs average shell length (mm)'
p <- ggplot(dat, aes_string(x = xvar, y = yvar)) +
geom_point(aes(fill = age), alpha = 0.7, pch = 21, size = 2) +
scale_fill_manual(values = colfct) +
# stat_smooth() +
facet_grid(~type, scales = 'free_x') +
pthm2 +
labs(
y = ylab,
x = xlab
) +
guides(fill = guide_legend(nrow = 1))
jpeg(paste0('figs/', flnm, '1.jpg'), height = 3.5, width = 9, units = 'in', res = 300, family = fml)
print(p)
dev.off()
knitr::include_graphics(paste0('figs/', flnm, '1.jpg'))
p <- ggplot(dat, aes_string(x = xvar, y = yvar)) +
geom_point(aes(fill = type), alpha = 0.7, pch = 21, size = 2) +
# stat_smooth() +
facet_grid(~age, scales = 'free_x') +
pthm2 +
labs(
y = ylab,
x = xlab
) +
guides(fill = guide_legend(nrow = 1))
jpeg(paste0('figs/', flnm, '2.jpg'), height = 3.5, width = 9, units = 'in', res = 300, family = fml)
print(p)
dev.off()
knitr::include_graphics(paste0('figs/', flnm, '2.jpg'))
p <- ggplot(dat, aes_string(x = xvar, y = yvar)) +
geom_point(aes(fill = site), alpha = 0.7, pch = 21, size = 2) +
# stat_smooth() +
facet_grid(~type, scales = 'free_x') +
pthm2 +
labs(
y = ylab,
x = xlab
) +
guides(fill = guide_legend(nrow = 1))
jpeg(paste0('figs/', flnm, '3.jpg'), height = 3.5, width = 9, units = 'in', res = 300, family = fml)
print(p)
dev.off()
knitr::include_graphics(paste0('figs/', flnm, '3.jpg'))
p <- ggplot(dat, aes_string(x = xvar, y = yvar)) +
geom_point(aes(fill = type), alpha = 0.7, pch = 21, size = 2) +
# stat_smooth() +
facet_grid(~site, scales = 'free_x') +
pthm2 +
labs(
y = ylab,
x = xlab
) +
guides(fill = guide_legend(nrow = 1))
jpeg(paste0('figs/', flnm, '4.jpg'), height = 3.5, width = 9, units = 'in', res = 300, family = fml)
print(p)
dev.off()
knitr::include_graphics(paste0('figs/', flnm, '4.jpg'))
p <- ggplot(dat, aes_string(x = xvar, y = yvar)) +
geom_point(aes(fill = age), alpha = 0.7, pch = 21, size = 2) +
# stat_smooth() +
scale_fill_manual(values = colfct) +
facet_grid(~site, scales = 'free_x') +
pthm2 +
labs(
y = ylab,
x = xlab
) +
guides(fill = guide_legend(nrow = 1))
jpeg(paste0('figs/', flnm, '5.jpg'), height = 3.5, width = 9, units = 'in', res = 300, family = fml)
print(p)
dev.off()
knitr::include_graphics(paste0('figs/', flnm, '5.jpg'))
p <- ggplot(dat, aes_string(x = xvar, y = yvar)) +
geom_point(aes(fill = site), alpha = 0.7, pch = 21, size = 2) +
# stat_smooth() +
facet_grid(~age, scales = 'free_x') +
pthm2 +
labs(
y = ylab,
x = xlab
) +
guides(fill = guide_legend(nrow = 1))
jpeg(paste0('figs/', flnm, '6.jpg'), height = 3.5, width = 9, units = 'in', res = 300, family = fml)
print(p)
dev.off()
knitr::include_graphics(paste0('figs/', flnm, '6.jpg'))
xvar <- 'shell_total'
yvar <- 'aveshell_mm'
xlab <- 'Shell total (count)'
ylab <- 'Shell length (mm)'
flnm <- 'lenvstot'
cplab <- 'Average shell length (mm) vs total shell count'
p <- ggplot(dat, aes_string(x = xvar, y = yvar)) +
geom_point(aes(fill = age), alpha = 0.7, pch = 21, size = 2) +
scale_fill_manual(values = colfct) +
# stat_smooth() +
facet_grid(~type, scales = 'free_x') +
pthm2 +
labs(
y = ylab,
x = xlab
) +
guides(fill = guide_legend(nrow = 1))
jpeg(paste0('figs/', flnm, '1.jpg'), height = 3.5, width = 9, units = 'in', res = 300, family = fml)
print(p)
dev.off()
knitr::include_graphics(paste0('figs/', flnm, '1.jpg'))
p <- ggplot(dat, aes_string(x = xvar, y = yvar)) +
geom_point(aes(fill = type), alpha = 0.7, pch = 21, size = 2) +
# stat_smooth() +
facet_grid(~age, scales = 'free_x') +
pthm2 +
labs(
y = ylab,
x = xlab
) +
guides(fill = guide_legend(nrow = 1))
jpeg(paste0('figs/', flnm, '2.jpg'), height = 3.5, width = 9, units = 'in', res = 300, family = fml)
print(p)
dev.off()
knitr::include_graphics(paste0('figs/', flnm, '2.jpg'))
p <- ggplot(dat, aes_string(x = xvar, y = yvar)) +
geom_point(aes(fill = site), alpha = 0.7, pch = 21, size = 2) +
# stat_smooth() +
facet_grid(~type, scales = 'free_x') +
pthm2 +
labs(
y = ylab,
x = xlab
) +
guides(fill = guide_legend(nrow = 1))
jpeg(paste0('figs/', flnm, '3.jpg'), height = 3.5, width = 9, units = 'in', res = 300, family = fml)
print(p)
dev.off()
knitr::include_graphics(paste0('figs/', flnm, '3.jpg'))
p <- ggplot(dat, aes_string(x = xvar, y = yvar)) +
geom_point(aes(fill = type), alpha = 0.7, pch = 21, size = 2) +
# stat_smooth() +
facet_grid(~site, scales = 'free_x') +
pthm2 +
labs(
y = ylab,
x = xlab
) +
guides(fill = guide_legend(nrow = 1))
jpeg(paste0('figs/', flnm, '4.jpg'), height = 3.5, width = 9, units = 'in', res = 300, family = fml)
print(p)
dev.off()
knitr::include_graphics(paste0('figs/', flnm, '4.jpg'))
p <- ggplot(dat, aes_string(x = xvar, y = yvar)) +
geom_point(aes(fill = age), alpha = 0.7, pch = 21, size = 2) +
# stat_smooth() +
scale_fill_manual(values = colfct) +
facet_grid(~site, scales = 'free_x') +
pthm2 +
labs(
y = ylab,
x = xlab
) +
guides(fill = guide_legend(nrow = 1))
jpeg(paste0('figs/', flnm, '5.jpg'), height = 3.5, width = 9, units = 'in', res = 300, family = fml)
print(p)
dev.off()
knitr::include_graphics(paste0('figs/', flnm, '5.jpg'))
p <- ggplot(dat, aes_string(x = xvar, y = yvar)) +
geom_point(aes(fill = site), alpha = 0.7, pch = 21, size = 2) +
# stat_smooth() +
facet_grid(~age, scales = 'free_x') +
pthm2 +
labs(
y = ylab,
x = xlab
) +
guides(fill = guide_legend(nrow = 1))
jpeg(paste0('figs/', flnm, '6.jpg'), height = 3.5, width = 9, units = 'in', res = 300, family = fml)
print(p)
dev.off()
knitr::include_graphics(paste0('figs/', flnm, '6.jpg'))