setwd("/Volumes/GoogleDrive/Mi unidad/Agrosavia/Colaboraciones/Fabricio/Yesid/growth")
datos<-read.table("ult.csv", header=T, sep=',')
datos$gen<-as.factor(datos$gen)
datos$Shade<-as.factor(datos$Shade)
datos$bloque<-as.factor(datos$bloque)
attach(datos)
library(ggplot2)
library(emmeans)
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(tidyverse)
## ── Attaching packages ─────────────────────────────────────── tidyverse 1.3.1 ──
## ✓ tibble  3.1.6     ✓ purrr   0.3.4
## ✓ tidyr   1.1.4     ✓ stringr 1.4.0
## ✓ readr   2.1.1     ✓ forcats 0.5.1
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## x dplyr::arrange()   masks plyr::arrange()
## x purrr::compact()   masks plyr::compact()
## x dplyr::count()     masks plyr::count()
## x dplyr::failwith()  masks plyr::failwith()
## x dplyr::filter()    masks stats::filter()
## x dplyr::id()        masks plyr::id()
## x dplyr::lag()       masks stats::lag()
## x dplyr::mutate()    masks plyr::mutate()
## x dplyr::rename()    masks plyr::rename()
## x dplyr::summarise() masks plyr::summarise()
## x dplyr::summarize() masks plyr::summarize()
library(ggpubr)
## 
## Attaching package: 'ggpubr'
## The following object is masked from 'package:plyr':
## 
##     mutate
library(rstatix)
## 
## Attaching package: 'rstatix'
## The following objects are masked from 'package:plyr':
## 
##     desc, mutate
## The following object is masked from 'package:stats':
## 
##     filter
##Summary statistics diameter
summ<-datos %>%
  group_by(Shade, gen) %>%
  get_summary_stats(diam, type = "mean_ci")
summ %>% as_tibble() %>% print(n=Inf)
## # A tibble: 9 × 6
##   Shade         gen   variable     n  mean    ci
##   <fct>         <fct> <chr>    <dbl> <dbl> <dbl>
## 1 C. pyriformis CCN51 diam        18  5.04 1.10 
## 2 C. pyriformis TCS01 diam        18  6.79 0.648
## 3 C. pyriformis TCS19 diam        18  5.7  0.734
## 4 T. rosea      CCN51 diam        18  6.2  0.797
## 5 T. rosea      TCS01 diam        18  5.56 0.648
## 6 T. rosea      TCS19 diam        17  5.61 0.772
## 7 T. superba    CCN51 diam        18  5.67 0.755
## 8 T. superba    TCS01 diam        18  6.49 0.528
## 9 T. superba    TCS19 diam        18  5.53 0.611
summ
## # A tibble: 9 × 6
##   Shade         gen   variable     n  mean    ci
##   <fct>         <fct> <chr>    <dbl> <dbl> <dbl>
## 1 C. pyriformis CCN51 diam        18  5.04 1.10 
## 2 C. pyriformis TCS01 diam        18  6.79 0.648
## 3 C. pyriformis TCS19 diam        18  5.7  0.734
## 4 T. rosea      CCN51 diam        18  6.2  0.797
## 5 T. rosea      TCS01 diam        18  5.56 0.648
## 6 T. rosea      TCS19 diam        17  5.61 0.772
## 7 T. superba    CCN51 diam        18  5.67 0.755
## 8 T. superba    TCS01 diam        18  6.49 0.528
## 9 T. superba    TCS19 diam        18  5.53 0.611
#Modelo diam
aov.diam<-aov(diam~gen*Shade+bloque)
summary(aov.diam)
##              Df Sum Sq Mean Sq F value   Pr(>F)    
## gen           2  15.26    7.63   4.143  0.01774 *  
## Shade         2   0.31    0.16   0.085  0.91851    
## bloque        2  66.29   33.15  18.001 9.84e-08 ***
## gen:Shade     4  26.92    6.73   3.654  0.00717 ** 
## Residuals   150 276.20    1.84                     
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
#Contrastes Posthoc 
contrast <- emmeans(aov.diam, ~gen|Shade)
diammc<-plot(contrast, comparisons = TRUE, xlab = expression ("Estimated marginal mean, diameter"), 
          ylab = expression ("Genotype"))
