figura 1

Loading libraries

library(readr)
library(dplyr)

Adjuntando el paquete: 'dplyr'
The following objects are masked from 'package:stats':

    filter, lag
The following objects are masked from 'package:base':

    intersect, setdiff, setequal, union
library(ggplot2)
library(tidyr)
library(patchwork)

Loading dataset

getwd()
[1] "C:/Users/msantamaria/Documents/RStudio/R_docs/Tesis/Tesis MageDaniel"
df1 <- read.csv("DatosTesis_vf_Deteccion3.csv")
#df1
names(df1)
 [1] "Code"                 "Method"               "Target"              
 [4] "deteccion"            "Quantity"             "Percentil.33."       
 [7] "percentil.66."        "resultado.percentil"  "Band_Intensity"      
[10] "Expected_size_bp"     "Observed_size_bp"     "Location"            
[13] "Concentration_method" "Extraction_kit"       "Year"                
[16] "Month"                "Sketa_Inhibitors"    
table(df1$Method)

CtrlExt CtrlPos      M1      M2      M3      M4      M5      M6      M7      M8 
     12       2       8       8       8       8      32      32      24      24 
    NFW 
      4 
df1%>%select(Code, Method, Target, Detection = deteccion, Quantity, Percentile = resultado.percentil, Site = Location, ConcMet = Concentration_method, ExtKit = Extraction_kit, Year, Month)->df2
#df2
table(df1$Method, df1$resultado.percentil)
         
           0  1  2  3
  CtrlExt 12  0  0  0
  CtrlPos  0  0  1  1
  M1       8  0  0  0
  M2       7  0  1  0
  M3       6  2  0  0
  M4       4  3  1  0
  M5       7  9  9  7
  M6       5  7 14  6
  M7       9  2  3 10
  M8       5  8  2  9
  NFW      4  0  0  0
df2%>% filter(Year == 2023, !is.na(Site))->df2f
#df2f
#table(df2f$Method, df2f$Percentile,df2f$Target)
df2f%>%filter(Site == "UTEC", Target != "16S")->df_UTEC
#df_UTEC
df2f%>%filter(Site == "UPCH", Target != "16S")->df_UPCH
#df_UPCH
fig1UTEC <- ggplot(df_UTEC, aes(x=Method, y=Percentile,fill = Target)) +
  geom_col(position ="dodge")+
  scale_fill_manual(values = c(
    "CTX" = "blue",
    "KPC" = "red",
    "NDM" = "yellow"),
    name = NULL)+
  ylim(0,3)+
  labs(x = "Método",
       y = "Nivel de detección")+
  theme_minimal()+
  theme(legend.position = "top")

#fig1UTEC
fig1UPCH <- ggplot(df_UPCH, aes(x=Method, y=Percentile,fill = Target)) +
  geom_col(position ="dodge")+
  scale_fill_manual(values = c(
    "CTX" = "blue",
    "KPC" = "red",
    "NDM" = "yellow"),
    name = NULL)+
  ylim(0,3)+
  labs(x = "Método",
       y = NULL)+
  theme_minimal()+
  theme(legend.position = "top")

#fig1UPCH
fig1 <- fig1UTEC + fig1UPCH + plot_annotation(tag_levels = c("A","B"))
fig1

ggsave("figure1.tiff"
       , plot = fig1
       , device = "tiff"
       , width = 8
       , height = 4
       , units = "in"
       , dpi = 300
       )
df2%>% filter(Year != "2023", !is.na(Site), Target != "16S", !Method %in% c("M7", "M8"))->df3f
#df3f
table(df3f$Method,df3f$Percentile)
    
     0 1 2 3
  M5 4 4 4 6
  M6 2 4 7 5
df3f <- df3f %>% mutate(date = factor(paste(Month, Year, sep = "/")))
#df3f
df3f%>%filter(Site == "UTEC", date == "Jun/2024") ->df_UTEC_Jun24
#df_UTEC_Jun24
df3f%>%filter(Site == "UTEC", date == "Feb/2025") ->df_UTEC_Feb25
#df_UTEC_Feb25
df3f%>%filter(Site == "UTEC", date == "Abr/2025") ->df_UTEC_Abr25
#df_UTEC_Abr25
df3f%>%filter(Site == "UPCH", date == "Abr/2025") ->df_UPCH_Abr25
#df_UPCH_Abr25
df3f%>%filter(Site == "UPCH", date == "Feb/2025") ->df_UPCH_Feb25
#df_UPCH_Feb25
df3f%>%filter(Site == "UPCH", date == "Jun/2024") ->df_UPCH_Jun24
#df_UPCH_Jun24
fig2_A <- ggplot(df_UTEC_Jun24, aes(x=Method, y=Percentile,fill = Target)) +
  geom_col(position ="dodge")+
  scale_fill_manual(values = c(
    "CTX" = "blue",
    "KPC" = "red",
    "NDM" = "yellow"),
    name = NULL)+
  ylim(0,3)+
  labs(x = "Método",
       y = "Nivel de detección")+
  theme_minimal()+
  theme(legend.position = "top")

fig2_B <- ggplot(df_UTEC_Feb25, aes(x=Method, y=Percentile,fill = Target)) +
  geom_col(position ="dodge")+
  scale_fill_manual(values = c(
    "CTX" = "blue",
    "KPC" = "red",
    "NDM" = "yellow"),
    name = NULL)+
  ylim(0,3)+
  labs(x = "Método",
       y = "Nivel de detección")+
  theme_minimal()+
  theme(legend.position = "top")

fig2_C <- ggplot(df_UTEC_Abr25, aes(x=Method, y=Percentile,fill = Target)) +
  geom_col(position ="dodge")+
  scale_fill_manual(values = c(
    "CTX" = "blue",
    "KPC" = "red",
    "NDM" = "yellow"),
    name = NULL)+
  ylim(0,3)+
  labs(x = "Método",
       y = "Nivel de detección")+
  theme_minimal()+
  theme(legend.position = "top")


fig2_D <- ggplot(df_UPCH_Jun24, aes(x=Method, y=Percentile,fill = Target)) +
  geom_col(position ="dodge")+
  scale_fill_manual(values = c(
    "CTX" = "blue",
    "KPC" = "red",
    "NDM" = "yellow"),
    name = NULL)+
  ylim(0,3)+
  labs(x = "Método",
       y = "Nivel de detección")+
  theme_minimal()+
  theme(legend.position = "top")


fig2_E <- ggplot(df_UPCH_Feb25, aes(x=Method, y=Percentile,fill = Target)) +
  geom_col(position ="dodge")+
  scale_fill_manual(values = c(
    "CTX" = "blue",
    "KPC" = "red",
    "NDM" = "yellow"),
    name = NULL)+
  ylim(0,3)+
  labs(x = "Método",
       y = "Nivel de detección")+
  theme_minimal()+
  theme(legend.position = "top")


fig2_F <- ggplot(df_UPCH_Abr25, aes(x=Method, y=Percentile,fill = Target)) +
  geom_col(position ="dodge")+
  scale_fill_manual(values = c(
    "CTX" = "blue",
    "KPC" = "red",
    "NDM" = "yellow"),
    name = NULL)+
  ylim(0,3)+
  labs(x = "Método",
       y = "Nivel de detección")+
  theme_minimal()+
  theme(legend.position = "top")


fig2_A + fig2_B + fig2_C + fig2_D + fig2_E + fig2_F + plot_annotation(tag_levels = c("A","B", "C", "D", "E", "F"))