setwd("~/Google Drive/Agrosavia/Colaboraciones/Fabricio/data")
library(Plasticity)
library(agricolae)
library(Rmisc)
## Loading required package: lattice
## Loading required package: plyr
library(dplyr)
## 
## Attaching package: 'dplyr'
## The following objects are masked from 'package:plyr':
## 
##     arrange, count, desc, failwith, id, mutate, rename, summarise,
##     summarize
## The following objects are masked from 'package:stats':
## 
##     filter, lag
## The following objects are masked from 'package:base':
## 
##     intersect, setdiff, setequal, union
library(ggplot2)
library(psych)
## 
## Attaching package: 'psych'
## The following objects are masked from 'package:ggplot2':
## 
##     %+%, alpha
library(FSA)
## ## FSA v0.9.1. See citation('FSA') if used in publication.
## ## Run fishR() for related website and fishR('IFAR') for related book.
## 
## Attaching package: 'FSA'
## The following object is masked from 'package:psych':
## 
##     headtail
## The following object is masked from 'package:plyr':
## 
##     mapvalues
library(forcats)
library(Hmisc)
## Loading required package: survival
## Loading required package: Formula
## 
## Attaching package: 'Hmisc'
## The following object is masked from 'package:psych':
## 
##     describe
## The following objects are masked from 'package:dplyr':
## 
##     src, summarize
## The following objects are masked from 'package:plyr':
## 
##     is.discrete, summarize
## The following objects are masked from 'package:base':
## 
##     format.pval, units
library("PerformanceAnalytics")
## Loading required package: xts
## Loading required package: zoo
## 
## Attaching package: 'zoo'
## The following objects are masked from 'package:base':
## 
##     as.Date, as.Date.numeric
## 
## Attaching package: 'xts'
## The following objects are masked from 'package:dplyr':
## 
##     first, last
## 
## Attaching package: 'PerformanceAnalytics'
## The following objects are masked from 'package:agricolae':
## 
##     kurtosis, skewness
## The following object is masked from 'package:graphics':
## 
##     legend
library(onewaytests)
## Registered S3 methods overwritten by 'car':
##   method       from
##   hist.boot    FSA 
##   confint.boot FSA
## 
## Attaching package: 'onewaytests'
## The following object is masked from 'package:Hmisc':
## 
##     describe
## The following object is masked from 'package:psych':
## 
##     describe
library(emmeans)
library(ggthemes)
library(multcompView)
clone <- read.table("res_fin.csv", header=T, sep=",")
clone$Repetición<-as.factor(clone$Repetición)
clone$Clon<-as.factor(clone$Clon)
clone$env<-as.factor(clone$env)
## Generando bases de datos para los rangos ambientales a evaluar (100-300, 500-2000)
clone.low <- filter(clone, clone$env == "100" | clone$env=="300")
clone.low.fin <- droplevels(clone.low)
clone.low.fin$Clon<-as.factor(clone.low.fin$Clon)
clone.low.fin$env<-as.factor(clone.low.fin$env)
## Calculo del RDPI para todos los caracteres luz baja (100-300)
A.low.rdpi<-rdpi(clone.low.fin, Clon, A, env)
## 
## Attaching package: 'sciplot'
## The following object is masked from 'package:FSA':
## 
##     se
## [1] "ANOVA test"
##              Df Sum Sq Mean Sq F value Pr(>F)  
## RDPI$sp      19  0.672 0.03535   1.946  0.011 *
## Residuals   300  5.450 0.01817                 
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## Joining, by = "sp"

