Carga de librerías

library(ggplot2)
library(ggthemes)
library(ggthemr)
library(patchwork)
library(ggtech)
library(ggtext)
library(plotly)
## 
## Adjuntando el paquete: 'plotly'
## The following object is masked from 'package:ggplot2':
## 
##     last_plot
## The following object is masked from 'package:stats':
## 
##     filter
## The following object is masked from 'package:graphics':
## 
##     layout
library(plotrix)
library(RColorBrewer)
library(ggpubr)
## 
## Adjuntando el paquete: 'ggpubr'
## The following objects are masked from 'package:ggthemr':
## 
##     rotate_x_text, rotate_y_text
library(sjPlot)
## Learn more about sjPlot with 'browseVignettes("sjPlot")'.
library(ggpmisc)
## Cargando paquete requerido: ggpp
## Registered S3 methods overwritten by 'ggpp':
##   method                  from   
##   heightDetails.titleGrob ggplot2
##   widthDetails.titleGrob  ggplot2
## 
## Adjuntando el paquete: 'ggpp'
## The following objects are masked from 'package:ggpubr':
## 
##     as_npc, as_npcx, as_npcy
## The following object is masked from 'package:ggplot2':
## 
##     annotate
library(doBy)
library(readxl)
library(xlsx)

Carga de base de datos para graficar

datos <- read_xlsx("datos_visualizacion.xlsx")
dim(datos)
## [1] 24  5
head(datos)
## # A tibble: 6 × 5
##   material   rep ambiente rinde proteina
##   <chr>    <dbl> <chr>    <dbl>    <dbl>
## 1 hibrido3     1 A        4637.       20
## 2 hibrido7     1 A        5385.        5
## 3 hibrido1     1 A        5803.       17
## 4 hibrido6     1 A        5018.        4
## 5 hibrido2     1 A        5441.       21
## 6 hibrido4     1 A        4246.       27
which(is.na(datos))
## integer(0)
range(datos$rinde)
## [1] 3087.719 6569.051
datos$material <- as.factor(datos$material)
datos$ambiente <- as.factor(datos$ambiente)
media_rinde <- mean(datos$rinde)

La base de datos contiene 5 columnas y 28 observaciones.

Gráfico de barras