diammc

# Letras marginal means diameter
medias.Shade.gen <- emmeans(aov.diam, pairwise ~ gen*Shade)
medias.Shade.gen
## $emmeans
##  gen   Shade         emmean    SE  df lower.CL upper.CL
##  CCN51 C. pyriformis   5.04 0.320 150     4.41     5.68
##  TCS01 C. pyriformis   6.79 0.320 150     6.16     7.42
##  TCS19 C. pyriformis   5.70 0.320 150     5.07     6.33
##  CCN51 T. rosea        6.20 0.320 150     5.57     6.83
##  TCS01 T. rosea        5.56 0.320 150     4.92     6.19
##  TCS19 T. rosea        5.62 0.329 150     4.97     6.27
##  CCN51 T. superba      5.67 0.320 150     5.04     6.30
##  TCS01 T. superba      6.49 0.320 150     5.86     7.12
##  TCS19 T. superba      5.53 0.320 150     4.90     6.16
## 
## Results are averaged over the levels of: bloque 
## Confidence level used: 0.95 
## 
## $contrasts
##  contrast                                  estimate    SE  df t.ratio p.value
##  CCN51 C. pyriformis - TCS01 C. pyriformis  -1.7444 0.452 150  -3.857  0.0052
##  CCN51 C. pyriformis - TCS19 C. pyriformis  -0.6556 0.452 150  -1.449  0.8765
##  CCN51 C. pyriformis - CCN51 T. rosea       -1.1556 0.452 150  -2.555  0.2151
##  CCN51 C. pyriformis - TCS01 T. rosea       -0.5111 0.452 150  -1.130  0.9687
##  CCN51 C. pyriformis - TCS19 T. rosea       -0.5778 0.459 150  -1.259  0.9414
##  CCN51 C. pyriformis - CCN51 T. superba     -0.6278 0.452 150  -1.388  0.9008
##  CCN51 C. pyriformis - TCS01 T. superba     -1.4444 0.452 150  -3.193  0.0439
##  CCN51 C. pyriformis - TCS19 T. superba     -0.4833 0.452 150  -1.069  0.9778
##  TCS01 C. pyriformis - TCS19 C. pyriformis   1.0889 0.452 150   2.407  0.2877
##  TCS01 C. pyriformis - CCN51 T. rosea        0.5889 0.452 150   1.302  0.9294
##  TCS01 C. pyriformis - TCS01 T. rosea        1.2333 0.452 150   2.727  0.1475
##  TCS01 C. pyriformis - TCS19 T. rosea        1.1667 0.459 150   2.542  0.2209
##  TCS01 C. pyriformis - CCN51 T. superba      1.1167 0.452 150   2.469  0.2558
##  TCS01 C. pyriformis - TCS01 T. superba      0.3000 0.452 150   0.663  0.9991
##  TCS01 C. pyriformis - TCS19 T. superba      1.2611 0.452 150   2.788  0.1277
##  TCS19 C. pyriformis - CCN51 T. rosea       -0.5000 0.452 150  -1.105  0.9726
##  TCS19 C. pyriformis - TCS01 T. rosea        0.1444 0.452 150   0.319  1.0000
##  TCS19 C. pyriformis - TCS19 T. rosea        0.0778 0.459 150   0.169  1.0000
##  TCS19 C. pyriformis - CCN51 T. superba      0.0278 0.452 150   0.061  1.0000
##  TCS19 C. pyriformis - TCS01 T. superba     -0.7889 0.452 150  -1.744  0.7182
##  TCS19 C. pyriformis - TCS19 T. superba      0.1722 0.452 150   0.381  1.0000
##  CCN51 T. rosea - TCS01 T. rosea             0.6444 0.452 150   1.425  0.8866
##  CCN51 T. rosea - TCS19 T. rosea             0.5778 0.459 150   1.259  0.9414
##  CCN51 T. rosea - CCN51 T. superba           0.5278 0.452 150   1.167  0.9621
##  CCN51 T. rosea - TCS01 T. superba          -0.2889 0.452 150  -0.639  0.9993
##  CCN51 T. rosea - TCS19 T. superba           0.6722 0.452 150   1.486  0.8604
##  TCS01 T. rosea - TCS19 T. rosea            -0.0667 0.459 150  -0.145  1.0000
##  TCS01 T. rosea - CCN51 T. superba          -0.1167 0.452 150  -0.258  1.0000
##  TCS01 T. rosea - TCS01 T. superba          -0.9333 0.452 150  -2.063  0.5022
##  TCS01 T. rosea - TCS19 T. superba           0.0278 0.452 150   0.061  1.0000
##  TCS19 T. rosea - CCN51 T. superba          -0.0500 0.459 150  -0.109  1.0000
##  TCS19 T. rosea - TCS01 T. superba          -0.8667 0.459 150  -1.888  0.6230
##  TCS19 T. rosea - TCS19 T. superba           0.0944 0.459 150   0.206  1.0000
##  CCN51 T. superba - TCS01 T. superba        -0.8167 0.452 150  -1.806  0.6785
##  CCN51 T. superba - TCS19 T. superba         0.1444 0.452 150   0.319  1.0000
##  TCS01 T. superba - TCS19 T. superba         0.9611 0.452 150   2.125  0.4606
## 
## Results are averaged over the levels of: bloque 
## P value adjustment: tukey method for comparing a family of 9 estimates
cld_Shade_gen <-multcomp::cld(contrast, alpha = 0.05, Letters = LETTERS, reversed=T)
cld_Shade_gen
## Shade = C. pyriformis:
##  gen   emmean    SE  df lower.CL upper.CL .group
##  TCS01   6.79 0.320 150     6.16     7.42  A    
##  TCS19   5.70 0.320 150     5.07     6.33   B   
##  CCN51   5.04 0.320 150     4.41     5.68   B   
## 
## Shade = T. rosea:
##  gen   emmean    SE  df lower.CL upper.CL .group
##  CCN51   6.20 0.320 150     5.57     6.83  A    
##  TCS19   5.62 0.329 150     4.97     6.27  A    
##  TCS01   5.56 0.320 150     4.92     6.19  A    
## 
## Shade = T. superba:
##  gen   emmean    SE  df lower.CL upper.CL .group
##  TCS01   6.49 0.320 150     5.86     7.12  A    
##  CCN51   5.67 0.320 150     5.04     6.30  A    
##  TCS19   5.53 0.320 150     4.90     6.16  A    
## 
## Results are averaged over the levels of: bloque 
## Confidence level used: 0.95 
## P value adjustment: tukey method for comparing a family of 3 estimates 
## significance level used: alpha = 0.05 
## NOTE: Compact letter displays can be misleading
##       because they show NON-findings rather than findings.
##       Consider using 'pairs()', 'pwpp()', or 'pwpm()' instead.
ggsave("mgdiam.tiff", plot= diammc, width = 16, height = 12, units= c("cm"), dpi = 1000)