## [1] "Tukey HSD test for differences accross groups"
## # A tibble: 20 × 5
##    sp      mean     sd     se groups
##    <fct>  <dbl>  <dbl>  <dbl> <chr> 
##  1 TCS 01 0.268 0.0647 0.0162 a     
##  2 TCS 02 0.359 0.0743 0.0186 a     
##  3 TCS 03 0.388 0.208  0.0521 a     
##  4 TCS 04 0.267 0.135  0.0339 a     
##  5 TCS 05 0.226 0.0948 0.0237 a     
##  6 TCS 08 0.278 0.0651 0.0163 a     
##  7 TCS 10 0.243 0.173  0.0433 a     
##  8 TCS 11 0.298 0.158  0.0396 a     
##  9 TCS 12 0.327 0.220  0.0550 a     
## 10 TCS 20 0.369 0.198  0.0495 a     
## 11 TCS 40 0.336 0.129  0.0323 a     
## 12 TCS 41 0.307 0.0739 0.0185 a     
## 13 TCS 42 0.268 0.0545 0.0136 a     
## 14 TCS 43 0.329 0.0990 0.0247 a     
## 15 TCS 44 0.306 0.116  0.0289 a     
## 16 TCS 45 0.271 0.0548 0.0137 a     
## 17 TCS 46 0.303 0.0709 0.0177 a     
## 18 TCS 47 0.253 0.0960 0.0240 a     
## 19 TCS 48 0.325 0.108  0.0270 a     
## 20 TCS 49 0.386 0.242  0.0605 a
E.low.rdpi<-rdpi(clone.low.fin, Clon, E, env)
## [1] "ANOVA test"
##              Df Sum Sq Mean Sq F value   Pr(>F)    
## RDPI$sp      19  2.230 0.11738   4.327 1.52e-08 ***
## Residuals   300  8.138 0.02713                     
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## Joining, by = "sp"

## [1] "Tukey HSD test for differences accross groups"
## # A tibble: 20 × 5
##    sp       mean     sd      se groups
##    <fct>   <dbl>  <dbl>   <dbl> <chr> 
##  1 TCS 01 0.165  0.142  0.0356  abc   
##  2 TCS 02 0.121  0.0954 0.0238  bc    
##  3 TCS 03 0.364  0.346  0.0864  a     
##  4 TCS 04 0.202  0.145  0.0363  abc   
##  5 TCS 05 0.132  0.133  0.0332  bc    
##  6 TCS 08 0.137  0.103  0.0258  bc    
##  7 TCS 10 0.138  0.106  0.0266  bc    
##  8 TCS 11 0.165  0.154  0.0386  abc   
##  9 TCS 12 0.207  0.176  0.0439  abc   
## 10 TCS 20 0.250  0.222  0.0554  ab    
## 11 TCS 40 0.124  0.115  0.0289  bc    
## 12 TCS 41 0.0325 0.0162 0.00404 c     
## 13 TCS 42 0.0683 0.0511 0.0128  bc    
## 14 TCS 43 0.212  0.176  0.0440  abc   
## 15 TCS 44 0.190  0.167  0.0417  abc   
## 16 TCS 45 0.0463 0.0330 0.00824 bc    
## 17 TCS 46 0.146  0.101  0.0254  bc    
## 18 TCS 47 0.128  0.122  0.0306  bc    
## 19 TCS 48 0.139  0.121  0.0302  bc    
## 20 TCS 49 0.357  0.336  0.0841  a
WUE.low.rdpi<-rdpi(clone.low.fin, Clon, WUE, env)
## [1] "ANOVA test"
##              Df Sum Sq Mean Sq F value   Pr(>F)    
## RDPI$sp      19  0.976 0.05138    3.21 1.12e-05 ***
## Residuals   300  4.802 0.01601                     
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## Joining, by = "sp"

## [1] "Tukey HSD test for differences accross groups"
## # A tibble: 20 × 5
##    sp      mean     sd     se groups
##    <fct>  <dbl>  <dbl>  <dbl> <chr> 
##  1 TCS 01 0.248 0.146  0.0366 abc   
##  2 TCS 02 0.363 0.0808 0.0202 a     
##  3 TCS 03 0.335 0.200  0.0501 ab    
##  4 TCS 04 0.222 0.105  0.0262 abc   
##  5 TCS 05 0.235 0.130  0.0325 abc   
##  6 TCS 08 0.259 0.108  0.0269 abc   
##  7 TCS 10 0.150 0.100  0.0251 c     
##  8 TCS 11 0.269 0.0719 0.0180 abc   
##  9 TCS 12 0.200 0.114  0.0284 bc    
## 10 TCS 20 0.241 0.165  0.0412 abc   
## 11 TCS 40 0.344 0.110  0.0275 ab    
## 12 TCS 41 0.327 0.0524 0.0131 ab    
## 13 TCS 42 0.261 0.0848 0.0212 abc   
## 14 TCS 43 0.366 0.221  0.0553 a     
## 15 TCS 44 0.285 0.137  0.0343 abc   
## 16 TCS 45 0.245 0.0918 0.0230 abc   
## 17 TCS 46 0.285 0.143  0.0356 abc   
## 18 TCS 47 0.249 0.116  0.0291 abc   
## 19 TCS 48 0.314 0.0874 0.0219 ab    
## 20 TCS 49 0.222 0.132  0.0331 abc
gsw.low.rdpi<-rdpi(clone.low.fin, Clon, gsw, env)
## [1] "ANOVA test"
##              Df Sum Sq Mean Sq F value   Pr(>F)    
## RDPI$sp      19  2.490 0.13105   5.802 2.32e-12 ***
## Residuals   300  6.776 0.02259                     
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## Joining, by = "sp"

