library(readxl)
library(tidyverse)
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ dplyr     1.1.2     ✔ readr     2.1.4
## ✔ forcats   1.0.0     ✔ stringr   1.5.0
## ✔ ggplot2   3.4.3     ✔ tibble    3.2.1
## ✔ lubridate 1.9.2     ✔ tidyr     1.3.0
## ✔ purrr     1.0.1     
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag()    masks stats::lag()
## ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
library(collapsibleTree)
library(agricolae)
DATA_FUNGICIDAS <- read_excel("DATA FUNGICIDAS.xlsx", 
    sheet = "DATA R")
collapsibleTree(DATA_FUNGICIDAS,hierarchy=c("tratamiento","dosis","dimensión","valor"))
DATA_FUNGICIDAS=DATA_FUNGICIDAS %>% mutate(porcentaje=round(((86-valor)/86*100),2))
DATA_FUNGICIDAS$dosis=paste(DATA_FUNGICIDAS$dosis, "ppm")
data_dosis=DATA_FUNGICIDAS %>% filter(dosis==c("100 ppm","10 ppm","1 ppm","0.1 ppm"))
ggplot(data_dosis,aes(y=porcentaje,x=as.factor(tratamiento),fill=as.factor(tratamiento)))+
  geom_bar(stat="identity")+
  facet_wrap(~dosis)+
  labs(title = "
       Efecto de diferentes fungicidas sobre el crecimiento micelial \nde P. palmivora a nivel in-vitro",y="Inhibición (%)",x="Tratamiento",caption = "Elaborado por: Andrea Galindo")+
  theme(plot.title=element_text(hjust=40, size=20, face='bold', color='red'))+
  theme_bw()+  guides(fill = guide_legend(title = "Fungicidas"))

mod_1=lm(porcentaje~tratamiento+tratamiento/dosis,data=data_dosis)
anova(mod_1)
## Analysis of Variance Table
## 
## Response: porcentaje
##                   Df Sum Sq Mean Sq F value    Pr(>F)    
## tratamiento        4  11750 2937.43  53.916 < 2.2e-16 ***
## tratamiento:dosis 15  43325 2888.33  53.015 < 2.2e-16 ***
## Residuals         80   4358   54.48                      
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
#comparacion medias
prueba_comp=HSD.test(y = mod_1,trt = c("tratamiento","dosis"),console = T)
## 
## Study: mod_1 ~ c("tratamiento", "dosis")
## 
## HSD Test for porcentaje 
## 
## Mean Square Error:  54.48123 
## 
## tratamiento:dosis,  means
## 
##            porcentaje       std r       se    Min    Max    Q25    Q50    Q75
## T1:0.1 ppm      7.830  3.245127 5 3.300946   3.93  12.47   6.17   7.24   9.34
## T1:1 ppm        6.796  2.148495 5 3.300946   3.66   8.95   5.87   6.94   8.56
## T1:10 ppm       5.466  2.344116 5 3.300946   2.83   8.70   4.02   4.86   6.92
## T1:100 ppm      7.504  3.329013 5 3.300946   3.56  12.17   5.23   7.72   8.84
## T2:0.1 ppm      1.574  3.519571 5 3.300946   0.00   7.87   0.00   0.00   0.00
## T2:1 ppm        1.590  3.555348 5 3.300946   0.00   7.95   0.00   0.00   0.00
## T2:10 ppm      28.044  8.334106 5 3.300946  15.30  37.78  25.91  29.42  31.81
## T2:100 ppm    100.000  0.000000 5 3.300946 100.00 100.00 100.00 100.00 100.00
## T3:0.1 ppm      6.460  2.065297 5 3.300946   3.55   9.28   5.92   6.50   7.05
## T3:1 ppm        0.000  0.000000 5 3.300946   0.00   0.00   0.00   0.00   0.00
## T3:10 ppm      24.026 28.603064 5 3.300946   3.94  71.50   5.47   8.84  30.38
## T3:100 ppm      2.588  5.786944 5 3.300946   0.00  12.94   0.00   0.00   0.00
## T4:0.1 ppm      7.464  4.262438 5 3.300946   0.00  10.33   7.95   9.35   9.69
## T4:1 ppm       12.102  1.857625 5 3.300946  10.00  14.74  11.05  11.59  13.13
## T4:10 ppm      10.680  3.212164 5 3.300946   5.33  13.67  10.71  11.14  12.55
## T4:100 ppm      6.020  3.673200 5 3.300946   0.00   9.81   5.73   7.05   7.51
## T5:0.1 ppm      0.000  0.000000 5 3.300946   0.00   0.00   0.00   0.00   0.00
## T5:1 ppm       12.538  5.296647 5 3.300946   4.73  19.48  11.51  13.16  13.81
## T5:10 ppm      43.738  1.062342 5 3.300946  42.34  45.05  43.03  44.03  44.24
## T5:100 ppm     51.084  5.737005 5 3.300946  42.05  56.64  49.36  52.53  54.84
## 
## Alpha: 0.05 ; DF Error: 80 
## Critical Value of Studentized Range: 5.183444 
## 
## Minimun Significant Difference: 17.11027 
## 
## Treatments with the same letter are not significantly different.
## 
##            porcentaje groups
## T2:100 ppm    100.000      a
## T5:100 ppm     51.084      b
## T5:10 ppm      43.738     bc
## T2:10 ppm      28.044     cd
## T3:10 ppm      24.026     de
## T5:1 ppm       12.538    def
## T4:1 ppm       12.102    def
## T4:10 ppm      10.680     ef
## T1:0.1 ppm      7.830     ef
## T1:100 ppm      7.504     ef
## T4:0.1 ppm      7.464     ef
## T1:1 ppm        6.796      f
## T3:0.1 ppm      6.460      f
## T4:100 ppm      6.020      f
## T1:10 ppm       5.466      f
## T3:100 ppm      2.588      f
## T2:1 ppm        1.590      f
## T2:0.1 ppm      1.574      f
## T3:1 ppm        0.000      f
## T5:0.1 ppm      0.000      f
letras=prueba_comp$groups[,2]
#length(letras)
dosis_res=data_dosis %>% 
  group_by(tratamiento,dosis)%>%
  summarise(por=mean(porcentaje),
            err=sd(porcentaje)) %>%
  arrange(desc(por))
## `summarise()` has grouped output by 'tratamiento'. You can override using the
## `.groups` argument.
dosis_res$letras=letras
dosis_res %>%
  ggplot(aes(y=por,x=tratamiento,fill=as.factor(tratamiento)))+
  geom_bar(stat="identity")+
  geom_errorbar(aes(ymin=por,ymax=por+err),width=0.1)+ geom_text(aes(x=tratamiento,y=por+err+5,label=letras),size=3)+
  labs(title = "Efecto de diferentes fungicidas sobre el crecimiento micelial \nde P. palmivora a nivel in-vitro",y="Inhibición (%)",x="Tratamiento",caption = "Elaborado por: Andrea Galindo")+
  facet_wrap(~dosis)+
  scale_color_brewer (palette= 'Set2')+
  theme_bw() + guides(fill = guide_legend(title = "Tratamiento"))+ theme(plot.title=element_text(hjust=0.5, size=12, face='bold', color='black'),axis.title=element_text(size=10,face="bold"))+
  scale_fill_hue(labels = c("Antracol", "Javari","Rainbow","Ranman","Sideral"))