Cargar librerias

library(ggplot2)
library(patchwork)
library(dplyr)
library(readr)

leer archivos

all_selected <- read_csv("All_rounds_selected.csv")
## 
## ── Column specification ────────────────────────────────────────────────────────
## cols(
##   X1 = col_double(),
##   Ronda = col_character(),
##   Fecha = col_date(format = ""),
##   ID = col_character(),
##   Clave = col_character(),
##   IgG = col_character(),
##   valor_IgG = col_double(),
##   Edad = col_double(),
##   Sexo = col_character(),
##   Riesgo = col_character(),
##   Area = col_character(),
##   Delegación = col_character(),
##   Vacunado = col_character(),
##   Vacuna = col_character(),
##   Diagnostico_COVID = col_character(),
##   Metodo = col_character(),
##   Fecha_diagnostico = col_character(),
##   dias_postinfeccion = col_double(),
##   Factores_riesgo = col_character()
## )
all_selected
## # A tibble: 262 x 19
##       X1 Ronda Fecha      ID      Clave IgG   valor_IgG  Edad Sexo  Riesgo Area 
##    <dbl> <chr> <date>     <chr>   <chr> <chr>     <dbl> <dbl> <chr> <chr>  <chr>
##  1     1 D0    2021-01-13 Anny N… CR20… nega…    0.0392    23 Feme… Inter… Soco…
##  2     2 D0    2021-01-13 Omar M… CR20… nega…    0.0422    23 Masc… Alto   Soco…
##  3     3 D0    2021-01-13 Pedro … CR20… nega…    0.0768    30 Masc… Inter… Soco…
##  4     4 D0    2021-01-13 Eduard… CR20… nega…    0.0552    25 Masc… Alto   Soco…
##  5     5 D0    2021-01-13 Mauric… CR20… nega…    0.0758    37 Masc… Inter… Soco…
##  6     6 D0    2021-01-13 Edgar … CR20… nega…    0.0958    45 Masc… Inter… Soco…
##  7     7 D0    2021-01-13 Diana … CR20… nega…    0.0528    24 Feme… Inter… Soco…
##  8     8 D0    2021-01-13 Daniel… CR20… nega…    0.0828    40 Masc… Alto   Soco…
##  9     9 D0    2021-01-13 Juan P… CR20… nega…    0.0362    24 Masc… Alto   Soco…
## 10    10 D0    2021-01-13 Rene H… CR20… nega…    0.0368    45 Masc… Alto   Soco…
## # … with 252 more rows, and 8 more variables: Delegación <chr>, Vacunado <chr>,
## #   Vacuna <chr>, Diagnostico_COVID <chr>, Metodo <chr>,
## #   Fecha_diagnostico <chr>, dias_postinfeccion <dbl>, Factores_riesgo <chr>

Graficas de muestreo

muestras_area <- ggplot(data=all_selected, aes(x= Fecha, fill= Area)) +
          geom_histogram(colour="grey") +
          theme(legend.spacing.x= unit(10, 'cm')) +
          theme_bw(base_size = 12) +
          labs(title="Toma de muestras", y="Número de Muestras", x="")

muestras_area

# ggsave(plot = muestras_area, 
#        filename = "tomademuestras_por_area.png", 
#        width = 7,
#        height = 4,
#        dpi = 300)
order_riesgo <- c("Alto", "Intermedio", "Bajo")

Toma_riesgo <- ggplot(all_selected, 
                      aes(x= Fecha, 
                          fill= factor(Riesgo, levels = order_riesgo))) +
          geom_histogram(colour="grey") +
          theme(legend.spacing.x= unit(10, 'cm')) +
          scale_fill_manual(values = c("orangered", "royalblue1", "springgreen")) +
          theme_bw(base_size = 12) +
          labs(title="Riesgo", y="Número de Muestras", x="", fill= "") 
          
Toma_riesgo

# ggsave(plot = Toma_riesgo, 
#        filename = "tomademuestras_por_Riesgo.png", 
#        width = 7,
#        height = 4,
#        dpi = 300)          

Pie Charts

num_sexo <- all_selected %>%
          filter(Ronda != "D0") %>% 
   group_by(Sexo) %>% 
   summarise(n = n())

num_sexo
## # A tibble: 2 x 2
##   Sexo          n
##   <chr>     <int>
## 1 Femenino     56
## 2 Masculino    92
sexo_Pie <- num_sexo %>%
  ggplot() +
  geom_col(aes(x= 1, y= n, # para que funcione como pie chart debes poner x=1
               fill= factor(Sexo)),
               position = "fill") +
  coord_polar(theta = "y") +
  labs(title= "", fill="Sexo") +
  theme_bw() +
  theme(plot.title = element_text(size = 22, hjust = 0.5)) +
  theme(axis.title = element_blank(),
        axis.text = element_blank(),
        axis.ticks = element_blank(),
        panel.grid.major = element_blank(),
        panel.grid.minor = element_blank(),
        panel.border = element_blank())

sexo_Pie

Porcentaje de muestras por delegación

num_delegacion <- all_selected %>%
          filter(Ronda != "D0") %>% 
   group_by(Delegación) %>% 
   summarise(n = n())

