USAID-OHA-SI / glitr

SI graphics package to adorn your ggplots
https://usaid-oha-si.github.io/glitr/
Other
27 stars 4 forks source link

Function around an achievement legend #101

Open achafetz opened 1 week ago

achafetz commented 1 week ago

What is the most optimal way to include a legend into an achievement plot? We would want:

library(tidyverse)
library(glitr)

df_t <- tibble::tribble(
            ~snu1, ~achievement,     ~achv_desc, ~achv_label, ~achv_color,
        "Midwest",         0.99,    "On Target",   "90-110%",   "#5BB5D5",
      "Northwest",         1.22, "Above Target",      "+110%",  "#697EBC",
  "Pacific Coast",         0.62,    "Concerned",      "<75%",   "#F8A27E"
  )

df_t %>% 
  ggplot(aes(achievement, snu1, 
             fill = factor(achv_color, achv_color_map$achv_color))) +
  geom_col() +
  scale_fill_identity(guide = "legend",
                      labels = achv_color_map$achv_desc,
                      breaks = achv_color_map$achv_color) +
  guides(fill = guide_legend(title = "Achievement")) +
  si_style()