-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy path07_Plots_annual.Rmd
93 lines (70 loc) · 2.3 KB
/
07_Plots_annual.Rmd
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
---
title: "07 Plots of annual data"
output:
html_document:
keep_md: true
toc: true
toc_depth: 3
toc_float: true
code_folding: hide
df_print: paged
---
Mass production of time series plots including Theil-Sen regression line
* Uses library 'openair' for plots
Plots are saved in folder [Figures_07](Figures_07)
Note: plotting uses a file [07_Plotdata.csv](07_Plotdata.csv) (manually made in Excel) to add y labels; this file can be extedned to also included headers to be added to each plot
## 0. Libraries
```{r}
library(tidyverse)
library(readxl)
library(broom)
library(lubridate)
install.packages("openair")
library(openair)
# library(pander)
```
## 1. Data
```{r}
dat_a <- read.csv("Data_produced/06_dat_a.csv")
dat_q <- read.csv("Data_produced/06_dat_q.csv")
```
## 2. Test plot
```{r}
varname <- "Dinoflagellater_med"
varname <- "Tetthet_Deep"
df <- dat_a %>% filter(Variable %in% varname)
df$date <- ymd(paste(df$Year, "07 01"))
# test plot
TheilSen(df, pollutant = "Value", main = varname, ylab = "Median during year",
shade = "transparent", pch = 21, cex = 1.2, data.col = "black", fill = "firebrick")
```
## 3. Define function for making and saving plots
```{r}
# write.table(tibble(unique(dat_a$Variable)), "clipboard", row.names = FALSE, quote = FALSE)
# plotdata <- read_xls("07_Plotdata.xlsx", sheet = 1)
plotdata <- read.csv2("07_Plotdata.csv", stringsAsFactors = FALSE)
TheilSen_save <- function(varname, ylabel){
df <- dat_a %>% filter(Variable %in% varname)
df$date <- ymd(paste(df$Year, "07 01"))
png(sprintf("Figures_07/Annual_timeseries_%s.png", varname), width = 15, height = 10, units = 'cm',
res = 300, type="cairo", antialias="default")
TheilSen(df, pollutant = "Value", main = varname, ylab = ylabel,
shade = "transparent", pch = 21, cex = 1.2, data.col = "black", fill = "firebrick")
dev.off()
}
# TheilSen_save("Flagellater_med", "Density")
# i <- 73
# i <- 1
# TheilSen_save(plotdata[i,"Variable"], plotdata[i, "Ylabel"])
```
## 4. Actually produce plots (takes perhaps 10-15 minutes)
Set 'produce_plots <- TRUE' in order to actually produce plots
```{r}
produce_plots <- FALSE
if (produce_plots){
for (i in 1:nrow(plotdata)){
TheilSen_save(plotdata[i,"Variable"], plotdata[i, "Ylabel"])
Sys.sleep(2)
}
}
```