num_delegacion
## # A tibble: 4 x 2
##   Delegación     n
##   <chr>      <int>
## 1 Cuautla       10
## 2 Cuernavaca   107
## 3 Jojutla       26
## 4 <NA>           5
data <- num_delegacion %>% 
  arrange(desc(Delegación)) %>%
  mutate(prop = n/ sum(num_delegacion$n) *100) %>%
  mutate(ypos = cumsum(prop)- 0.5*prop )

delegacion_Pie <- num_delegacion %>%
  ggplot() +
  geom_col(aes(x= 1, y= n, # para que funcione como pie chart debes poner x=1
               fill= factor(Delegación)),
               position = "fill") +
  #geom_text(aes(x = n, y = ypos, label = n), color = "white", size=6) +
  coord_polar(theta = "y", start = 0) +
  labs(title= "Porcentaje de muestras por Delegación", fill="") +
  scale_fill_manual(values=c("lightgreen","skyblue","violet"), na.value = "azure2") +
  theme_bw() +
  theme(plot.title = element_text(size = 22, hjust = 0.5)) +
  theme(axis.title = element_blank(),
        axis.text = element_blank(),
        axis.ticks = element_blank(),
        panel.grid.major = element_blank(),
        panel.grid.minor = element_blank(),
        panel.border = element_blank())

delegacion_Pie

vacunados <- all_selected %>% 
          filter(Vacunado == "Sí") 

Toma_dosis <- ggplot(data= all_selected, aes(x= Fecha, fill= Vacuna)) +
          geom_histogram(colour="grey") +
          theme(legend.spacing.x= unit(10, 'cm')) +
          theme_bw(base_size = 12) +
          labs(title="Vacuna", y="Número de Muestras", x="", fill= "") 

Toma_dosis   

# ggsave(plot = Toma_dosis, 
#        filename = "tomademuestras_por_Vacuna.png", 
#        width = 7,
#        height = 4,
#        dpi = 300)   
Anticuerpos <- all_selected %>% 
          ggplot(aes(x = Ronda, y =  valor_IgG)) +
          geom_jitter(aes(shape= Diagnostico_COVID, colour= Vacunado)) +
          theme(legend.spacing.x= unit(10, 'cm')) +
          theme_bw(base_size = 12) +
          labs(title="Anticuerpos de tipo IgG", 
               y="Absorbancia", 
               x="Dosis", 
               colour= "Vacunado",
               shape= "Diagnosticado vs COVID-19") +
          geom_boxplot(alpha=0.4, outlier.shape = NA)
          
# 
Anticuerpos

# ggsave(plot = Anticuerpos,
#        filename = "Anticuerpos_IgG_boxplot_CR.png",
#        width = 7,
#        height = 4,
#        dpi = 300)
Anticuerpos1 <- all_selected %>% 
          ggplot(aes(x = Ronda, y =  valor_IgG)) +
          geom_jitter(aes(shape= Diagnostico_COVID, colour= Vacunado)) +
          geom_boxplot(alpha=0.4, outlier.shape = NA) +
          facet_wrap(.~ Sexo) +
          theme(legend.spacing.x= unit(10, 'cm')) +
          theme_bw(base_size = 12) +
          labs(title="Anticuerpos de tipo IgG", 
               y="Absorbancia", 
               x="Dosis", 
               colour= "Vacunado",
               shape= "Diagnosticado vs COVID-19") 
        
Anticuerpos1

# ggsave(plot = Anticuerpos1,
#        filename = "Anticuerpos_IgG_boxplot_CR_vacunado_sexo.png",
#        width = 7,
#        height = 4,
#        dpi = 300
# )
Anticuerpos2 <- all_selected %>% 
          ggplot(aes(x = Ronda, y =  valor_IgG)) +
          geom_jitter(aes(shape= Diagnostico_COVID, colour= Edad)) +
          theme(legend.spacing.x= unit(10, 'cm')) +
          theme_bw(base_size = 12) +
          labs(title="Anticuerpos de tipo IgG", 
               y="Absorbancia", 
               x="Dosis", 
               colour= "Edad",
               shape= "Diagnosticado vs COVID-19") +
          #scale_y_log10() +
          geom_boxplot(alpha=0.4, outlier.shape = NA)
          

Anticuerpos2

# ggsave(plot = Anticuerpos2,
#        filename = "Anticuerpos_IgG_boxplot_CR_edad.png",
#        width = 7,
#        height = 4,
#        dpi = 300)
Anticuerpos3 <- all_selected %>% 
          ggplot(aes(x = Ronda, y =  valor_IgG)) +
          geom_jitter(aes(shape= Diagnostico_COVID, colour= Factores_riesgo)) +
          geom_boxplot(alpha=0.4, outlier.shape = NA) +
          theme_bw(base_size = 12) +
          theme(legend.text = element_text(size= 8)) +
          labs(title="Anticuerpos de tipo IgG", 
               y="Absorbancia", 
               x="Dosis", 
               colour= "Factores de Riesgo",
               shape= "Diagnosticado vs COVID-19") 
          
          
          
Anticuerpos3

# ggsave(plot = Anticuerpos3,
#        filename = "Anticuerpos_IgG_boxplot_FR_CR.png",
#        width = 7,
#        height = 4,
#        dpi = 300,
#        scale = 1.5)