## [1] "Tukey HSD test for differences accross groups"
## # A tibble: 20 × 5
##    sp       mean     sd      se groups
##    <fct>   <dbl>  <dbl>   <dbl> <chr> 
##  1 TCS 01 0.0977 0.0766 0.0192  d     
##  2 TCS 02 0.0976 0.0753 0.0188  d     
##  3 TCS 03 0.319  0.286  0.0714  ab    
##  4 TCS 04 0.180  0.127  0.0317  bcd   
##  5 TCS 05 0.204  0.159  0.0398  bcd   
##  6 TCS 08 0.0963 0.0697 0.0174  d     
##  7 TCS 10 0.201  0.140  0.0351  bcd   
##  8 TCS 11 0.0829 0.0562 0.0140  d     
##  9 TCS 12 0.301  0.253  0.0632  abc   
## 10 TCS 20 0.219  0.181  0.0452  abcd  
## 11 TCS 40 0.168  0.135  0.0337  bcd   
## 12 TCS 41 0.0905 0.0560 0.0140  d     
## 13 TCS 42 0.150  0.118  0.0295  bcd   
## 14 TCS 43 0.0294 0.0197 0.00493 d     
## 15 TCS 44 0.153  0.120  0.0300  bcd   
## 16 TCS 45 0.154  0.132  0.0330  bcd   
## 17 TCS 46 0.129  0.0897 0.0224  cd    
## 18 TCS 47 0.160  0.130  0.0325  bcd   
## 19 TCS 48 0.0928 0.0810 0.0202  d     
## 20 TCS 49 0.402  0.306  0.0766  a
cica.low.rdpi<-rdpi(clone.low.fin, Clon, cica, env)
## [1] "ANOVA test"
##              Df Sum Sq  Mean Sq F value   Pr(>F)    
## RDPI$sp      19 0.1618 0.008518   3.029 3.17e-05 ***
## Residuals   300 0.8435 0.002812                     
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## Joining, by = "sp"

## [1] "Tukey HSD test for differences accross groups"
## # A tibble: 20 × 5
##    sp       mean      sd      se groups
##    <fct>   <dbl>   <dbl>   <dbl> <chr> 
##  1 TCS 01 0.106  0.0368  0.00919 abcd  
##  2 TCS 02 0.108  0.0272  0.00681 abcd  
##  3 TCS 03 0.164  0.0651  0.0163  a     
##  4 TCS 04 0.104  0.0334  0.00835 abcd  
##  5 TCS 05 0.146  0.0971  0.0243  abc   
##  6 TCS 08 0.121  0.0141  0.00352 abcd  
##  7 TCS 10 0.100  0.0633  0.0158  abcd  
##  8 TCS 11 0.0809 0.0455  0.0114  cd    
##  9 TCS 12 0.111  0.0420  0.0105  abcd  
## 10 TCS 20 0.0780 0.0710  0.0177  d     
## 11 TCS 40 0.125  0.0303  0.00759 abcd  
## 12 TCS 41 0.135  0.0612  0.0153  abcd  
## 13 TCS 42 0.141  0.0803  0.0201  abcd  
## 14 TCS 43 0.152  0.0307  0.00768 ab    
## 15 TCS 44 0.0980 0.0271  0.00677 abcd  
## 16 TCS 45 0.104  0.0614  0.0154  abcd  
## 17 TCS 46 0.130  0.0442  0.0111  abcd  
## 18 TCS 47 0.120  0.0577  0.0144  abcd  
## 19 TCS 48 0.103  0.00849 0.00212 abcd  
## 20 TCS 49 0.0957 0.0660  0.0165  bcd
low.rdpi<-data.frame(A.low.rdpi$sp, A.low.rdpi$rdpi, E.low.rdpi$rdpi, WUE.low.rdpi$rdpi, gsw.low.rdpi$rdpi, 
                     cica.low.rdpi$rdpi)
