library(readxl)
df <- read_excel("C:/Users/User/Downloads/DATOS LECHUGAS.xlsx")
df
## # A tibble: 64 × 10
##    MUESTREO   DDT TRATAMIENTO LONGITUD_RAIZ PESO_FRESCO NO_HOJAS ANCHO_HOJA
##       <dbl> <dbl> <chr>               <dbl>       <dbl>    <dbl>      <dbl>
##  1        1    25 CONTROL              22           7.5        7       2.5 
##  2        1    25 CONTROL              15           4.5        7       2.3 
##  3        1    25 CONTROL              23          11          7       2.25
##  4        1    25 CONTROL              16           7          7       2.5 
##  5        1    25 CONTROL              16           6          7       2.5 
##  6        1    25 CONTROL              16.5         3.5        6       2.3 
##  7        1    25 CONTROL              23.5         9          7       2.9 
##  8        1    25 CONTROL              23.1         8          6       2.5 
##  9        1    25 ORGANICO             16           3.5        7       3   
## 10        1    25 ORGANICO             22           3.5        6       2   
## # ℹ 54 more rows
## # ℹ 3 more variables: LARGO_HOJA <dbl>, AREA_HOJA <dbl>, DENSIDAD_RAICES <dbl>
library(agricolae)
mod <- aov(LONGITUD_RAIZ~TRATAMIENTO*DDT, df)
summary(mod)
##                 Df Sum Sq Mean Sq F value   Pr(>F)    
## TRATAMIENTO      3  306.7   102.2   3.116   0.0332 *  
## DDT              1 1705.7  1705.7  51.988 1.55e-09 ***
## TRATAMIENTO:DDT  3   25.1     8.4   0.255   0.8571    
## Residuals       56 1837.3    32.8                     
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
comparison<- LSD.test(mod,c("TRATAMIENTO"),alpha=0.01,group=TRUE)
print(comparison$groups)
##           LONGITUD_RAIZ groups
## MINERAL         30.1875      a
## COMBINADO       26.6875     ab
## CONTROL         24.9750     ab
## ORGANICO        24.6875      b
library(ggplot2)
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
library(ggtext)
## Warning: package 'ggtext' was built under R version 4.3.3
p1 <- df%>%
 group_by(TRATAMIENTO,DDT)%>%
  summarise(media_trt=mean(LONGITUD_RAIZ),
            minimo=min(LONGITUD_RAIZ),
            maximo=max(LONGITUD_RAIZ)) %>% 
  
  ggplot(aes(x=DDT, y=media_trt, color=TRATAMIENTO))+
  geom_line(size=1, linetype=1)+
  geom_point()+
  theme(plot.title = element_markdown())+
  labs(x = 'Días Después de Transplante', 
       y = 'Longitud de raíces (cm)',
       color="TRATAMIENTOS")+
  theme_minimal() +
  theme(plot.title = element_text(hjust = 0.5))
## `summarise()` has grouped output by 'TRATAMIENTO'. You can override using the
## `.groups` argument.
## Warning: Using `size` aesthetic for lines was deprecated in ggplot2 3.4.0.
## ℹ Please use `linewidth` instead.
## This warning is displayed once every 8 hours.
## Call `lifecycle::last_lifecycle_warnings()` to see where this warning was
## generated.
p1

# Reordenar los niveles del factor Tratamiento
df$TRATAMIENTO <- factor(df$TRATAMIENTO, 
                            levels = c("CONTROL", "ORGANICO",
                                       "MINERAL", "COMBINADO"))

library(ggplot2)
library(dplyr)
letra <- c("ab","b","a","ab")
p2 <- df%>%
  group_by(TRATAMIENTO)%>%
  summarise(media_trt=mean(LONGITUD_RAIZ),
            minimo=min(LONGITUD_RAIZ),
            maximo=max(LONGITUD_RAIZ)) %>% 
  
  ggplot(aes(x=TRATAMIENTO, y=media_trt, fill=TRATAMIENTO))+
  geom_bar(stat="identity", position = "dodge")+
  scale_fill_manual(values=c('#333333','#666666','#999999','#E6E6E6')) +
  geom_text(aes(label=letra),
          position=position_dodge(width = 0), vjust=8)+
  geom_errorbar(aes(ymin=minimo, ymax=maximo), width=0.2, color='black',
                position="dodge")+
  labs(x = 'Tratamientos', 
       y = 'Longitud de las raíces (cm)') +
  theme_minimal()  
