This vignette is to help show how the ggplot2 themes can be used. The aim of the themes is to help giving an “IMPACT” touch to the graphs, not to create them. The graph should already be created, i.e. type of plots, and the correct aesthetics.
The following example aims to plot the percentages of households by category of water sources, by gender of the head of households (This a dummy dataset).
data_to_plot <- presentresults::presentresults_MSNA2024_labelled_results_table |>
dplyr::filter(
analysis_var == "wash_drinking_water_source_cat",
group_var == "hoh_gender",
group_var_value %in% c("male", "female")
) |>
dplyr::mutate(label_analysis_var_value = factor(label_analysis_var_value,
levels = c("Improved",
"Unimproved",
"Surface water",
"Undefined")))
initialplot <- data_to_plot %>%
ggplot2::ggplot() +
ggplot2::geom_col(
ggplot2::aes(
x = label_analysis_var_value,
y = stat,
fill = label_group_var_value
),
position = "dodge"
) +
ggplot2::labs(
title = stringr::str_wrap(unique(data_to_plot$indicator), 50),
x = stringr::str_wrap(unique(data_to_plot$label_analysis_var), 50),
fill = stringr::str_wrap(unique(data_to_plot$label_group_var), 20)
)Initial plot without theme.
theme_barplottheme_barplot will give REACH color palette to the bar
plot, put the y-axis to 0 to 100%.
Initial plot without theme_barplot
theme_impacttheme_impact will change the background and color of the
title.
Initial plot without theme_barplot and
theme_impact
Initial plot without theme_barplot and
theme_impact set with IMPACT theme
Some palettes are available in the impact_palettes
object.
impact_palettes
#> $reach_palette
#> [1] "#58585A" "#EE5859" "#D2CBB8" "#c7c8ca"
#>
#> $impact_palette
#> [1] "#000000" "#315975" "#58585A"
#>
#> $agora_palette
#> [1] "#581522" "#023C40" "#4F9C35" "#F56741" "#F6ECD0"
#>
#> $tol_palette
#> [1] "#322288" "#505050" "#44AA99" "#88CCEE" "#DDCC77" "#EE5859" "#AA4499"
#> [8] "#721621"
#>
#> $high_contrast_tol_palette
#> [1] "#275587" "#CEA936" "#A35464"
#>
#> $wong_palette
#> [1] "#EE5859" "#E69F00" "#56B4E9" "#322288" "#F0E442" "#0072B2" "#505050"
#> [8] "#CC79A7"
#>
#> $divergent
#> [1] "#F15B22" "#F58120" "#FBAB35" "#209EA0" "#008083" "#0072B2" "#016060"
#>
#> $divergent_with_neutral
#> [1] "#721621" "#D7191C" "#FDAE61" "#FFFFBF" "#97D3C3" "#209EA0" "#016060"The palette should have enough color to match the scale fill. The impact palette only has 3 colors while the graph needs 4.
data_to_plot <- presentresults::presentresults_MSNA2024_labelled_results_table |>
dplyr::filter(
analysis_var == "snfi_fds_cannot_cat",
group_var == "hoh_gender")
initialplot <- data_to_plot %>%
ggplot2::ggplot() +
ggplot2::geom_col(
ggplot2::aes(
x = label_analysis_var_value,
y = stat,
fill = label_group_var_value
),
position = "dodge"
) +
ggplot2::labs(
title = stringr::str_wrap(unique(data_to_plot$indicator), 50),
x = stringr::str_wrap(unique(data_to_plot$label_analysis_var), 50),
fill = stringr::str_wrap(unique(data_to_plot$label_group_var), 20)
)
initialplot +
theme_barplot(palette = impact_palettes$impact_palette) +
theme_impact("impact")
#> Error in `palette()`:
#> ! Insufficient values in manual scale. 4 needed but only 3 provided.