colnames(low.rdpi)<-c('gen', 'Ardpi', 'Erdpi', 'WUErdpi', 'gswrdpi', 'cicardpi')
low.rdpi$treatment <- "low"
## analysis of variance
anova_A <- aov(low.rdpi$Ardpi ~ low.rdpi$gen, data = low.rdpi)
anova_E <- aov(low.rdpi$Erdpi ~ low.rdpi$gen, data = low.rdpi)
anova_WUE <- aov(low.rdpi$WUErdpi ~ low.rdpi$gen, data = low.rdpi)
anova_gsw <- aov(low.rdpi$gswrdpi ~ low.rdpi$gen, data = low.rdpi)
anova_cica <- aov(low.rdpi$cicardpi ~ low.rdpi$gen, data = low.rdpi)
## Mean contrast for A
A_emm <- emmeans(anova_A, "gen")
pwpp(A_emm)

multcomp::cld(A_emm, alpha = 0.10, Letters = LETTERS)
##  gen    emmean     SE  df lower.CL upper.CL .group
##  TCS 05  0.226 0.0337 300    0.159    0.292  A    
##  TCS 10  0.243 0.0337 300    0.177    0.309  AB   
##  TCS 47  0.253 0.0337 300    0.187    0.319  AB   
##  TCS 04  0.267 0.0337 300    0.201    0.334  AB   
##  TCS 42  0.268 0.0337 300    0.201    0.334  AB   
##  TCS 01  0.268 0.0337 300    0.202    0.334  AB   
##  TCS 45  0.271 0.0337 300    0.204    0.337  AB   
##  TCS 08  0.278 0.0337 300    0.212    0.344  AB   
##  TCS 11  0.298 0.0337 300    0.232    0.365  AB   
##  TCS 46  0.303 0.0337 300    0.237    0.370  AB   
##  TCS 44  0.306 0.0337 300    0.240    0.373  AB   
##  TCS 41  0.307 0.0337 300    0.241    0.374  AB   
##  TCS 48  0.325 0.0337 300    0.259    0.392  AB   
##  TCS 12  0.327 0.0337 300    0.261    0.394  AB   
##  TCS 43  0.329 0.0337 300    0.263    0.395  AB   
##  TCS 40  0.336 0.0337 300    0.269    0.402  AB   
##  TCS 02  0.359 0.0337 300    0.292    0.425  AB   
##  TCS 20  0.369 0.0337 300    0.303    0.435  AB   
##  TCS 49  0.386 0.0337 300    0.320    0.452   B   
##  TCS 03  0.388 0.0337 300    0.322    0.455   B   
## 
## Confidence level used: 0.95 
## P value adjustment: tukey method for comparing a family of 20 estimates 
## significance level used: alpha = 0.1 
## NOTE: Compact letter displays can be misleading
##       because they show NON-findings rather than findings.
##       Consider using 'pairs()', 'pwpp()', or 'pwpm()' instead.
## Tukey's test
tukey_A <- TukeyHSD(anova_A)
tukey_E <- TukeyHSD(anova_E)
tukey_WUE <- TukeyHSD(anova_WUE)
tukey_gsw <- TukeyHSD(anova_gsw)
tukey_cica <- TukeyHSD(anova_cica)
## compact letter display
cld_A <- multcompLetters4(anova_A, tukey_A)
cld_E <- multcompLetters4(anova_E, tukey_E)
cld_WUE <- multcompLetters4(anova_WUE, tukey_WUE)
cld_gsw <- multcompLetters4(anova_gsw, tukey_gsw)
cld_cica <- multcompLetters4(anova_cica, tukey_cica)
## table with factors and 3rd quantile
dt_A <- group_by(low.rdpi, gen) %>%
  summarise(w=mean(Ardpi)) %>%
  arrange(desc(w))
dt_E <- group_by(low.rdpi, gen) %>%
  summarise(w=mean(Erdpi)) %>%
  arrange(desc(w))
dt_WUE <- group_by(low.rdpi, gen) %>%
  summarise(w=mean(WUErdpi)) %>%
  arrange(desc(w))
