Skip to content

Commit

Permalink
fix(plot_sex): added percentage validation
Browse files Browse the repository at this point in the history
Ref: #108
  • Loading branch information
GeraldineGomez committed Apr 25, 2024
1 parent 61c0d0f commit 0909d3d
Showing 1 changed file with 42 additions and 21 deletions.
63 changes: 42 additions & 21 deletions R/plotting.R
Original file line number Diff line number Diff line change
Expand Up @@ -541,27 +541,48 @@ plot_sex <- function(data_agrupada,
package = "sivirep"),
"label_incidence")
}
plot_casos_sex <- ggplot2::ggplot(data_agrupada,
ggplot2::aes(x = .data[[col_sex]],
y = .data[[col_distribucion]],
fill = .data[[col_sex]])) +
ggplot2::geom_bar(width = 0.5,
stat = "identity") +
ggplot2::labs(x = "\nSexo\n", y = paste0(etiqueta_eje, "\n"),
caption = fuente_data) +
ggplot2::theme_classic() +
ggplot2::geom_text(ggplot2::aes(label = paste0(.data[[col_distribucion]],
" \n (",
.data[["porcentaje"]],
" %)")),
vjust = 1.5,
color = "black",
hjust = 0.5) +
obtener_estetica_escala(escala = 2, nombre = "Sexo") +
tema_sivirep() +
ggplot2::facet_wrap(facets = ~nombre_evento,
scales = "free_y",
ncol = 2)
if (porcentaje) {
plot_casos_sex <- ggplot2::ggplot(data_agrupada,
ggplot2::aes(x = .data[[col_sex]],
y = .data[[col_distribucion]],
fill = .data[[col_sex]])) +
ggplot2::geom_bar(width = 0.5,
stat = "identity") +
ggplot2::labs(x = "\nSexo\n", y = paste0(etiqueta_eje, "\n"),
caption = fuente_data) +
ggplot2::theme_classic() +
ggplot2::geom_text(ggplot2::aes(label = paste0(.data[[col_distribucion]],
" \n (",
.data[["porcentaje"]],
" %)")),
vjust = 1.5,
color = "black",
hjust = 0.5) +
obtener_estetica_escala(escala = 2, nombre = "Sexo") +
tema_sivirep() +
ggplot2::facet_wrap(facets = ~nombre_evento,
scales = "free_y",
ncol = 2)
} else {
plot_casos_sex <- ggplot2::ggplot(data_agrupada,
ggplot2::aes(x = .data[[col_sex]],
y = .data[[col_distribucion]],
fill = .data[[col_sex]])) +
ggplot2::geom_bar(width = 0.5,
stat = "identity") +
ggplot2::labs(x = "\nSexo\n", y = paste0(etiqueta_eje, "\n"),
caption = fuente_data) +
ggplot2::theme_classic() +
ggplot2::geom_text(ggplot2::aes(label = .data[[col_distribucion]]),
vjust = 1.5,
color = "black",
hjust = 0.5) +
obtener_estetica_escala(escala = 2, nombre = "Sexo") +
tema_sivirep() +
ggplot2::facet_wrap(facets = ~nombre_evento,
scales = "free_y",
ncol = 2)
}
return(plot_casos_sex)
}

Expand Down

0 comments on commit 0909d3d

Please sign in to comment.