if(!require("pacman"))
  install.packages("pacman")
## Cargando paquete requerido: pacman
## Warning: package 'pacman' was built under R version 4.5.2
if(!require("tidyr"))
  install.packages("tidyr")
## Cargando paquete requerido: tidyr
library("pacman")
p_load("ggplot2",  
       "dplyr",
       "vroom")
Datos_PCRa <- vroom(file="https://raw.githubusercontent.com/ManuelLaraMVZ/Metabolomica_2026_1/refs/heads/main/Amplificacion_ambos%20grupos.csv")
## Rows: 51 Columns: 9
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## dbl (9): Cycle, 50 ng, 10 ng, 5 ng, 1 ng, 0.5 ng, 0.1 ng, G1-M, G2-M
## 
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
Datos_PCRa
## # A tibble: 51 × 9
##    Cycle `50 ng` `10 ng` `5 ng` `1 ng` `0.5 ng` `0.1 ng` `G1-M`  `G2-M`
##    <dbl>   <dbl>   <dbl>  <dbl>  <dbl>    <dbl>    <dbl>  <dbl>   <dbl>
##  1     1    21.3   0.124 -2.25    2.06   -1.78    -2.32    22.1 -0.184 
##  2     2    27.9   1.39   2.61    8.66    5.96     2.18    92.0  8.29  
##  3     3    34.5  -0.660 11.4    12.2     5.94     2.34   132.   3.73  
##  4     4    56.6   1.000  1.87    6.49    5.20     1.05   164.   3.20  
##  5     5    65.2  -0.484 -1.18    1.77   -5.23     0.606  184.   0.557 
##  6     6    72.3   1.44  -0.477   2.35   -0.958    4.81   214.   0.0300
##  7     7    89.1  -5.10  -3.87   -4.93   -3.60    -4.87   249.  -7.37  
##  8     8   101.   -1.67  -3.52   -3.31   -2.34     0.403  277.  -6.98  
##  9     9   114.    2.66   5.35   -2.11   -1.40    -0.659  302.  -3.63  
## 10    10   123.   13.6   10.4    -5.98    2.27     1.13   332.  -1.16  
## # ℹ 41 more rows
Curvas_PCRa <- Datos_PCRa %>% 
  rename_with(~ sub("^(\\d+)$", "var\\1", .x))

Curvas_PCRa
## # A tibble: 51 × 9
##    Cycle `50 ng` `10 ng` `5 ng` `1 ng` `0.5 ng` `0.1 ng` `G1-M`  `G2-M`
##    <dbl>   <dbl>   <dbl>  <dbl>  <dbl>    <dbl>    <dbl>  <dbl>   <dbl>
##  1     1    21.3   0.124 -2.25    2.06   -1.78    -2.32    22.1 -0.184 
##  2     2    27.9   1.39   2.61    8.66    5.96     2.18    92.0  8.29  
##  3     3    34.5  -0.660 11.4    12.2     5.94     2.34   132.   3.73  
##  4     4    56.6   1.000  1.87    6.49    5.20     1.05   164.   3.20  
##  5     5    65.2  -0.484 -1.18    1.77   -5.23     0.606  184.   0.557 
##  6     6    72.3   1.44  -0.477   2.35   -0.958    4.81   214.   0.0300
##  7     7    89.1  -5.10  -3.87   -4.93   -3.60    -4.87   249.  -7.37  
##  8     8   101.   -1.67  -3.52   -3.31   -2.34     0.403  277.  -6.98  
##  9     9   114.    2.66   5.35   -2.11   -1.40    -0.659  302.  -3.63  
## 10    10   123.   13.6   10.4    -5.98    2.27     1.13   332.  -1.16  
## # ℹ 41 more rows
Curvas_PCRa <- Datos_PCRa %>% 
  mutate(Ciclos = Cycle, SJM = `50 ng`, AVY = `10 ng`, RAM = `5 ng`, RAS = `1 ng`, Otro_grupo_1 = `0.5 ng`, Otro_grupo_2 = `0.1 ng`, Muestra_1 = `G1-M`, Muestra_2 = `G2-M`) %>% 
  select(-Cycle:-`G2-M`)