dt_gsw <- group_by(low.rdpi, gen) %>%
  summarise(w=mean(gswrdpi)) %>%
  arrange(desc(w))
dt_cica <- group_by(low.rdpi, gen) %>%
  summarise(w=mean(cicardpi)) %>%
  arrange(desc(w))
## extracting the compact letter display and adding to the Tk table
dt_A$cldA <- cld_A$`low.rdpi$gen`$Letters
print(dt_A)
## # A tibble: 20 × 3
##    gen        w cldA 
##    <fct>  <dbl> <chr>
##  1 TCS 03 0.388 a    
##  2 TCS 49 0.386 a    
##  3 TCS 20 0.369 a    
##  4 TCS 02 0.359 a    
##  5 TCS 40 0.336 a    
##  6 TCS 43 0.329 a    
##  7 TCS 12 0.327 a    
##  8 TCS 48 0.325 a    
##  9 TCS 41 0.307 a    
## 10 TCS 44 0.306 a    
## 11 TCS 46 0.303 a    
## 12 TCS 11 0.298 a    
## 13 TCS 08 0.278 a    
## 14 TCS 45 0.271 a    
## 15 TCS 01 0.268 a    
## 16 TCS 42 0.268 a    
## 17 TCS 04 0.267 a    
## 18 TCS 47 0.253 a    
## 19 TCS 10 0.243 a    
## 20 TCS 05 0.226 a
dt_E$cldE <- cld_E$`low.rdpi$gen`$Letters
print(dt_E)
## # A tibble: 20 × 3
##    gen         w cldE 
##    <fct>   <dbl> <chr>
##  1 TCS 03 0.364  a    
##  2 TCS 49 0.357  a    
##  3 TCS 20 0.250  ab   
##  4 TCS 43 0.212  abc  
##  5 TCS 12 0.207  abc  
##  6 TCS 04 0.202  abc  
##  7 TCS 44 0.190  abc  
##  8 TCS 11 0.165  abc  
##  9 TCS 01 0.165  abc  
## 10 TCS 46 0.146  bc   
## 11 TCS 48 0.139  bc   
## 12 TCS 10 0.138  bc   
## 13 TCS 08 0.137  bc   
## 14 TCS 05 0.132  bc   
## 15 TCS 47 0.128  bc   
## 16 TCS 40 0.124  bc   
## 17 TCS 02 0.121  bc   
## 18 TCS 42 0.0683 bc   
## 19 TCS 45 0.0463 bc   
## 20 TCS 41 0.0325 c
dt_WUE$cldWUE <- cld_WUE$`low.rdpi$gen`$Letters
print(dt_WUE)
## # A tibble: 20 × 3
##    gen        w cldWUE
##    <fct>  <dbl> <chr> 
##  1 TCS 43 0.366 a     
##  2 TCS 02 0.363 a     
##  3 TCS 40 0.344 ab    
##  4 TCS 03 0.335 ab    
##  5 TCS 41 0.327 ab    
##  6 TCS 48 0.314 ab    
##  7 TCS 46 0.285 abc   
##  8 TCS 44 0.285 abc   
##  9 TCS 11 0.269 abc   
## 10 TCS 42 0.261 abc   
## 11 TCS 08 0.259 abc   
## 12 TCS 47 0.249 abc   
## 13 TCS 01 0.248 abc   
## 14 TCS 45 0.245 abc   
## 15 TCS 20 0.241 abc   
## 16 TCS 05 0.235 abc   
## 17 TCS 04 0.222 abc   
## 18 TCS 49 0.222 abc   
## 19 TCS 12 0.200 bc    
## 20 TCS 10 0.150 c
dt_gsw$cldgsw <- cld_gsw$`low.rdpi$gen`$Letters
print(dt_gsw)
## # A tibble: 20 × 3
##    gen         w cldgsw
##    <fct>   <dbl> <chr> 
##  1 TCS 49 0.402  a     
##  2 TCS 03 0.319  ab    
##  3 TCS 12 0.301  abc   
##  4 TCS 20 0.219  abcd  
##  5 TCS 05 0.204  bcd   
##  6 TCS 10 0.201  bcd   
##  7 TCS 04 0.180  bcd   
##  8 TCS 40 0.168  bcd   
##  9 TCS 47 0.160  bcd   
## 10 TCS 45 0.154  bcd   
## 11 TCS 44 0.153  bcd   
## 12 TCS 42 0.150  bcd   
## 13 TCS 46 0.129  cd    
## 14 TCS 01 0.0977 d     
## 15 TCS 02 0.0976 d     
## 16 TCS 08 0.0963 d     
## 17 TCS 48 0.0928 d     
## 18 TCS 41 0.0905 d     
## 19 TCS 11 0.0829 d     
## 20 TCS 43 0.0294 d
dt_cica$cldcica <- cld_cica$`low.rdpi$gen`$Letters
print(dt_cica)
## # A tibble: 20 × 3
##    gen         w cldcica
##    <fct>   <dbl> <chr>  
##  1 TCS 03 0.164  a      
##  2 TCS 43 0.152  ab     
##  3 TCS 05 0.146  abc    
##  4 TCS 42 0.141  abcd   
##  5 TCS 41 0.135  abcd   
##  6 TCS 46 0.130  abcd   
##  7 TCS 40 0.125  abcd   
##  8 TCS 08 0.121  abcd   
##  9 TCS 47 0.120  abcd   
## 10 TCS 12 0.111  abcd   
## 11 TCS 02 0.108  abcd   
## 12 TCS 01 0.106  abcd   
## 13 TCS 45 0.104  abcd   
## 14 TCS 04 0.104  abcd   
## 15 TCS 48 0.103  abcd   
## 16 TCS 10 0.100  abcd   
## 17 TCS 44 0.0980 abcd   
## 18 TCS 49 0.0957 bcd    
## 19 TCS 11 0.0809 cd     
## 20 TCS 20 0.0780 d
### group low.rdpi by gen and return some averages and estandar errors
low2 <- low.rdpi %>%
  select(gen, Ardpi, Erdpi, WUErdpi, gswrdpi, cicardpi) %>%
  group_by(gen) %>%
  summarise(
    Ardpi_m = mean(Ardpi), 
    Erdpi_m = mean(Erdpi), 
    WUErdpi_m = mean(WUErdpi), 
    gswrdpi_m = mean(gswrdpi), 
    cicardpi_m = mean(cicardpi),
    n=n(),
    sd_A=sd(Ardpi),
    sd_E=sd(Erdpi),
    sd_WUE=sd(WUErdpi),
    sd_gsw=sd(gswrdpi),
    sd_cica=sd(cicardpi)
  ) %>%
  mutate(se_A=sd_A/sqrt(n)) %>%
  mutate(se_E=sd_E/sqrt(n)) %>%
  mutate(se_WUE=sd_WUE/sqrt(n)) %>%
  mutate(se_gsw=sd_gsw/sqrt(n)) %>%
  mutate(se_cica=sd_cica/sqrt(n))
