-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path4f_Fig4_HD.R
106 lines (93 loc) · 4.81 KB
/
4f_Fig4_HD.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
# NO LONGER RUN THIS VERSION
# Package ID: knb-lter-ntl.88.30 Cataloging System:https://pasta.edirepository.org.
# Data set title: North Temperate Lakes LTER: Phytoplankton - Madison Lakes Area 1995 - current.
# Data set creator: John Magnuson - University of Wisconsin
# Data set creator: Stephen Carpenter - University of Wisconsin
# Data set creator: Emily Stanley - University of Wisconsin
# Contact: NTL Information Manager - University of Wisconsin - [email protected]
# Stylesheet v2.11 for metadata conversion into program: John H. Porter, Univ. Virginia, [email protected]
library(lubridate)
library(tidyverse)
# download ice data
inUrl1 <- "https://pasta.lternet.edu/package/data/eml/knb-lter-ntl/33/35/f5bc02452cafcd461c49bd7429d8b40c"
infile1 <- tempfile()
try(download.file(inUrl1,infile1,method="curl"))
ice.df <-read_csv(infile1)
ice.df2 = ice.df |> filter(lakeid == 'ME') |>
mutate(ice_on = ymd(ice_on), ice_off = ymd(ice_off)) |>
select(year4, ice_on, ice_off) |>
filter(year4 >= 1994) |>
mutate(year4 = year(ice_off))
# download phyto data
inUrl1 <- "https://pasta.lternet.edu/package/data/eml/knb-lter-ntl/88/30/f2de15b2fff6ae962a04c150c0a1c510"
infile1 <- tempfile()
try(download.file(inUrl1,infile1,method="curl"))
phyto.df <- read_csv(infile1) |>
filter(lakeid == 'ME') |>
filter(cells_per_ml > 0) |>
select(year4, sampledate, depth_range, division, biomass_conc) |>
mutate(division = if_else(division %in% c('Euglenophyta','Haptophyta','Miscellaneous','Xanthophyta'), 'other', division))
# load stratification data
straton = read_csv('data_processed/stratification_start.csv') |>
mutate(straton = `year<-`(linear, year)) |>
select(year4 = year, straton)
stratoff = read_csv('data_processed/stratification_end.csv') |>
mutate(stratoff = `year<-`(linear, year)) |>
select(year4 = year, stratoff)
# Join data sets
phyto.join = phyto.df |>
group_by(sampledate, year4, depth_range, division) |>
summarise(biomass_conc = sum(biomass_conc, na.rm = T)) |>
left_join(ice.df2) |>
left_join(straton) |>
left_join(stratoff) |>
mutate(season = case_when(sampledate < ice_off ~ 'ice',
sampledate > ice_off & sampledate < straton ~ 'spring',
sampledate > straton & sampledate < stratoff ~ 'stratified',
sampledate > stratoff ~ 'fall')) |>
mutate(season = factor(season, levels = c('ice', 'spring', 'stratified', 'fall'))) |>
mutate(division = factor(division, levels = c('Bacillariophyta','Cryptophyta','Cyanophyta','Chlorophyta',
'Chrysophyta','Pyrrhophyta','other'))) |>
group_by(season, year4, depth_range, division) |>
summarise(biomass_conc = mean(biomass_conc, na.rm = T)) |>
# mutate(division = fct_relevel(division, "other", after = Inf)) |>
filter(!is.na(season))
season.names = c('ice' = 'Ice', 'spring' = 'Spring Mixed','stratified' = 'Stratified','fall' = 'Fall Mixed')
ggplot(phyto.join |> filter (depth_range == '0-8m', year4 > 1994)) +
geom_col(aes(x = year4, y = biomass_conc, fill = division), width = 0.8) +
geom_vline(aes(xintercept = 2009.5), linetype = 2) +
scale_fill_manual(values = c('#9a713e', '#f1635c', '#4ea5d7', '#76b88a', '#ffa98f', '#c6eb55', 'grey50'), name = 'Division') +
facet_wrap(~season, ncol = 1, labeller = as_labeller(season.names) ) +
ylab("Mean Phytoplankton Biomass"~(mg~L^-1)) +
theme_bw(base_size = 9) +
theme(axis.title.x = element_blank(),
strip.background = element_blank(),
strip.text = element_text(size = 9, face = "bold", hjust = 0, margin = margin(0, 0, 0, 0, "pt")))
ggsave('figs_publication/Fig4_HD.png', dpi = 500, units = 'in', width = 6.5, height = 5)
# p3 = ggplot(phyto.join |> filter (depth_range == '0-8m', year4 > 1994)) +
# geom_col(aes(x = year4, y = biomass_conc, fill = division), width = 0.8) +
# geom_vline(aes(xintercept = 2009.5), linetype = 2) +
# scale_fill_manual(values = c('#9a713e', '#f1635c', '#4ea5d7', '#76b88a', '#ffa98f', '#c6eb55', 'grey50'), name = 'Division') +
# facet_wrap(~season, ncol = 2, labeller = as_labeller(season.names) ) +
# ylab("Mean Phytoplankton Biomass"~(mg~L^-1)) +
# theme_bw(base_size = 9) +
# theme(axis.title.x = element_blank(),
# legend.position = 'bottom',
# strip.background = element_blank(),
# legend.key.size = unit(0.2, "cm"),
# strip.text = element_text(size = 9, face = "bold", hjust = 0, margin = margin(0, 0, 0, 0, "pt"))) +
# guides(fill = guide_legend(nrow = 1))
#
# layout <- "
# AAAB
# AAAB
# CCCC
# CCCC
# CCCC
# "
#
# p1 + p2 + p3 + plot_layout(design = layout) +
# plot_annotation(tag_levels = 'A', tag_suffix = ')') &
# theme(plot.tag = element_text(size = 8))
# ggsave('figs_publication/Fig45_HD.png', dpi = 500, units = 'in', width = 6.5, height = 5.5)
#