p2

p2 <- p2+theme(axis.text.x = element_blank(),
        axis.ticks.x = element_blank())
p2

library(agricolae)
mod <- aov(PESO_FRESCO~TRATAMIENTO*DDT, df)
summary(mod)
##                 Df Sum Sq Mean Sq F value   Pr(>F)    
## TRATAMIENTO      3   1024     341   35.98 4.29e-13 ***
## DDT              1   4368    4368  460.45  < 2e-16 ***
## TRATAMIENTO:DDT  3    576     192   20.24 5.19e-09 ***
## Residuals       56    531       9                     
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
comparison<- LSD.test(mod,c("TRATAMIENTO"),alpha=0.01,group=TRUE)
print(comparison$groups)
##           PESO_FRESCO groups
## MINERAL      19.20000      a
## COMBINADO    16.85625      a
## CONTROL      12.40000      b
## ORGANICO      8.83750      c
p3 <- df%>%
 group_by(TRATAMIENTO,DDT)%>%
  summarise(media_trt=mean(PESO_FRESCO),
            minimo=min(PESO_FRESCO),
            maximo=max(PESO_FRESCO)) %>% 
  
  ggplot(aes(x=DDT, y=media_trt, color=TRATAMIENTO))+
  geom_line(size=1, linetype=1)+
  geom_point()+
  theme(plot.title = element_markdown())+
  labs(x = 'Días Después de Transplante', 
       y = 'Peso fresco (g)',
       color="TRATAMIENTOS")+
  theme_minimal() +
  theme(plot.title = element_text(hjust = 0.2))
## `summarise()` has grouped output by 'TRATAMIENTO'. You can override using the
## `.groups` argument.
p3

# Reordenar los niveles del factor Tratamiento
df$TRATAMIENTO <- factor(df$TRATAMIENTO, 
                            levels = c("CONTROL", "ORGANICO",
                                       "MINERAL", "COMBINADO"))

library(ggplot2)
library(dplyr)
letra <- c("b","c","a","a")
p4 <- df%>%
  group_by(TRATAMIENTO)%>%
  summarise(media_trt=mean(PESO_FRESCO),
            minimo=min(PESO_FRESCO),
            maximo=max(PESO_FRESCO)) %>% 
  
  ggplot(aes(x=TRATAMIENTO, y=media_trt, fill=TRATAMIENTO))+
  geom_bar(stat="identity", position = "dodge")+
  scale_fill_manual(values=c('#333333','#666666','#999999','#E6E6E6')) +
  geom_text(aes(label=letra),
          position=position_dodge(width = 0), vjust=2, hjust=2)+
  geom_errorbar(aes(ymin=minimo, ymax=maximo), width=0.2, color='black',
                position="dodge")+
  labs(x = 'Tratamientos', 
       y = 'Peso fresco (g)') +
  theme_minimal()  
p4

p4 <- p4+theme(axis.text.x = element_blank(),
        axis.ticks.x = element_blank())
p4

p5 <- df%>%
 group_by(TRATAMIENTO,DDT)%>%
  summarise(media_trt=mean(NO_HOJAS),
            minimo=min(NO_HOJAS),
            maximo=max(NO_HOJAS)) %>% 
  
  ggplot(aes(x=DDT, y=media_trt, color=TRATAMIENTO))+
  geom_line(size=1, linetype=1)+
  geom_point()+
  theme(plot.title = element_markdown())+
  labs(x = 'Días Después de Transplante', 
       y = 'Número de hojas',
       color="TRATAMIENTOS")+
  theme_minimal() +
  theme(plot.title = element_text(hjust = 0.5))
## `summarise()` has grouped output by 'TRATAMIENTO'. You can override using the
## `.groups` argument.
p5