## Adding Tukey letters to low
dt_AF <- read.table("letterA.csv", header=T, sep=",")
low2<-merge(dt_AF, low2, by="gen")
low2<-merge(dt_A, low2, by="gen")
low2<-merge(dt_E, low2, by="gen")
low2<-merge(dt_WUE, low2, by="gen")
low2<-merge(dt_gsw, low2, by="gen")
## Warning in merge.data.frame(dt_gsw, low2, by = "gen"): column names 'w.x', 'w.y'
## are duplicated in the result
low2<-merge(dt_cica, low2, by="gen")
## saving the data frames
write.csv(low2, "~/Google Drive/Agrosavia/Colaboraciones/Fabricio/data/low.csv")
lows <- read.table("low.csv", header=T, sep=",")
attach(lows)
##Reordering gen by mean
new_order3 <- with(lows, reorder(gen, Ardpi_m, mean, na.rm=T))
new_order4 <- with(lows, reorder(gen, Erdpi_m, mean, na.rm=T))
new_order5 <- with(lows, reorder(gen, WUErdpi_m, mean, na.rm=T))
new_order6 <- with(lows, reorder(gen, gswrdpi_m, mean, na.rm=T))
new_order7 <- with(lows, reorder(gen, cicardpi_m, mean, na.rm=T))
##Barplots
Aplot=lows %>%
  arrange(Ardpi_m) %>%
  mutate(gen=factor(gen, levels = gen)) %>%
  ggplot( aes(x=gen, y=Ardpi_m, fill=cld_FA)) +
  scale_fill_brewer(palette = "Paired") +
  geom_col(alpha=.9, width=.7, show.legend = FALSE) +
  geom_errorbar(aes(ymin=Ardpi_m-se_A, ymax=Ardpi_m+se_A), width=0.2)+
  geom_text(aes(label = cld_FA, y = Ardpi_m), nudge_x =0, nudge_y = 0.07, size = 3.5) +
  coord_flip() +
  xlab("") +
  ylab(expression(RDPI[A])) +
  theme_classic()
