A good approach when using {targets} is to create design targets using so your visual system is built once and reused everywhere.
design_targets <- list(
tar_target(nswers_colors,
list(
indigo_dye = "#0E294A",
electric_purple = "#94278F",
sunny_yellow = "#FDD106",
blue_sapphire = "#005F85",
sea_green = "#33BEAD",
light_gray = "#999999",
yellow_green = "#8CC73F"
)
),
tar_target(gender_color_map,
c("Male" = nswers_colors$yellow_green,
"Female" = nswers_colors$blue_sapphire)),
tar_target(intvervention_comparison_map,
c(
"Intervention" = nswers_colors$blue_sapphire,
"Comparison" = nswers_colors$light_gray
)
)
)
Then your charts stop depending on hex codes:
ggplot(df, aes(x = gender, y = outcome, fill = group)) +
geom_col() +
scale_fill_manual(values = gender_color_map)
This separates raw colors from meaningful mappings. If the Communications team decides the color mappings need to change, that only needs to be updated in a single location.
Leave a Reply