library(readxl)

ruta_excel <- "C:\\Users\\jdom3\\Desktop\\Datos tesis.xlsx"

Conteo_preventivo <- read_excel(ruta_excel, sheet = 'Preventivo - Conteo de conidias')
Conteo_preventivo
## # A tibble: 24 × 3
##    Numero_petalo Tratamiento             Conteo_conidias
##            <dbl> <chr>                             <dbl>
##  1             5 "Control\r\n"                    626000
##  2             8 "Control\r\n"                    858000
##  3            22 "Control\r\n"                    336000
##  4            39 "Control\r\n"                    392000
##  5            26 "Control comercial\r\n"          122000
##  6            28 "Control comercial\r\n"          230000
##  7            37 "Control comercial\r\n"          124000
##  8            40 "Control comercial\r\n"          598000
##  9            47 "Control comercial\r\n"          934000
## 10             3 "100 ppm"                        468000
## # ℹ 14 more rows
library(dplyr)
## 
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
## 
##     filter, lag
## The following objects are masked from 'package:base':
## 
##     intersect, setdiff, setequal, union
Conteoprevprom <- Conteo_preventivo %>%
  group_by(Tratamiento) %>%
  summarise(Conidias_por_mL= mean(Conteo_conidias))
library(ggplot2)

Grafico_conteo_preventivo <- ggplot(Conteoprevprom, aes(Tratamiento, Conidias_por_mL)) + geom_bar(width = 0.5, stat='identity') 
Grafico_conteo_preventivo

ggplot(data = Conteo_preventivo, aes(x = Tratamiento, y = Conteo_conidias, color = Tratamiento)) +
    geom_boxplot() +
    theme_bw()

anova_conteo_preventivo <- aov(Conteo_preventivo$Conteo_conidias ~ Conteo_preventivo$Tratamiento )
summary(anova_conteo_preventivo)
##                               Df    Sum Sq   Mean Sq F value Pr(>F)
## Conteo_preventivo$Tratamiento  4 4.062e+11 1.016e+11   0.829  0.523
## Residuals                     19 2.327e+12 1.225e+11
aovconprev_residuals <- residuals(object = anova_conteo_preventivo )
hist(aovconprev_residuals)

shapiro.test(x = aovconprev_residuals)
## 
##  Shapiro-Wilk normality test
## 
## data:  aovconprev_residuals
## W = 0.9614, p-value = 0.4673
plot(anova_conteo_preventivo ,2)

bartlett.test(aovconprev_residuals ~ Conteo_preventivo$Tratamiento)
## 
##  Bartlett test of homogeneity of variances
## 
## data:  aovconprev_residuals by Conteo_preventivo$Tratamiento
## Bartlett's K-squared = 2.1892, df = 4, p-value = 0.701
plot(aovconprev_residuals , pch = 20)

Tablafinalconprev<- group_by(Conteo_preventivo,Tratamiento) %>%
  summarise(mean=mean(Conteo_conidias), sd=sd(Conteo_conidias)) %>%
  arrange(desc(mean))
Tablafinalconprev
## # A tibble: 5 × 3
##   Tratamiento               mean      sd
##   <chr>                    <dbl>   <dbl>
## 1 "50 ppm"                711200 356541.
## 2 "1 ppm"                 639600 474471.
## 3 "Control\r\n"           553000 239001.
## 4 "Control comercial\r\n" 401600 355917.
## 5 "100 ppm"               389200 245004.
ggplot(Tablafinalconprev, aes(x = Tratamiento, y = mean, fill =Tratamiento)) + 
  geom_bar(stat = "identity", position = "dodge", alpha = 0.5, colour = "gray25")  +
  geom_errorbar(aes(ymin=mean-sd, ymax=mean+sd), position = position_dodge(0.9), width = 0.25,
                show.legend = FALSE, colour = "gray25") +
  labs(x="Tratamientos", y="Conidias/mL") +
  theme_bw() + 
  theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank()) +
  scale_fill_grey()