Curvas_PCRa
## # A tibble: 51 × 9
##    Ciclos   SJM    AVY    RAM   RAS Otro_grupo_1 Otro_grupo_2 Muestra_1
##     <dbl> <dbl>  <dbl>  <dbl> <dbl>        <dbl>        <dbl>     <dbl>
##  1      1  21.3  0.124 -2.25   2.06       -1.78        -2.32       22.1
##  2      2  27.9  1.39   2.61   8.66        5.96         2.18       92.0
##  3      3  34.5 -0.660 11.4   12.2         5.94         2.34      132. 
##  4      4  56.6  1.000  1.87   6.49        5.20         1.05      164. 
##  5      5  65.2 -0.484 -1.18   1.77       -5.23         0.606     184. 
##  6      6  72.3  1.44  -0.477  2.35       -0.958        4.81      214. 
##  7      7  89.1 -5.10  -3.87  -4.93       -3.60        -4.87      249. 
##  8      8 101.  -1.67  -3.52  -3.31       -2.34         0.403     277. 
##  9      9 114.   2.66   5.35  -2.11       -1.40        -0.659     302. 
## 10     10 123.  13.6   10.4   -5.98        2.27         1.13      332. 
## # ℹ 41 more rows
## # ℹ 1 more variable: Muestra_2 <dbl>
Curvas_PCRai <- Curvas_PCRa %>% 
  select(Ciclos, SJM)

Curvas_PCRai
## # A tibble: 51 × 2
##    Ciclos   SJM
##     <dbl> <dbl>
##  1      1  21.3
##  2      2  27.9
##  3      3  34.5
##  4      4  56.6
##  5      5  65.2
##  6      6  72.3
##  7      7  89.1
##  8      8 101. 
##  9      9 114. 
## 10     10 123. 
## # ℹ 41 more rows
Curvas_PCRaai <- Curvas_PCRai %>% 
  pivot_longer(cols=-Ciclos,
               names_to="muestras",
               values_to="Fluorescencias")
Curvas_PCRaai
## # A tibble: 51 × 3
##    Ciclos muestras Fluorescencias
##     <dbl> <chr>             <dbl>
##  1      1 SJM                21.3
##  2      2 SJM                27.9
##  3      3 SJM                34.5
##  4      4 SJM                56.6
##  5      5 SJM                65.2
##  6      6 SJM                72.3
##  7      7 SJM                89.1
##  8      8 SJM               101. 
##  9      9 SJM               114. 
## 10     10 SJM               123. 
## # ℹ 41 more rows
umbral_ciclos <- 0.008

Graficas_PCRai <- ggplot(Curvas_PCRaai,
                       mapping = aes(x = Ciclos,
                                     y = Fluorescencias, 
                                     color = muestras)) +
  geom_line(linewidth = 1.5)+
  geom_hline(yintercept = umbral_ciclos, linetype = "dashed", color = "#5286d0")+
  theme_classic()+
  labs(title = "Curvas de Amplificacion de valores absolutos",
       subtitle = "Equipo",
       caption = "Diseño: SJM",
       x = "Ciclos",
       y = "Fluorescencias(u.a.)")

Graficas_PCRai

ggsave(filename = "Grafica curva amplificacion absoluta SJM.jpg", plot = Graficas_PCRai, dpi = 300)
## Saving 7 x 5 in image
Curvas_PCRaa <- Curvas_PCRa %>% 
  pivot_longer(cols=-Ciclos,
               names_to="muestras",
               values_to="Fluorescencias")
Curvas_PCRaa
## # A tibble: 408 × 3
##    Ciclos muestras     Fluorescencias
##     <dbl> <chr>                 <dbl>
##  1      1 SJM                  21.3  
##  2      1 AVY                   0.124
##  3      1 RAM                  -2.25 
##  4      1 RAS                   2.06 
##  5      1 Otro_grupo_1         -1.78 
##  6      1 Otro_grupo_2         -2.32 
##  7      1 Muestra_1            22.1  
##  8      1 Muestra_2            -0.184
##  9      2 SJM                  27.9  
## 10      2 AVY                   1.39 
## # ℹ 398 more rows
umbral_ciclos <- 0.008

Graficas_PCRa <- ggplot(Curvas_PCRaa,
                       mapping = aes(x = Ciclos,
                                     y = Fluorescencias, 
                                     color = muestras)) +
  geom_line(linewidth = 1.5)+
  geom_hline(yintercept = umbral_ciclos, linetype = "dashed", color = "#5286d0")+
  theme_classic()+
  labs(title = "Curvas de Amplificacion de valores absolutos",
       subtitle = "Grupal",
       caption = "Diseño: SJM",
       x = "Ciclos",
       y = "Fluorescencias(u.a.)")

Graficas_PCRa

ggsave(filename = "Grafica curva amplificacion absoluta grupal.jpg", plot = Graficas_PCRa, dpi = 300)
## Saving 7 x 5 in image