Aplot + theme(axis.text = element_text(size = 12))

ggsave("Aplot.tiff", plot= Aplot, width = 4, height = 3, dpi = 1000)

Eplot=lows %>%
  arrange(Erdpi_m) %>%
  mutate(gen=factor(gen, levels = gen)) %>%
  ggplot( aes(x=gen, y=Erdpi_m, fill=cldE)) +
  geom_col(alpha=.9, width=.7, show.legend = FALSE) +
  scale_fill_brewer(palette = "Paired") +
  geom_errorbar(aes(ymin=Erdpi_m-se_E, ymax=Erdpi_m+se_E), width=0.2)+
  geom_text(aes(label = cldE, y = Erdpi_m), nudge_x =0, nudge_y = 0.1, size = 3.5)+
  coord_flip() +
  xlab("") +
  ylab(expression(RDPI[E])) +
  theme_classic()
Eplot + theme(axis.text = element_text(size = 12))

ggsave("Eplot.tiff", plot= Eplot, width = 4, height = 3, dpi = 1000)

WUEplot=lows %>%
  arrange(WUErdpi_m) %>%
  mutate(gen=factor(gen, levels = gen)) %>%
  ggplot( aes(x=gen, y=WUErdpi_m, fill=cldWUE)) +
  geom_col(alpha=.9, width=.7, show.legend = FALSE) +
  scale_fill_brewer(palette = "Paired") +
  geom_errorbar(aes(ymin=WUErdpi_m-se_WUE, ymax=WUErdpi_m+se_WUE), width=0.2)+
  geom_text(aes(label = cldWUE, y = WUErdpi_m), nudge_x =0, nudge_y = 0.09, size = 3.5)+
  coord_flip() +
  xlab("") +
  ylab(expression(RDPI[WUE])) +
  theme_classic()
WUEplot + theme(axis.text = element_text(size = 12))

ggsave("WUEplot.tiff", plot= WUEplot, width = 4, height = 3, dpi = 1000)

gswplot=lows %>%
  arrange(gswrdpi_m) %>%
  mutate(gen=factor(gen, levels = gen)) %>%
  ggplot( aes(x=gen, y=gswrdpi_m, fill = cldgsw)) +
  geom_col(alpha=.9, width=.7, show.legend = FALSE) +
  scale_fill_brewer(palette = "Paired") +
  geom_errorbar(aes(ymin=gswrdpi_m-se_gsw, ymax=gswrdpi_m+se_gsw), width=0.2)+
  geom_text(aes(label = cldgsw, y = gswrdpi_m), nudge_x =0, nudge_y = 0.09, size = 3.5)+
  coord_flip() +
  xlab("") +
  ylab(expression(RDPI[gSw])) +
  theme_classic()
gswplot + theme(axis.text = element_text(size = 12))

ggsave("gswplot.tiff", plot= gswplot, width = 4, height = 3, dpi = 1000)

cicaplot=lows %>%
  arrange(cicardpi_m) %>%
  mutate(gen=factor(gen, levels = gen)) %>%
  ggplot( aes(x=gen, y=cicardpi_m, fill = cldcica )) +
  geom_col(alpha=.9, width=.7, show.legend = FALSE) +
  scale_fill_brewer(palette = "Paired") +
  geom_errorbar(aes(ymin=cicardpi_m-se_cica, ymax=cicardpi_m+se_cica), width=0.2)+
  geom_text(aes(label = cldcica, y = cicardpi_m), nudge_x =0, nudge_y = 0.07, size = 3.5)+
  coord_flip() +
  xlab("") +
  ylab(expression(RDPI[Ci/Ca])) +
  theme_classic()
cicaplot + theme(axis.text = element_text(size = 12))

ggsave("cicaplot.tiff", plot= cicaplot, width = 4, height = 3, dpi = 1000)

detach(lows)