library(agricolae)
mod <- aov(NO_HOJAS~TRATAMIENTO*DDT, df)
summary(mod)
##                 Df Sum Sq Mean Sq F value   Pr(>F)    
## TRATAMIENTO      3  43.92   14.64  28.894 2.02e-11 ***
## DDT              1 192.52  192.52 379.943  < 2e-16 ***
## TRATAMIENTO:DDT  3   7.55    2.52   4.965  0.00399 ** 
## Residuals       56  28.37    0.51                     
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
comparison<- LSD.test(mod,c("TRATAMIENTO"),alpha=0.01,group=TRUE)
print(comparison$groups)
##           NO_HOJAS groups
## MINERAL     9.6250      a
## COMBINADO   9.2500     ab
## CONTROL     8.8750      b
## ORGANICO    7.4375      c
# Reordenar los niveles del factor Tratamiento
df$TRATAMIENTO <- factor(df$TRATAMIENTO, 
                            levels = c("CONTROL", "ORGANICO",
                                       "MINERAL", "COMBINADO"))

library(ggplot2)
library(dplyr)
letra <- c("b","c","a","ab")
p6 <- df%>%
  group_by(TRATAMIENTO)%>%
  summarise(media_trt=mean(NO_HOJAS),
            minimo=min(NO_HOJAS),
            maximo=max(NO_HOJAS)) %>% 
  
  ggplot(aes(x=TRATAMIENTO, y=media_trt, fill=TRATAMIENTO))+
  geom_bar(stat="identity", position = "dodge")+
  scale_fill_manual(values=c('#333333','#666666','#999999','#E6E6E6')) +
  geom_text(aes(label=letra),
          position=position_dodge(width = 0), vjust=2, hjust=2)+
  geom_errorbar(aes(ymin=minimo, ymax=maximo), width=0.2, color='black',
                position="dodge")+
  labs(x = 'Tratamientos', 
       y = 'Número de hojas') +
  theme_minimal()  
p6

p6 <- p6+theme(axis.text.x = element_blank(),
        axis.ticks.x = element_blank())
p6

library(agricolae)
mod <- aov(AREA_HOJA~TRATAMIENTO*DDT, df)
summary(mod)
##                 Df Sum Sq Mean Sq F value   Pr(>F)    
## TRATAMIENTO      3   3737    1246   14.43 4.45e-07 ***
## DDT              1   4792    4792   55.50 6.25e-10 ***
## TRATAMIENTO:DDT  3   2494     831    9.63 3.18e-05 ***
## Residuals       56   4835      86                     
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
comparison<- LSD.test(mod,c("TRATAMIENTO"),alpha=0.01,group=TRUE)
print(comparison$groups)
##           AREA_HOJA groups
## MINERAL    53.08310      a
## COMBINADO  49.55372      a
## CONTROL    38.68577      b
## ORGANICO   34.41026      b
p7 <- df%>%
 group_by(TRATAMIENTO,DDT)%>%
  summarise(media_trt=mean(AREA_HOJA),
            minimo=min(AREA_HOJA),
            maximo=max(AREA_HOJA)) %>% 
  
  ggplot(aes(x=DDT, y=media_trt, color=TRATAMIENTO))+
  geom_line(size=1, linetype=1)+
  geom_point()+
  theme(plot.title = element_markdown())+
  labs(x = 'Días Después de Transplante', 
       y = 'Área foliar (cm2)',
       color="TRATAMIENTOS")+
  theme_minimal() +
  theme(plot.title = element_text(hjust = 0.2))
## `summarise()` has grouped output by 'TRATAMIENTO'. You can override using the
## `.groups` argument.
p7

# Reordenar los niveles del factor Tratamiento
df$TRATAMIENTO <- factor(df$TRATAMIENTO, 
                            levels = c("CONTROL", "ORGANICO",
                                       "MINERAL", "COMBINADO"))

