I am trying to change the line colours for each facet in gg_miss_var.
For example, using the data airquality
#Load data
data("airquality")
#Load libraries
library(ggplot2)
#Create missing data plot using gg plot
gg_miss_var(airquality, Month, show_pct = TRUE) + ylim(0, 100) +
theme(
panel.background = element_rect(fill = "white"),
panel.border = element_blank()) +
scale_fill_manual(
values = c("forestgreen", "pink", "blue","yellow","red"))
But that doesn’t change the colours, any ideas?
>Solution :
Just as a reference: While out-of-the-box options are quick and easy when it comes to customizing it might be worthwhile to build up the plot from scratch using ggplot2 where for the data preparation you could use naniar::miss_var_summery:
data("airquality")
library(ggplot2)
library(naniar)
df_miss <- airquality %>%
dplyr::group_by(Month) %>%
miss_var_summary() |>
dplyr::mutate(variable = reorder(variable, pct_miss))
ggplot(df_miss, aes(pct_miss, variable, color = factor(Month))) +
geom_point() +
geom_segment(aes(yend = variable, xend = 0)) +
scale_color_manual(values = c("forestgreen", "pink", "blue","yellow","red"), guide = "none") +
xlim(0, 100) +
facet_wrap(~Month) +
theme_minimal() +
theme(
panel.background = element_rect(fill = "white"),
panel.border = element_blank())

