-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplot_Rollmean.R
More file actions
140 lines (118 loc) · 5.28 KB
/
plot_Rollmean.R
File metadata and controls
140 lines (118 loc) · 5.28 KB
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
134
135
136
137
138
139
140
library(tidyverse)
library(here)
library(lubridate)
library(zoo)
# data from
# http://www.bom.gov.au/climate/data/index.shtml
lst <- list.files(here("values"), pattern = "precip")
i <- 1
for (i in 1:length(lst)){
loc <- str_split_fixed(lst[i], "_", 2)[,2]
df <- readRDS(here("values", lst[i])) %>%
mutate(date = ymd(paste0(str_sub(date, end = 4), "-",
str_sub(date, start = 5, end = 6), "-01"))) %>%
rename(rain = mean) %>%
group_by(date) %>%
summarise(rain = sum(rain)) %>%
filter(date > ymd("1910-01-01"))
period <- 1
df <- df %>% #bind_rows(df.sp, df.da) %>%
#filter(date > ymd("1000-01-01") & loc == "Steep Point") %>%
#dplyr::select(-Year) %>%
ungroup()%>%
mutate(rmean = rollmean(rain, k = period * 12, fill = NA, align = 'right'))
df.min <- df[which(df$rmean == min(df$rmean, na.rm = TRUE)), ]
df.min.p <- filter(df, date <= df.min$date[nrow(df.min)] & date > df.min$date[nrow(df.min)] - 365, )
df.g <- df %>% mutate(Year = year(date)) %>%
group_by(Year) %>%
summarise(y.rain = sum(rain))
mean(df.g$y.rain)
sum(df.min.p$rain)
ggplot(df, aes(date, rain))+
geom_col()+
geom_line(aes(y=rmean), col = "red", size = 1) +
labs(y = "Monthly Rainfall (mm)", x = "Date",
title = paste0(loc, ": ", min(df$date), " to ", max(df$date)),
subtitle = paste0("Lowest 12 months of rainfall, ",
df.min.p$date[1], " to ", df.min.p$date[12], " = ", round(sum(df.min.p$rain), 1), " mm\n",
"Annual mean = ", round(mean(df.g$y.rain),1), " mm"),
caption = "12 month running mean in red\n Source: Bureau of Meteorology")+
#coord_cartesian(ylim = c(0, 200))+
theme_bw()
ggsave(here("graphs", paste0(loc, "_", max(df$date),".jpg" )), width = 7, height = 5)
#write.csv(df, here("tmp.csv"))
}
################################################################
lst <- list.files(here("values"), pattern = "tmax-mean")
i <- 1
for (i in 1:length(lst)){
loc <- str_split_fixed(lst[i], "_", 2)[,2]
df <- readRDS(here("values", lst[i])) %>%
mutate(date = ymd(paste0(str_sub(date, end = 4), "-",
str_sub(date, start = 5, end = 6), "-01"))) %>%
rename(tmax = mean) %>%
group_by(date) %>%
summarise(tmax = mean(tmax)) %>%
filter(date > ymd("1910-01-01"))
period <- 1
df <- df %>% #bind_rows(df.sp, df.da) %>%
#filter(date > ymd("1000-01-01") & loc == "Steep Point") %>%
#dplyr::select(-Year) %>%
ungroup()%>%
mutate(rmean = rollmean(tmax, k = period * 12, fill = NA, align = 'right'))
df.min <- df[which(df$rmean == max(df$rmean, na.rm = TRUE)), ]
df.min.p <- filter(df, date <= df.min$date[nrow(df.min)] & date > df.min$date[nrow(df.min)] - 365, )
df.g <- df %>% mutate(Year = year(date)) %>%
group_by(Year) %>%
summarise(y.tmax = mean(tmax))
ggplot(df, aes(date, tmax))+
geom_col()+
geom_line(aes(y=rmean), col = "red", size = 1) +
labs(y = "Monthly Rainfall (mm)", x = "Date",
title = paste0(loc, ": ", min(df$date), " to ", max(df$date)),
subtitle = paste0("Highest 12 months of temperature, ",
df.min.p$date[1], " to ", df.min.p$date[12], " = ", round(mean(df.min.p$tmax), 1), " \n",
"Annual mean = ", round(mean(df.g$y.tmax),1), " "),
caption = "12 month running mean in red\n Source: Bureau of Meteorology")+
coord_cartesian(ylim = c(10, 32))+
theme_bw()
ggsave(here("graphs", paste0(loc, "_tmax_", max(df$date),".jpg" )), width = 7, height = 5)
#write.csv(df, here("tmp.csv"))
}
################################################################
lst <- list.files(here("values"), pattern = "vapourpres15")
i <- 1
for (i in 1:length(lst)){
loc <- str_split_fixed(lst[i], "_", 2)[,2]
df <- readRDS(here("values", lst[i])) %>%
mutate(date = ymd(paste0(str_sub(date, end = 4), "-",
str_sub(date, start = 5, end = 6), "-01"))) %>%
rename(vpd = mean) %>%
group_by(date) %>%
summarise(vpd = mean(vpd)) %>%
filter(date > ymd("1910-01-01"))
period <- 1
df <- df %>% #bind_rows(df.sp, df.da) %>%
#filter(date > ymd("1000-01-01") & loc == "Steep Point") %>%
#dplyr::select(-Year) %>%
ungroup()%>%
mutate(rmean = rollmean(vpd, k = period * 12, fill = NA, align = 'right'))
df.min <- df[which(df$rmean == max(df$rmean, na.rm = TRUE)), ]
df.min.p <- filter(df, date <= df.min$date[nrow(df.min)] & date > df.min$date[nrow(df.min)] - 365, )
df.g <- df %>% mutate(Year = year(date)) %>%
group_by(Year) %>%
summarise(y.vpd = mean(vpd))
ggplot(df, aes(date, vpd))+
geom_col()+
geom_line(aes(y=rmean), col = "red", size = 1) +
labs(y = "Vapor pressure", x = "Date",
title = paste0(loc, ": ", min(df$date), " to ", max(df$date)),
subtitle = paste0("Highest 12 months of vpd, ",
df.min.p$date[1], " to ", df.min.p$date[12], " = ", round(mean(df.min.p$vpd), 1), " \n",
"Annual mean = ", round(mean(df.g$y.vpd),1), " "),
caption = "12 month running mean in red\n Source: Bureau of Meteorology")+
coord_cartesian(ylim = c(8, 18))+
theme_bw()
ggsave(here("graphs", paste0(loc, "_vpd_", max(df$date),".jpg" )), width = 7, height = 5)
#write.csv(df, here("tmp.csv"))
}