ggplot(data = datos, aes(material, rinde, fill = material)) +
  geom_bar( width = 0.4, stat = "identity", alpha=0.4)+
  ggtitle("Diagrama de barras")  + 
  scale_fill_manual(values=c('#999999','#E69F00', "lightgreen", "#E25539",
                             "#378963", "#64794666", "#699633", "#968563",
                             "#02689123", "#66631966", "#896687", "#888301"))+
  ylab("Rendimiento (kg/ha)")+
  xlab("Materiales")+
  geom_text(aes(x = 3, y = 6000,size=10,fontface="bold",colour = "red",
                label = "4863.4 kg/ha"))+
  geom_hline(yintercept = media_rinde, linetype="dashed",
             linewidth=1.3, color="red")+
  labs(caption = "Figura 1: Gráfico de barras del rendimiento en función de
       los diferentes materiales evaluados a campo.")+
  theme_few()+
  guides(fill = guide_legend(title = "Rendimiento\nde materiales"))+
  theme(axis.text.x = element_text(size = 13),
        axis.text.y = element_text(size = 11),
        axis.title.x = element_text(size = 12),
        axis.title.y = element_text(size = 12),
        legend.position = "none",
        plot.caption = element_text(hjust = 0.5, size = 13, color = "grey"))

Gráfico de cajas o box-plot

ggplot(datos,aes(material, rinde, fill=material))+
  geom_boxplot(alpha=0.5)+
  geom_jitter()+
  scale_fill_hue(c=40)+
  xlab("Material")+
  ylab("Rendimiento")+
  facet_grid(~ambiente)+
  labs(caption = "Figura 2: Gráfico de cajas del rendimiento en función de
       los diferentes materiales evaluados a campo.")+
  guides(fill = guide_legend(title = "Materiales"))+
  theme_sjplot2()+
  theme(axis.text.x = element_text(face = "italic", size = 8, 
                                   color = "black", angle = 0),
        axis.text.y = element_text(face = "italic",size = 11),
        axis.title.x = element_text(face = "bold.italic",size = 11),
        axis.title.y = element_text(face = "bold.italic",size = 11),
        legend.title = element_text(face = "bold.italic"),
        strip.background = element_rect(fill = "lightblue"),
        strip.text = element_text(size = 12, face = "bold"),
        panel.background = element_rect(fill = "lightyellow"),
        panel.border = element_rect(fill = "transparent",  
                                    color = 1,           
                                    linewidth = 0.5), 
        legend.background = element_rect(fill =  "pink"),
        legend.text.align = 0.5, 
        legend.justification = "left",
        legend.text = element_text(hjust = 2),
        plot.caption = element_text(hjust = 0.5, size = 13, color = "grey"))
## Warning: The `legend.text.align` argument of `theme()` is deprecated as of ggplot2
## 3.5.0.
## ℹ Please use theme(legend.text = element_text(hjust)) instead.
## This warning is displayed once every 8 hours.
## Call `lifecycle::last_lifecycle_warnings()` to see where this warning was
## generated.

Gráfico de dispersión

ggplot(datos,aes(proteina, rinde))+
  geom_point(size=2)+
  scale_fill_hue(c=40)+
  xlab("Contenido de Proteína")+
  ylab("Rendimiento (Kg/ha)")+
  facet_grid(~ambiente)+
  labs(caption = "Figura 3: Gráfico de dispersión del rendimiento en función del
       contenido de proteína de los diferentes materiales evaluados a campo.")+
  guides(fill = guide_legend(title = "Materiales"))+
  geom_smooth(se=F, method = "lm", col="lightgreen")+
  stat_poly_eq(use_label(c("eq", "adj.R2", "p", "n")), size=3, label.y = 7200) +
  stat_cor(label.x = 5, label.y = 6100, size=3) +
  theme_sjplot2()+
  theme(axis.text.x = element_text(face = "italic", size = 8, 
                                   color = "black", angle = 0),
        axis.text.y = element_text(face = "italic",size = 8),
        axis.title.x = element_text(face = "bold.italic",size = 11),
        axis.title.y = element_text(face = "bold.italic",size = 11),
        legend.title = element_text(face = "bold.italic"),
        strip.background = element_rect(fill = "lightblue"),
        strip.text = element_text(size = 12, face = "bold"),
        panel.background = element_rect(fill = "white"),
        panel.border = element_rect(fill = "transparent",  
                                    color = 1,           
                                    linewidth = 0.5), 
        legend.background = element_rect(fill =  "pink"),
        legend.text.align = 0.5, 
        legend.justification = "left",
        legend.text = element_text(hjust = 2),
        plot.caption = element_text(hjust = 0.5, size = 13, color = "grey"),
        legend.position = "none")
## `geom_smooth()` using formula = 'y ~ x'

Gráfico de líneas o perfiles

datos2 <- read_xlsx("data_lineas.xlsx")
datos2$tratamiento <- as.factor(datos2$tratamiento)
dim(datos2)
## [1] 60  4
head(datos2)
## # A tibble: 6 × 4
##     dda tratamiento mortalidad_acum mortalidad
##   <dbl> <fct>                 <dbl>      <dbl>
## 1     3 BB3                    23.2       23.2
## 2     3 BB3                     8.8        8.8
## 3     3 BB3                    16.4       16.4
## 4     3 BB3                    12.8       12.8
## 5     3 BB5                    10.4       10.4
## 6     3 BB5                    11.2       11.2
datos2 <- summaryBy(mortalidad ~ tratamiento + dda, data = datos2,FUN = mean)
colnames(datos2) <- c("tratamiento", "dda", "mortalidad")
datos2
## # A tibble: 15 × 3
##    tratamiento   dda mortalidad
##    <fct>       <dbl>      <dbl>
##  1 BB3             3       15.3
##  2 BB3             9       20.1
##  3 BB3            14       18.4
##  4 BB5             3       21.3
##  5 BB5             9       25.3
##  6 BB5            14       22.1
##  7 PRO3            3       10.3
##  8 PRO3            9        7.8
##  9 PRO3           14       13.1
## 10 PRO5            3       10  
## 11 PRO5            9        9.4
## 12 PRO5           14       14.6
## 13 Testigo         3        1.1
## 14 Testigo         9        1.5
## 15 Testigo        14        6.4
ggplot(datos2, aes(factor(dda), mortalidad, col=tratamiento)) +
  geom_point(aes(size=0.5),stat = "identity",position = "identity")+
  geom_line(linewidth=0.7,aes(group = tratamiento))+
  scale_colour_brewer(palette = "Set2")+
  geom_label(aes(x=factor(dda), label = tratamiento, group=factor(dda)), 
            position = position_dodge(width = 0.7), size=2, 
            vjust=-1, hjust=1 ,col="black")+
  geom_vline(xintercept = 5 , linetype ="dashed", color ="red", 
             linewidth = 0.6)+
  labs(fill="Tratamiento", caption = "Figura 4: Gráfico de perfiles de la mortalidad
       de los insectos en función del tratamiento aplicado a campo.")+
  ylab("Mortalidad (%)")+
  xlab("Días después de la aplicación")+
  ylim(0,30)+
  theme_sjplot()+
  theme(axis.text.x = element_text(face = "italic", size = 8, 
                                   color = "black", angle = 0),
        axis.text.y = element_text(face = "italic",size = 8),
        axis.title.x = element_text(face = "bold.italic",size = 11),
        axis.title.y = element_text(face = "bold.italic",size = 11),
        legend.title = element_text(face = "bold.italic"),
        strip.background = element_rect(fill = "lightblue"),
        strip.text = element_text(size = 12, face = "bold"),
        panel.background = element_rect(fill = "white"),
        panel.border = element_rect(fill = "transparent",  
                                    color = 1,           
                                    linewidth = 0.5), 
        legend.background = element_rect(fill =  "pink"),
        legend.text.align = 0.5, 
        legend.justification = "left",
        legend.text = element_text(hjust = 2),
        plot.caption = element_text(hjust = 0.5, size = 13, color = "grey"),
        legend.position = "none")