library(ggplot2)
library(dplyr)
letra <- c("b","b","a","a")
p8 <- df%>%
  group_by(TRATAMIENTO)%>%
  summarise(media_trt=mean(AREA_HOJA),
            minimo=min(AREA_HOJA),
            maximo=max(AREA_HOJA)) %>% 
  
  ggplot(aes(x=TRATAMIENTO, y=media_trt, fill=TRATAMIENTO))+
  geom_bar(stat="identity", position = "dodge")+
  scale_fill_manual(values=c('#333333','#666666','#999999','#E6E6E6')) +
  geom_text(aes(label=letra),
          position=position_dodge(width = 0), vjust=2, hjust=2)+
  geom_errorbar(aes(ymin=minimo, ymax=maximo), width=0.2, color='black',
                position="dodge")+
  labs(x = 'Tratamientos', 
       y = 'Área foliar (cm2)') +
  theme_minimal()  
p8

p8 <- p8+theme(axis.text.x = element_blank(),
        axis.ticks.x = element_blank())
p8

library(agricolae)
mod <- aov(DENSIDAD_RAICES~TRATAMIENTO*DDT, df)
summary(mod)
##                 Df Sum Sq Mean Sq F value   Pr(>F)    
## TRATAMIENTO      3 0.7853  0.2618   9.377 4.06e-05 ***
## DDT              1 3.1289  3.1289 112.074 5.57e-15 ***
## TRATAMIENTO:DDT  3 0.4765  0.1588   5.689  0.00179 ** 
## Residuals       56 1.5634  0.0279                     
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
comparison<- LSD.test(mod,c("TRATAMIENTO"),alpha=0.01,group=TRUE)
print(comparison$groups)
##           DENSIDAD_RAICES groups
## MINERAL         0.6118216      a
## COMBINADO       0.6117184      a
## CONTROL         0.4767366     ab
## ORGANICO        0.3448644      b
p9 <- df%>%
 group_by(TRATAMIENTO,DDT)%>%
  summarise(media_trt=mean(DENSIDAD_RAICES),
            minimo=min(DENSIDAD_RAICES),
            maximo=max(DENSIDAD_RAICES)) %>% 
  
  ggplot(aes(x=DDT, y=media_trt, color=TRATAMIENTO))+
  geom_line(size=1, linetype=1)+
  geom_point()+
  theme(plot.title = element_markdown())+
  labs(x = 'Días Después de Transplante', 
       y = 'Densidad radicular (g/cm)',
       color="TRATAMIENTOS")+
  theme_minimal() +
  theme(plot.title = element_text(hjust = 0.2))
## `summarise()` has grouped output by 'TRATAMIENTO'. You can override using the
## `.groups` argument.
p9

# Reordenar los niveles del factor Tratamiento
df$TRATAMIENTO <- factor(df$TRATAMIENTO, 
                            levels = c("CONTROL", "ORGANICO",
                                       "MINERAL", "COMBINADO"))

library(ggplot2)
library(dplyr)
letra <- c("ab","b","a","a")
p10 <- df%>%
  group_by(TRATAMIENTO)%>%
  summarise(media_trt=mean(DENSIDAD_RAICES),
            minimo=min(DENSIDAD_RAICES),
            maximo=max(DENSIDAD_RAICES)) %>% 
  
  ggplot(aes(x=TRATAMIENTO, y=media_trt, fill=TRATAMIENTO))+
  geom_bar(stat="identity", position = "dodge")+
  scale_fill_manual(values=c('#333333','#666666','#999999','#E6E6E6')) +
  geom_text(aes(label=letra),
          position=position_dodge(width = 0), vjust=2, hjust=2)+
  geom_errorbar(aes(ymin=minimo, ymax=maximo), width=0.2, color='black',
                position="dodge")+
  labs(x = 'Tratamientos', 
       y = 'Densidad radicular (g/cm)') +
  theme_minimal()  
p10

p10 <- p10+theme(axis.text.x = element_blank(),
        axis.ticks.x = element_blank())
p10

library(ggplot2)
library(patchwork)
## Warning: package 'patchwork' was built under R version 4.3.3
## Combinar los gráficos en una sola figura
combinado_raices <- p1+p2+p3+p4+p9+p10+
  plot_layout(ncol = 2)  # Especificar el número de columnas

# Mostrar el gráfico combinado
print(combinado_raices)

## Combinar los gráficos en una sola figura
combinado_hoja <- p5+p6+p7+p8+
  plot_layout(ncol = 2)  # Especificar el número de columnas

# Mostrar el gráfico combinado
print(combinado_hoja)