This question is a follow-up to my previous question: Adding color code (fill) to vis_miss plot
I would like to visualize the "missing info" in a data frame using geom_raster
from ggplot2
in R while also highlighting some additional data structure using color-coding.
Solution attempt:
library(tidyverse)
x11()
airquality %>%
mutate(id = row_number()) %>%
gather(-c(id,Month), key = "key", value = "val") %>%
mutate(isna = is.na(val)) %>%
mutate(Month=as.factor(ifelse(isna==TRUE,NA,Month))) %>%
ggplot(aes(key, id, fill = Month)) +
geom_raster() +
labs(x = "Variable",
y = "Row Number", title = "Missing values in rows") +
coord_flip()
This is almost what I want, but it would be nicer to separate the month and NA legends. Is that possible? (Note that my system does not allow me to use transparency (alpha
)).