##Summary statistics height
summ<-datos %>%
  group_by(Shade, gen) %>%
  get_summary_stats(alt_m, type = "mean_ci")
summ %>% as_tibble() %>% print(n=Inf)
## # A tibble: 9 × 6
##   Shade         gen   variable     n  mean    ci
##   <fct>         <fct> <chr>    <dbl> <dbl> <dbl>
## 1 C. pyriformis CCN51 alt_m       18  1.96 0.436
## 2 C. pyriformis TCS01 alt_m       18  2.43 0.355
## 3 C. pyriformis TCS19 alt_m       18  1.83 0.208
## 4 T. rosea      CCN51 alt_m       18  2.29 0.228
## 5 T. rosea      TCS01 alt_m       18  2.00 0.233
## 6 T. rosea      TCS19 alt_m       17  1.86 0.254
## 7 T. superba    CCN51 alt_m       18  2.21 0.188
## 8 T. superba    TCS01 alt_m       18  2.34 0.145
## 9 T. superba    TCS19 alt_m       18  1.74 0.215
summ
## # A tibble: 9 × 6
##   Shade         gen   variable     n  mean    ci
##   <fct>         <fct> <chr>    <dbl> <dbl> <dbl>
## 1 C. pyriformis CCN51 alt_m       18  1.96 0.436
## 2 C. pyriformis TCS01 alt_m       18  2.43 0.355
## 3 C. pyriformis TCS19 alt_m       18  1.83 0.208
## 4 T. rosea      CCN51 alt_m       18  2.29 0.228
## 5 T. rosea      TCS01 alt_m       18  2.00 0.233
## 6 T. rosea      TCS19 alt_m       17  1.86 0.254
## 7 T. superba    CCN51 alt_m       18  2.21 0.188
## 8 T. superba    TCS01 alt_m       18  2.34 0.145
## 9 T. superba    TCS19 alt_m       18  1.74 0.215
#Modelo diam
aov.alt<-aov(alt_m~gen*Shade+bloque)
summary(aov.alt)
##              Df Sum Sq Mean Sq F value   Pr(>F)    
## gen           2   5.85   2.926  12.908 6.72e-06 ***
## Shade         2   0.07   0.034   0.152   0.8594    
## bloque        2   8.94   4.472  19.724 2.48e-08 ***
## gen:Shade     4   3.06   0.765   3.374   0.0112 *  
## Residuals   150  34.00   0.227                     
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
#Contrastes Posthoc 
contrast <- emmeans(aov.alt, ~gen|Shade)
altc<-plot(contrast, comparisons = TRUE, xlab = expression ("Estimated marginal mean, height" ), 
             ylab = expression ("Genotype"))
