# written with R version 4.0.2 (2020-06-22) -- "Taking Off Again"
##------ Tue Oct 13 11:53:48 2020 ------##
# by Norman Gentsch
library(tidyverse)
library(lme4)
library(emmeans)
library(multcomp)
library(knitr)
library(DT)
# set theme for ggplot
theme_set(theme_bw())
theme_myBW <- theme(axis.title.x = element_text(size = 10, color = "black"),
axis.title.y = element_text(angle = 90, vjust = 1.5, size = 10, color = "black"),
axis.text.x = element_text(size = 10, color = "black"),
axis.text.y = element_text(size = 10, color = "black"),
axis.ticks =element_line(colour="black"),
strip.text.x = element_text(size = 10, color = "black"),
strip.background = element_blank(),
panel.border =element_rect(colour="black", fill=NA),
panel.grid.major = element_blank(),
panel.grid.minor = element_blank(),
plot.title = element_text(size = 12, hjust=0.5),
#legend.position=c(0.0,1.0),
#legend.justification=c(0,1),
legend.text = element_text(size = 10),
legend.text.align=0,
legend.title = element_text(size = 10),
legend.key = element_rect(colour="white", fill = "white"),
legend.key.size = unit(5, "mm"),
legend.background = element_blank())
# set vector with colors and label
COL <- c("Fallow" = "slategray", "Mustard" = "red3" , "Mix4" = "orchid3", "Mix12"= "orange4")
SHP <- c("Fallow"=21,"Mustard"=22,"Mix4"=23, "Mix12"=24)
data <- read.csv2("data.csv", as.is=T)
data$NEE <- as.numeric(data$NEE)
lm_NEE <- lmer(NEE ~ cc_variant + (1|Date), data=data)
df_NEE <- cld(emmeans(lm_NEE, specs ="cc_variant"), Letters=letters, sort=FALSE)
# summary table for
sum.lm <- glht(lm_NEE, linfct = mcp(cc_variant = "Tukey"))
#summary(sum.lm)$test$pvalue
glht.table <- function(x) {
pq <- summary(x)$test
mtests <- cbind(pq$coefficients, pq$sigma, pq$tstat, pq$pvalues)
colnames(mtests) <- c("Estimate", "Std Error", "z value", "p value")
return(mtests)
}
df.summary <- data.frame(glht.table(sum.lm))
#df.summary
abc <- subset (df.summary, p.value<0.01)
maxValue <- max(abc$p.value)
p <- round(maxValue + 5*10^(-3), 2)
colMax <- function(data) sapply(data, max, na.rm = TRUE)
# Plot for BFS
ggplot(data, aes(x= cc_variant, y=NEE, fill= cc_variant))+
geom_boxplot()+
scale_fill_manual(values = COL, guide=FALSE)+
geom_text(data= df_NEE ,aes(y=-600,x=cc_variant, label=.group))+
labs(x="Catch crop variant", y=expression("NEE (mg CO"[2]~"- C"~m^{-2}~h^{-1}~")"), fill="")+
theme_myBW+scale_x_discrete(limits=c("Fallow", "Mustard", "Mix4", "Mix12"))
#ggsave("Fig1.png", width = 84, height = 70, units = "mm", dpi = 600)
#summary(lm_NEE)