Skip to content

Commit

Permalink
feat: added logic to sort ascending data by cases
Browse files Browse the repository at this point in the history
Added logic to sort ascending data by cases for improve and facilitate the visualisation in plot_mpio and plot_dpto functions.

Refs: #78
  • Loading branch information
GeraldineGomez committed Feb 14, 2024
1 parent 93322dc commit 42d014c
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions R/plotting.R
Original file line number Diff line number Diff line change
Expand Up @@ -686,17 +686,19 @@ plot_dptos <- function(data_agrupada,
if (num_eventos > 3) {
pos_leyenda <- ggplot2::theme(legend.position = "bottom")
}
data_agrupada <- data_agrupada %>%
group_by_at(nomb_col) %>%
dplyr::summarise(casos = sum(.data[["casos"]]), .groups = "drop")
plot_casos_dptos <-
ggplot2::ggplot(data_agrupada,
ggplot2::aes(x = .data[[nomb_col]],
y = .data[["casos"]],
fill = .data[["nombre_evento"]])) +
y = .data[["casos"]])) +
ggplot2::geom_bar(width = 0.5,
stat = "identity") +
stat = "identity",
fill = "#2274BB") +
ggplot2::labs(x = "\nDepartamento\n", y = "Numero de casos\n",
caption = fuente_data) +
ggplot2::theme_classic() +
obtener_estetica_escala(escala = num_eventos, nombre = "Eventos") +
tema_sivirep() +
pos_leyenda +
ggplot2::coord_flip()
Expand Down Expand Up @@ -748,17 +750,20 @@ plot_mpios <- function(data_agrupada,
if (num_eventos > 3) {
pos_leyenda <- ggplot2::theme(legend.position = "bottom")
}
data_agrupada <- data_agrupada %>%
group_by_at(nomb_col) %>%
dplyr::summarise(casos = sum(.data[["casos"]]), .groups = "drop")
plot_casos_muns <-
ggplot2::ggplot(data_agrupada,
ggplot2::aes(x = .data[[nomb_col]],
y = .data[["casos"]],
fill = .data[["nombre_evento"]])) +
ggplot2::aes(x = reorder(.data[[nomb_col]],
.data[["casos"]]),
y = .data[["casos"]])) +
ggplot2::geom_bar(width = 0.5,
stat = "identity") +
stat = "identity",
fill = "#2274BB") +
ggplot2::labs(x = "\nMunicipio\n", y = "Numero de casos\n",
caption = fuente_data) +
ggplot2::theme_classic() +
obtener_estetica_escala(escala = num_eventos, nombre = "Eventos") +
tema_sivirep() +
pos_leyenda +
ggplot2::coord_flip()
Expand Down

0 comments on commit 42d014c

Please sign in to comment.