altc

# Letras marginal means height
medias.Shade.gen <- emmeans(aov.alt, pairwise ~ gen*Shade)
medias.Shade.gen
## $emmeans
##  gen   Shade         emmean    SE  df lower.CL upper.CL
##  CCN51 C. pyriformis   1.96 0.112 150     1.74     2.18
##  TCS01 C. pyriformis   2.43 0.112 150     2.21     2.65
##  TCS19 C. pyriformis   1.83 0.112 150     1.61     2.05
##  CCN51 T. rosea        2.29 0.112 150     2.06     2.51
##  TCS01 T. rosea        2.00 0.112 150     1.77     2.22
##  TCS19 T. rosea        1.87 0.116 150     1.64     2.10
##  CCN51 T. superba      2.21 0.112 150     1.99     2.43
##  TCS01 T. superba      2.34 0.112 150     2.12     2.57
##  TCS19 T. superba      1.74 0.112 150     1.51     1.96
## 
## Results are averaged over the levels of: bloque 
## Confidence level used: 0.95 
## 
## $contrasts
##  contrast                                  estimate    SE  df t.ratio p.value
##  CCN51 C. pyriformis - TCS01 C. pyriformis  -0.4700 0.159 150  -2.961  0.0829
##  CCN51 C. pyriformis - TCS19 C. pyriformis   0.1256 0.159 150   0.791  0.9970
##  CCN51 C. pyriformis - CCN51 T. rosea       -0.3283 0.159 150  -2.069  0.4985
##  CCN51 C. pyriformis - TCS01 T. rosea       -0.0383 0.159 150  -0.242  1.0000
##  CCN51 C. pyriformis - TCS19 T. rosea        0.0878 0.161 150   0.545  0.9998
##  CCN51 C. pyriformis - CCN51 T. superba     -0.2528 0.159 150  -1.593  0.8074
##  CCN51 C. pyriformis - TCS01 T. superba     -0.3861 0.159 150  -2.433  0.2742
##  CCN51 C. pyriformis - TCS19 T. superba      0.2222 0.159 150   1.400  0.8962
##  TCS01 C. pyriformis - TCS19 C. pyriformis   0.5956 0.159 150   3.752  0.0075
##  TCS01 C. pyriformis - CCN51 T. rosea        0.1417 0.159 150   0.893  0.9931
##  TCS01 C. pyriformis - TCS01 T. rosea        0.4317 0.159 150   2.720  0.1498
##  TCS01 C. pyriformis - TCS19 T. rosea        0.5578 0.161 150   3.463  0.0194
##  TCS01 C. pyriformis - CCN51 T. superba      0.2172 0.159 150   1.369  0.9078
##  TCS01 C. pyriformis - TCS01 T. superba      0.0839 0.159 150   0.529  0.9998
##  TCS01 C. pyriformis - TCS19 T. superba      0.6922 0.159 150   4.362  0.0008
##  TCS19 C. pyriformis - CCN51 T. rosea       -0.4539 0.159 150  -2.860  0.1072
##  TCS19 C. pyriformis - TCS01 T. rosea       -0.1639 0.159 150  -1.033  0.9821
##  TCS19 C. pyriformis - TCS19 T. rosea       -0.0377 0.161 150  -0.234  1.0000
##  TCS19 C. pyriformis - CCN51 T. superba     -0.3783 0.159 150  -2.384  0.3006
##  TCS19 C. pyriformis - TCS01 T. superba     -0.5117 0.159 150  -3.224  0.0402
##  TCS19 C. pyriformis - TCS19 T. superba      0.0967 0.159 150   0.609  0.9995
##  CCN51 T. rosea - TCS01 T. rosea             0.2900 0.159 150   1.827  0.6641
##  CCN51 T. rosea - TCS19 T. rosea             0.4162 0.161 150   2.584  0.2023
##  CCN51 T. rosea - CCN51 T. superba           0.0756 0.159 150   0.476  0.9999
##  CCN51 T. rosea - TCS01 T. superba          -0.0578 0.159 150  -0.364  1.0000
##  CCN51 T. rosea - TCS19 T. superba           0.5506 0.159 150   3.469  0.0191
##  TCS01 T. rosea - TCS19 T. rosea             0.1262 0.161 150   0.783  0.9972
##  TCS01 T. rosea - CCN51 T. superba          -0.2144 0.159 150  -1.351  0.9138
##  TCS01 T. rosea - TCS01 T. superba          -0.3478 0.159 150  -2.191  0.4167
##  TCS01 T. rosea - TCS19 T. superba           0.2606 0.159 150   1.642  0.7802
##  TCS19 T. rosea - CCN51 T. superba          -0.3406 0.161 150  -2.115  0.4673
##  TCS19 T. rosea - TCS01 T. superba          -0.4739 0.161 150  -2.943  0.0870
##  TCS19 T. rosea - TCS19 T. superba           0.1344 0.161 150   0.834  0.9956
##  CCN51 T. superba - TCS01 T. superba        -0.1333 0.159 150  -0.840  0.9954
##  CCN51 T. superba - TCS19 T. superba         0.4750 0.159 150   2.993  0.0763
##  TCS01 T. superba - TCS19 T. superba         0.6083 0.159 150   3.833  0.0057
## 
## Results are averaged over the levels of: bloque 
## P value adjustment: tukey method for comparing a family of 9 estimates
cld_Shade_gen <-multcomp::cld(contrast, alpha = 0.05, Letters = LETTERS, reversed=T)
cld_Shade_gen
## Shade = C. pyriformis:
##  gen   emmean    SE  df lower.CL upper.CL .group
##  TCS01   2.43 0.112 150     2.21     2.65  A    
##  CCN51   1.96 0.112 150     1.74     2.18   B   
##  TCS19   1.83 0.112 150     1.61     2.05   B   
## 
## Shade = T. rosea:
##  gen   emmean    SE  df lower.CL upper.CL .group
##  CCN51   2.29 0.112 150     2.06     2.51  A    
##  TCS01   2.00 0.112 150     1.77     2.22  AB   
##  TCS19   1.87 0.116 150     1.64     2.10   B   
## 
## Shade = T. superba:
##  gen   emmean    SE  df lower.CL upper.CL .group
##  TCS01   2.34 0.112 150     2.12     2.57  A    
##  CCN51   2.21 0.112 150     1.99     2.43  A    
##  TCS19   1.74 0.112 150     1.51     1.96   B   
## 
## Results are averaged over the levels of: bloque 
## Confidence level used: 0.95 
## P value adjustment: tukey method for comparing a family of 3 estimates 
## significance level used: alpha = 0.05 
## NOTE: Compact letter displays can be misleading
##       because they show NON-findings rather than findings.
##       Consider using 'pairs()', 'pwpp()', or 'pwpm()' instead.
ggsave("mgalt.tiff", plot= altc, width = 16, height = 12, units= c("cm"), dpi = 1000)