From ffd2feb14e4bc0f97668c607e018ffd4cf19ddc2 Mon Sep 17 00:00:00 2001 From: Kathryn Dumschott <k.dumschott@fz-juelich.de> Date: Wed, 26 Jul 2023 13:16:23 +0000 Subject: [PATCH] Upload New File --- workflows/environment_Rscript.R | 268 ++++++++++++++++++++++++++++++++ 1 file changed, 268 insertions(+) create mode 100644 workflows/environment_Rscript.R diff --git a/workflows/environment_Rscript.R b/workflows/environment_Rscript.R new file mode 100644 index 0000000..32e5946 --- /dev/null +++ b/workflows/environment_Rscript.R @@ -0,0 +1,268 @@ +#Load libraries + +library(dplyr) +library(ggplot2) +library(tidyverse) +library(lubridate) +library(ggpubr) + +#set working directory + +setwd("~/Documents/QuinoaDiveristy/FIELDTRIAL_publicationdata/FieldTrial_R/WeatherData") + +#import Night data + +Envdata_Night<- read.csv(file = "EnvironmentAll_night_values.csv", head = TRUE, sep = ' ') + + +#Calculate mean temp per night + +EnvdataNight_meantemp <- Envdata_Night %>% dplyr::group_by(das) %>% summarise(mean(AT_DEGC, na.rm = TRUE)) + +#import Day data + +Envdata_Day<- read.csv(file = "EnvironmentAll_Day_values.csv", head = TRUE, sep = ' ') + +#Calculate parameters +#Daily Max temp + +EnvdataDay_maxtemp <- Envdata_Day %>% dplyr::group_by(das) %>% summarise(max(AT_DEGC, na.rm = TRUE)) + +#Daily max VDP + +EnvdataDay_maxVPD <- Envdata_Day %>% dplyr::group_by(das) %>% summarise(max(VPD_kPa, na.rm = TRUE)) + +#Daily sum Radiation + +EnvdataDay_sumRAD <- Envdata_Day %>% dplyr::group_by(das) %>% summarise(sum(RAD_maxWM2, na.rm = TRUE)) + +#Rename columns + +#Daily max temp +colnames(EnvdataDay_maxtemp) + +names (EnvdataDay_maxtemp)[names(EnvdataDay_maxtemp) == "max(AT_DEGC, na.rm = TRUE)"] <- "Daily_MaxTemp" + +#Average night temp + +colnames(EnvdataNight_meantemp) + +names (EnvdataNight_meantemp)[names(EnvdataNight_meantemp) == "mean(AT_DEGC, na.rm = TRUE)"] <- "Nightly_MeanTemp" + +#Daily max VPD + +colnames(EnvdataDay_maxVPD) + +names (EnvdataDay_maxVPD)[names(EnvdataDay_maxVPD) == "max(VPD_kPa, na.rm = TRUE)"] <- "Daily_MaxVPD" + +#Daily sum RAD + +colnames(EnvdataDay_sumRAD) + +names (EnvdataDay_sumRAD)[names(EnvdataDay_sumRAD) == "sum(RAD_maxWM2, na.rm = TRUE)"] <- "Daily_sumRAD" + + +#Day and Night Temperatures + +Temps_all <- cbind(EnvdataDay_maxtemp$das, EnvdataDay_maxtemp$Daily_MaxTemp, + EnvdataNight_meantemp$Nightly_MeanTemp) +tempheadings <- c("das", "Daily_MaxTemp", "Nightly_MeanTemp") + +colnames(Temps_all) <- tempheadings + +Temps_DayNight <- as.data.frame(Temps_all) + +#Import SWC data + +SWCData<- read.csv(file = "~/Documents/QuinoaDiveristy/FIELDTRIAL_publicationdata/FieldTrial_R/WeatherData/SoilVWC_averages.csv", head = TRUE, sep = ' ') + +SWCData_WWmeanSWC <- SWCData %>% dplyr::group_by(das) %>% summarise(mean(soilVWC_WW)) + +SWCData_WDmeanSWC <- SWCData %>% dplyr::group_by(das) %>% summarise(mean(soilVWC_WD)) + + +#Soil Water Content data + +SWCData_meanVWC<- cbind(SWCData_WWmeanSWC$das, SWCData_WWmeanSWC$`mean(soilVWC_WW)`, SWCData_WDmeanSWC$`mean(soilVWC_WD)`) + +headings <-c("das", "SWC_WW", "SWC_WD") + +colnames(SWCData_meanVWC) <- headings + +SWCData_VWC <- as.data.frame(SWCData_meanVWC) + +class(SWCData_VWC[,3]) + +levels(SWCData_VWC) + +#reorder levels + + + +#line graphs + +#MaxTempLG <-EnvdataDay_maxtemp %>% + #ggplot(aes (x=das, y=Daily_MaxTemp)) + + # geom_line()+ + #theme(panel.grid = element_blank())+ + #labs(y= expression( Temperature~(degree*C)), + # title= "Daily Maximum Temperature") + +#MeanTempNightLG <-EnvdataNight_meantemp %>% +# ggplot(aes (x=das, y=Nightly_MeanTemp)) + +# geom_line()+ +# theme(panel.grid = element_blank())+ +# labs(y= expression( Temperature~(degree*C)), + # title= "Nightly Average Temperature") + + +temperatures <- rep(c("solid", "dashed"),2) + +AllTempsLG <- Temps_DayNight %>% + ggplot(aes (x=das)) + + annotate(geom = "rect", xmin=0, xmax=60, ymin=-Inf, ymax=Inf, + fill="palegreen2", alpha=0.5)+ + annotate(geom = "rect", xmin=60, xmax=105, ymin=-Inf, ymax=Inf, + fill="paleturquoise2", alpha=0.7)+ + annotate(geom = "rect", xmin=105, xmax=155, ymin=-Inf, ymax=Inf, + fill="gray80", alpha=0.5)+ + geom_line(aes(y=Daily_MaxTemp, linetype="Daily Maximum Temperature"))+ + geom_line(aes(y=Nightly_MeanTemp, linetype="Nightly Mean Temperature"))+ + labs(y= expression(Temperature~(degree*C)), + title= "Daily Maximum and Nightly Average Temperatures", + x= "Days after sowing")+ + theme(panel.grid = element_blank(), + panel.background = element_rect(fill= "White"), + panel.border = element_blank(), + axis.line = element_line(), + legend.title = element_blank(), + legend.position = c(0.5,1.10), + legend.direction ="horizontal", + legend.background= element_rect(fill=NA), + legend.key=element_blank()) + + scale_linetype_manual(values = temperatures) + + scale_x_continuous(expand = c(0,0))+ + scale_fill_discrete(name=NULL) + +AllTempsLG + +MaxVPDLG <-EnvdataDay_maxVPD %>% + ggplot(aes (x=das, y=Daily_MaxVPD)) + + annotate(geom = "rect", xmin=0, xmax=60, ymin=-Inf, ymax=Inf, + fill="palegreen2", alpha=0.5)+ + annotate(geom = "rect", xmin=60, xmax=105, ymin=-Inf, ymax=Inf, + fill="paleturquoise2", alpha=0.7)+ + annotate(geom = "rect", xmin=105, xmax=155, ymin=-Inf, ymax=Inf, + fill="gray80", alpha=0.5)+ + theme(panel.grid = element_blank())+ + geom_line()+ + labs(y= expression( VPD~(kPa) ), + title= "Daily Maximum Vapor-Pressure Deficit", x= "Days after sowing")+ + theme(panel.grid = element_blank(), + panel.background = element_rect(fill= "White"), + panel.border = element_blank(), + axis.line = element_line(), + legend.title = element_blank()) + + scale_x_continuous(expand = c(0,0))+ + scale_fill_discrete(name=NULL) + +MaxVPDLG + +SumRADLG <-EnvdataDay_sumRAD %>% + ggplot(aes (x=das, y=Daily_sumRAD)) + + annotate(geom = "rect", xmin=0, xmax=60, ymin=-Inf, ymax=Inf, + fill="palegreen2", alpha=0.5)+ + annotate(geom = "rect", xmin=60, xmax=105, ymin=-Inf, ymax=Inf, + fill="paleturquoise2", alpha=0.7)+ + annotate(geom = "rect", xmin=105, xmax=155, ymin=-Inf, ymax=Inf, + fill="gray80", alpha=0.5)+ + geom_line()+ + theme(panel.grid = element_blank())+ +labs(y= expression(Radiation~(W/m^2)), + title= "Daily Total Radiation", x= "Days after sowing")+ + theme(panel.grid = element_blank(), + panel.background = element_rect(fill= "White"), + panel.border = element_blank(), + axis.line = element_line(), + legend.title = element_blank()) + + scale_x_continuous(expand = c(0,0))+ + scale_fill_discrete(name=NULL) + + +treatment <- c("solid", "dashed") + +SumSWCLG <-SWCData_VWC %>% + ggplot(aes (x=das)) + + annotate(geom = "rect", xmin=0, xmax=60, ymin=-Inf, ymax=Inf, + fill="palegreen2", alpha=0.5)+ + annotate(geom = "rect", xmin=60, xmax=105, ymin=-Inf, ymax=Inf, + fill="paleturquoise2", alpha=0.7)+ + annotate(geom = "rect", xmin=105, xmax=155, ymin=-Inf, ymax=Inf, + fill="gray80", alpha=0.5)+ + geom_line(aes(y=SWC_WW, linetype="Full Irrigation"))+ + geom_line(aes(y=SWC_WD, linetype="Reduced Irrigation"))+ + labs(y= expression(VSWC~(m^3*m^3)), + title= "Daily Volumetric Soil Water Content", x= "Days after sowing")+ + theme(panel.grid = element_blank(), + panel.background = element_rect(fill= "White"), + panel.border = element_blank(), + axis.line = element_line(), + legend.title = element_blank(), + legend.position = c(0.5,1.10), + legend.direction ="horizontal", + legend.background= element_rect(fill=NA), + legend.key=element_blank())+ + scale_linetype_manual(values = treatment, breaks=c("Full Irrigation","Reduced Irrigation"))+ + scale_x_continuous(expand = c(0,0)) + +SumSWCLG + +background <- SWCData_WDmeanSWC %>% +ggplot(aes (x=das, y="mean(soilVWC_WD)")) + + annotate(geom = "rect", xmin=0, xmax=60, ymin=-Inf, ymax=Inf, + fill="palegreen2", alpha=0.5)+ + annotate(geom = "rect", xmin=60, xmax=105, ymin=-Inf, ymax=Inf, + fill="paleturquoise2", alpha=0.7)+ + annotate(geom = "rect", xmin=105, xmax=155, ymin=-Inf, ymax=Inf, + fill="gray80", alpha=0.5)+ + theme(panel.grid = element_blank(), + panel.background = element_rect(fill= "White"), + panel.border = element_blank(), + axis.text.y = element_blank(), + axis.ticks.y = element_blank())+ + scale_x_continuous(expand = c(0,0))+ + labs(y=" ", x=" ")+ + geom_line() + +background + +figure <- ggarrange(AllTempsLG, MaxVPDLG, SumRADLG, SumSWCLG, background, + labels = c("A", "B", "C", "D", " "), + ncol = 1, nrow = 5, align = "v") + +figure + + +colnames(SWCData_WDmeanSWC) + + + + +#Graphs with different rectangle colors +MaxTempLG <-EnvdataDay_maxtemp %>% + ggplot(aes (x=das, y=Daily_MaxTemp)) + + geom_line()+ + theme(panel.grid = element_blank())+ + labs(y= expression( Temperature~(degree*C)), + title= "Daily Maximum Temperature")+ + geom_rect(aes(xmin=0, xmax=60, ymin=-Inf, ymax=Inf), + fill= 'gray100', alpha = 0.002)+ + geom_rect(aes(xmin=60, xmax=105, ymin=-Inf, ymax=Inf), + fill= 'gray78', alpha = 0.002)+ + geom_rect(aes(xmin=105, xmax=156, ymin=-Inf, ymax=Inf), + fill= 'gray61', alpha = 0.002) + + + + + -- GitLab