-
Notifications
You must be signed in to change notification settings - Fork 0
/
wrangling_SSTdata.R
134 lines (103 loc) · 6.47 KB
/
wrangling_SSTdata.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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
## ----include=FALSE---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
knitr::opts_chunk$set(echo = TRUE)
#rm(list=ls()) # Clear out environment if necessary
source("code/packages.R")
source("code/extras.R")
getwd()
## --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
AMM_SST <-
read_excel('data/SST/osprey_climatology.xlsx', skip = 1) %>%
mutate(Month = as_date(paste(2021, Month, 15, sep = "-"))) %>% # Use the middle/15th day of the month for plotting later
bind_rows(read_excel('data/SST/osprey_climatology.xlsx', skip = 1) %>%
mutate(Month = as_date(paste(2022, Month, 15, sep = "-")))) %>%
filter(as_date(Month) >= as_date("2021-10-01"),
as_date(Month) <= as_date("2022-10-31")) %>%
rename(AMM = SST)
## --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
AMM_SST %>%
ggplot() +
geom_line(aes(x = Month, y = AMM)) +
geom_point(aes(x = Month, y = AMM)) +
theme_bjc() +
scale_x_date(date_breaks = "1 month", date_labels = '%b') +
theme(axis.text.x = element_text(angle = 30, vjust = 0.8)) +
xlab("Month of year") +
ylab("Averaged monthly mean SST \n (°C)")
## ----message = FALSE, warning = FALSE--------------------------------------------------------------------------------------------------------------------------------------------------------------------------
SST <- read_csv('data/SST/sst_geopolar_osprey_19850101-20230430.csv', skip = 5) %>%
mutate(date = ymd(dmy(Date)), .keep = "unused", .before = "SST") %>%
filter(#SST >0,
as_date(date) >= as_date("2021-10-01"),
as_date(date) <= as_date("2022-10-31"))
save(SST, file = "data/RData/SST.Rdata")
## ----message=FALSE, warning=FALSE------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
#SST_plot <-
ggplot() +
geom_line(aes(x = date, y = SST), data = SST, colour = "black") +
geom_line(aes(x = date, y = SST_N), data = SST, colour = "blue") +
geom_line(aes(x = date, y = SST_S), data = SST, colour = "orange") +
geom_line(aes(x = date, y = SST_E), data = SST, colour = "green4") +
geom_line(aes(x = date, y = SST_W), data = SST, colour = "yellow") +
theme_bjc() +
scale_x_date(date_breaks = "1 month", date_labels = '%b-%y') +
theme(axis.text.x = element_text(angle = 30, vjust = 0.8)) +
xlab("Month/year") +
ylab("Temp (°C)")
#SST_plot
#ggsave(filename = "output/SSTcomps.png", SST_plot)
## --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
ggplot() +
geom_line(aes(x = Month, y = AMM), data = AMM_SST, col = "blue4") +
geom_point(aes(x = Month, y = AMM), data = AMM_SST, col = "blue4", alpha =.5, size = 1) +
geom_line(aes(x = date, y = SST), data = SST, colour = "black") +
theme_bjc() +
scale_x_date(date_breaks = "1 month", date_labels = '%b-%y') +
#theme(axis.text.x = element_blank()) +
xlab("Month") +
ylab("Temp (°C)")
## --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
study_MM <-
SST %>%
mutate(month = month(date, label = TRUE),
year = year(date)) %>%
mutate(Month = as_date(paste(year, month, 15, sep = "-"))) %>% # Use the middle/15th day of the month for plotting later
group_by(year, Month) %>%
summarise(MM = mean(SST))%>%
left_join(AMM_SST) %>%
mutate(Month_diff = MM - AMM)
study_MM
## ----fig.width = 110/25.4, fig.height = 70/25.4----------------------------------------------------------------------------------------------------------------------------------------------------------------
SSTvAMMplot <-
ggplot() +
geom_hline(yintercept = 28.69, colour = "grey60") + # Plot the MMM
geom_line(aes(x = date, y = SST), data = SST, colour = "grey20") +
geom_line(aes(x = Month, y = AMM), data = AMM_SST, colour = "dodgerblue") +
geom_point(aes(x = Month, y = AMM), data = AMM_SST, fill = "dodgerblue", colour = "black",
stroke = 0.8, pch = 22, alpha = 0.9, size = 2) +
geom_line(aes(x = Month, y = MM), data = study_MM, colour = "firebrick") +
geom_point(aes(x = Month, y = MM), data = study_MM, fill = "firebrick", colour = "black",
stroke = 0.8, pch = 24, alpha = 0.9, size = 2) +
theme_bjc() +
scale_x_date(date_breaks = "1 month", date_labels = '%b-%y', limits = c(as_date("2021-10-14"), as_date("2022-10-16"))) +
theme(axis.text.x = element_text(size = 9, angle = 45, vjust = 1, hjust = 1)) +
theme(axis.text.y = element_text(size = 9)) +
theme(axis.title = element_text(size = 9)) +
xlab("Month/year") +
ylab("SST (°C)")
SSTvAMMplot
## --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
ggsave(filename = "output/SSTvAMMplot.pdf", SSTvAMMplot, width = 170, height = 100, units = "mm", dpi = 300)
## --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
SST %>%
filter(SST == max(SST))
SST %>%
filter(SST == min(SST))
## --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
study_MM %>%
ungroup() %>%
summarise_at(vars(MM),list(min = min, median=median, mean = mean, max = max))
study_MM %>%
ungroup() %>%
summarise_at(vars(AMM),list(min = min, median=median, mean = mean, max = max))
## --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
# END