if (!require(pacman))
  install.packages("pacman")
## Loading required package: pacman

Llamar a pacman

library("pacman")

Llamar paqueteria necesaria

p_load("vroom",
       "dplyr",
       "ggplot2",
       "tidyr")

Llamar a base de datos

Curvas_amplif <- 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.
Curvas_amplif
## # 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

Modificar base de datos

Curvas_amplif2 <- Curvas_amplif %>%

  rename(

    Ciclos = Cycle,

    JPP = `G2-M`) %>%
  select(-"50 ng":-"10 ng")

  #filter(Ciclos >= 10)

Curvas_amplif2
## # A tibble: 51 × 7
##    Ciclos `5 ng` `1 ng` `0.5 ng` `0.1 ng` `G1-M`     JPP
##     <dbl>  <dbl>  <dbl>    <dbl>    <dbl>  <dbl>   <dbl>
##  1      1 -2.25    2.06   -1.78    -2.32    22.1 -0.184 
##  2      2  2.61    8.66    5.96     2.18    92.0  8.29  
##  3      3 11.4    12.2     5.94     2.34   132.   3.73  
##  4      4  1.87    6.49    5.20     1.05   164.   3.20  
##  5      5 -1.18    1.77   -5.23     0.606  184.   0.557 
##  6      6 -0.477   2.35   -0.958    4.81   214.   0.0300
##  7      7 -3.87   -4.93   -3.60    -4.87   249.  -7.37  
##  8      8 -3.52   -3.31   -2.34     0.403  277.  -6.98  
##  9      9  5.35   -2.11   -1.40    -0.659  302.  -3.63  
## 10     10 10.4    -5.98    2.27     1.13   332.  -1.16  
## # ℹ 41 more rows

Reordenamiento de datos

  1. Seleccionar los datos a reordenar (variables dependientes)
  2. Agrupar todas las variables por nombre
  3. Agrupar todas las variables por ciclo.
Curvas_amplif3 <- Curvas_amplif2 %>% 
  pivot_longer(cols= -Ciclos, 
               names_to = "Muestras",
               values_to = "Fluorescencias")
Curvas_amplif3
## # A tibble: 306 × 3
##    Ciclos Muestras Fluorescencias
##     <dbl> <chr>             <dbl>
##  1      1 5 ng             -2.25 
##  2      1 1 ng              2.06 
##  3      1 0.5 ng           -1.78 
##  4      1 0.1 ng           -2.32 
##  5      1 G1-M             22.1  
##  6      1 JPP              -0.184
##  7      2 5 ng              2.61 
##  8      2 1 ng              8.66 
##  9      2 0.5 ng            5.96 
## 10      2 0.1 ng            2.18 
## # ℹ 296 more rows

Grafica

Grafica_amplif <- ggplot(data=Curvas_amplif3,
                         mapping = aes(x=Ciclos, 
                                       y=Fluorescencias,
                                       color=Muestras)) + 
  geom_line(size=1.5)
## Warning: Using `size` aesthetic for lines was deprecated in ggplot2 3.4.0.
## ℹ Please use `linewidth` instead.
## This warning is displayed once per session.
## Call `lifecycle::last_lifecycle_warnings()` to see where this warning was
## generated.
Grafica_amplif

Mejorar la gráfica

Umbral_ciclos <- 0.1
Grafica_amplif2 <- Grafica_amplif+
  geom_hline(yintercept=Umbral_ciclos, linetype="dashed", color="#91197C")+
  theme_classic()+
  labs(title="Curvas de amplificación de valores absolutos RT-qPCR",
       subtitle="Todas las muestras", 
       caption="Equipo: JPP", 
       x="Ciclos", 
       y="Fluorescencia (u.a.)")+
  theme(axis.line = element_line(size=1.2, color="black"),
        axis.title = element_text(face="bold"),
        axis.text = element_text(face="bold"), 
        legend.title = element_text(face="bold"),
        legend.text = element_text(face="bold"))+
  scale_x_continuous(breaks = seq(min(Curvas_amplif3$Ciclos),
                                  max(Curvas_amplif3$Ciclos),
                                  by=5))+
  scale_y_continuous(breaks = seq(min(Curvas_amplif3$Fluorescencias),
                                  max(Curvas_amplif3$Fluorescencias),
                                  by=80),
                     labels = scales::number_format(accuracy = 1))
## Warning: The `size` argument of `element_line()` is deprecated as of ggplot2 3.4.0.
## ℹ Please use the `linewidth` argument instead.
## This warning is displayed once per session.
## Call `lifecycle::last_lifecycle_warnings()` to see where this warning was
## generated.
Grafica_amplif2

Grafica de los datos del equipo

Grafica_amplif_equipo <- ggplot(Curvas_amplif2, aes(x = Ciclos)) +
  geom_line(aes(y = JPP, color = "JPP"), linewidth = 1.5) +
  geom_hline(yintercept = Umbral_ciclos, 
             linetype = "dashed", 
             color = "#91197C",
             linewidth = 1) +
  scale_color_manual(
    name = "Muestras",
    values = c("JPP" = "#6AA84F", 
               "MLL" = "#2E2A8C")
  ) +
  theme_classic() +
  labs(
    title = "Curvas de amplificación de valores absolutos RT-qPCR",
    subtitle = "EQUIPO JPP",
    caption = "Equipo: JPP",
    x = "Ciclos",
    y = "Fluorescencia (u.a.)"
  ) +
  theme(
    axis.line = element_line(linewidth = 1.2, color = "black"),
    axis.title = element_text(face = "bold", size = 12),
    axis.text = element_text(face = "bold", size = 10),
    legend.title = element_text(face = "bold", size = 12),
    legend.text = element_text(face = "bold", size = 10),
    plot.title = element_text(face = "bold", size = 14),
    plot.subtitle = element_text(size = 12)
  ) +
  scale_x_continuous(
    breaks = seq(min(Curvas_amplif2$Ciclos),
                 max(Curvas_amplif2$Ciclos),
                 by = 3)
  ) +
  scale_y_continuous(
    breaks = seq(0, max(Curvas_amplif2$JPP), by = 40),
    labels = scales::number_format(accuracy = 1)
  )

Grafica_amplif_equipo