Skip to content

Commit

Permalink
mejora etiquetas cortes
Browse files Browse the repository at this point in the history
  • Loading branch information
rikivillalba committed Jan 16, 2025
1 parent a924de5 commit 289ec42
Showing 1 changed file with 30 additions and 18 deletions.
48 changes: 30 additions & 18 deletions demanda_diaria_API_MEM.R
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ plot.DemandasGBA <- function(x) {
) +
annotate("label",
hjust = "right",
size = 3,
size = 4,
x = max_24[, fecha] + c(0, 0, 0, 0),
y = max_24[, unlist(.(
eds + 500, dem + 500, eds + 1000,
Expand Down Expand Up @@ -342,26 +342,38 @@ plot.DemandasGBA <- function(x) {
data[max.curr, on = .(fecha == fmax), by = .EACHI,
fmax := i.fmax]
}

plt <- plot_grid(
nrow = 2, ncol = 1, align = "v", rel_heights = 2:1,
plt,
ggplot(data, aes(fecha, cortes)) +
geom_line(color="darkorange",linewidth=1) +
scale_x_datetime(
breaks = seq(as.POSIXct(cdate - ndias), data[, max(fecha)], "6 hour"),
minor_breaks = seq(as.POSIXct(cdate - ndias), data[, max(fecha)], "3 hour"),
date_labels = "%d %b %Hh") +
theme(
axis.title.x = element_blank(), axis.text.x = element_blank(),
axis.ticks.x = element_blank()) +
geom_label(
data = data[!is.na(fmax)], aes(fecha, cortes, label = sprintf("%s", cortes)),
size= 3, nudge_y = 800, alpha = 0.75) +
geom_label(
data = data[!is.na(fmax)], aes(fecha, cortes, label = format(fecha, "%d/%m %H:%M")),
size = 3, nudge_y = 1600, alpha = 0.75) +
labs(subtitle="Cortes ENRE (Edesur)")
{
plt_cortes <- ggplot(data, aes(fecha, cortes)) +
geom_line(color="darkorange",linewidth=1) +
scale_x_datetime(
breaks = seq(as.POSIXct(cdate - ndias), data[, max(fecha)], "6 hour"),
minor_breaks = seq(as.POSIXct(cdate - ndias), data[, max(fecha)], "3 hour"),
date_labels = "%d %b %Hh") +
theme(
axis.title.x = element_blank(), axis.text.x = element_blank(),
axis.ticks.x = element_blank()) +
labs(subtitle="Cortes ENRE (Edesur)")
# medición aprox. de las etiquetas de cortes
# $children$axis$grobs[[2]]$children[[1]]$label
# size es mm
if ("fmax" %in% names(data)) {
plt_cortes +
geom_label(
data = data[!is.na(fmax)], aes(fecha, cortes, label = format(fecha, "%d/%m %H:%M")),
size = 4, nudge_y = data[,1e-1 * (ceiling(max(cortes, na.rm = TRUE)/5) * 5) ],
alpha = 0.75) +
geom_label(
data = data[!is.na(fmax)], aes(fecha, cortes, label = sprintf("%s", cortes)),
size= 4, nudge_y = data[, 2e-1 * (ceiling(max(cortes, na.rm = TRUE)/5) * 5) ],
alpha = 0.75)
} else {
plt_cortes
}
}
)
}
plt
Expand Down

0 comments on commit 289ec42

Please sign in to comment.