Depuracion datos historicos

Secciones

Tab 1

Lectura de tibbles proceso previo (lectura)

Correspondencia Tibbles: iny.rds: inyecciones al SISTRANGAS; ext.rds: extracciones del SISTRANGAS

iny <- readRDS("data_01_output/iny.rds")
ext <- readRDS("data_01_output/ext.rds")

str(iny)
tibble [97,116 × 8] (S3: tbl_df/tbl/data.frame)
 $ nodo  : chr [1:97116] "V024" "V025" "V028" "V030" ...
 $ name  : chr [1:97116] "CACTUS100" "CACTUSNVOPMX" "CULEBRA" "GLORIADIOS" ...
 $ origen: chr [1:97116] "nacional" "nacional" "nacional" "importacion" ...
 $ region: chr [1:97116] "Sur" "Sur" "Golfo" "Norte" ...
 $ zona  : chr [1:97116] "Zona 8" "Zona 8" "Zona 3" "Zona 1" ...
 $ energy: num [1:97116] 584716 1073351 0 103695 0 ...
 $ fecha : POSIXct[1:97116], format: "2015-01-01" "2015-01-01" ...
 $ unidad: chr [1:97116] "GJ" "GJ" "GJ" "GJ" ...
str(ext)
tibble [656,630 × 7] (S3: tbl_df/tbl/data.frame)
 $ nodo  : chr [1:656630] "E016" "E017" "E018" "E019" ...
 $ name  : chr [1:656630] "AEROPUERTO" "ALTAMIRA" "APASCO" "APASCOTULA" ...
 $ region: chr [1:656630] "Golfo" "Golfo" "Sur" "Centro" ...
 $ zona  : chr [1:656630] "Zona 3" "Zona 4" "Zona 8" "Zona 5" ...
 $ energy: num [1:656630] 10446 5733 2476 711 25467 ...
 $ fecha : POSIXct[1:656630], format: "2015-01-01" "2015-01-01" ...
 $ unidad: chr [1:656630] "GJ" "GJ" "GJ" "GJ" ...

Validacion de fechas.

v_time_span <- unique(iny$fecha)
v_time_span_min <- min(v_time_span)
v_time_span_max <- max(v_time_span)
#
v_time <- tibble(tset = c(0),
                    tsetid = c("raw"),
                   tmin = c(v_time_span_min),
                   tmax = c(v_time_span_max))
#
print(v_time)
# A tibble: 1 × 4
   tset tsetid tmin                tmax               
  <dbl> <chr>  <dttm>              <dttm>             
1     0 raw    2015-01-01 00:00:00 2024-05-31 00:00:00
gg_01 <-ggplot(iny, aes(x = region, y = energy, fill = region)) +
  geom_bar(stat = "identity") +
  coord_flip() + # Flips the axes for better readability
  theme_classic()

#
print(gg_01)

Tab 2

Textos graficos

Cuadro de textos basicos

tb_labels <- tibble(
  lblid = c(1,1,2,2),
  lbllng = c("En","Sp",
             "En","Sp"),
  lbltit1 = c("SISTRANGAS gas receipts by", "SISTRANGAS recepciones de gas por",
              "SISTRANGAS gas deliveries by","SISTRANGAS entregas de gas por"),
  lbltit2 = c("region","region",
              "region","region"),
  lblstt1 = c("From ", "Desde ",
              "From ", "Desde "),
  lblstt2 = c("to ", "a ",
              "to ", "a "),
  lblx = c("Region","Region","Region","Region"),
  lblyax = c("Energy (GJ)","Energia (GJ)","Energy (GJ)","Energia (GJ)"))

print(tb_labels)
# A tibble: 4 × 8
  lblid lbllng lbltit1                      lbltit2 lblstt1 lblstt2 lblx  lblyax
  <dbl> <chr>  <chr>                        <chr>   <chr>   <chr>   <chr> <chr> 
1     1 En     SISTRANGAS gas receipts by   region  "From " "to "   Regi… Energ…
2     1 Sp     SISTRANGAS recepciones de g… region  "Desde… "a "    Regi… Energ…
3     2 En     SISTRANGAS gas deliveries by region  "From " "to "   Regi… Energ…
4     2 Sp     SISTRANGAS entregas de gas … region  "Desde… "a "    Regi… Energ…

Agregacion de textos. Se segregan los cuadros para facilitar la agregacion de nuevos textos.

tb_labplus <- tibble(
  lblid = c(3,3),
  lbllng = c("En","Sp"),
  lbltit1 = c("SISTRANGAS gas receipts by", "SISTRANGAS recepciones de gas por"),
  lbltit2 = c("node","nodo"),
  lblstt1 = c("From ", "Desde "),
  lblstt2 = c("to ", "a "),
  lblx = c("CENAGAS operations","Operaciones CENAGAS"),
  lblyax = c("Energy (TJ)","Energia (TJ)"))

tb_labels <- add_row(tb_labels, tb_labplus)

print(tb_labels)
# A tibble: 6 × 8
  lblid lbllng lbltit1                      lbltit2 lblstt1 lblstt2 lblx  lblyax
  <dbl> <chr>  <chr>                        <chr>   <chr>   <chr>   <chr> <chr> 
1     1 En     SISTRANGAS gas receipts by   region  "From " "to "   Regi… Energ…
2     1 Sp     SISTRANGAS recepciones de g… region  "Desde… "a "    Regi… Energ…
3     2 En     SISTRANGAS gas deliveries by region  "From " "to "   Regi… Energ…
4     2 Sp     SISTRANGAS entregas de gas … region  "Desde… "a "    Regi… Energ…
5     3 En     SISTRANGAS gas receipts by   node    "From " "to "   CENA… Energ…
6     3 Sp     SISTRANGAS recepciones de g… nodo    "Desde… "a "    Oper… Energ…

Funcion de aplicacion de textos

set_lbl_0 <- function(id, lng) {
  setout <- filter(tb_labels, lblid == id, lbllng == lng)
  # Return the setout
  return(setout)
}

##
set_lbl_1 <- function(p,id, lng, dat1, dat2) {
  lblrow <- set_lbl_0(id,lng)
  
  p + labs(title = paste0(lblrow$lbltit1, " ", lblrow$lbltit2),
           subtitle = paste0(lblrow$lblstt1, " ", dat1, " ", lblrow$lblstt2, " ", dat2),
           x = lblrow$lblx,
           y = lblrow$lblyax)
}

Ro2

v_lbl_row_01 <- 1
v_lbl_row_02 <- 2
# language "En", "Sp"
v_lbl_lng_01 <- paste0("Sp")


gg_01 <- set_lbl_1(gg_01, v_lbl_row_01,
                  v_lbl_lng_01,
                  v_time_span_min, v_time_span_max)
#
print(gg_01)