0

I am trying to do a visualisation on the state of multiple boolean variables. I managed to get a hacky solution using naniar:

library(tidyverse)
library(naniar)
a <- c(TRUE, FALSE, TRUE,FALSE)
b <- c(FALSE, FALSE, TRUE,FALSE)
c <- c(FALSE, TRUE, TRUE,FALSE)

data.frame(a,b,c) %>%
  mutate_all(~ if_else(., NA, FALSE)) %>%
  vis_miss()

missing value visualisation using naniar

Obviously that is abusing this library and doesn't have the right labels. How could I achieve the same thing in ggplot (say with a colour variable of enabled TRUE or FALSE)?

94621
  • 39
  • 7
  • Could you give examples/describe what you would want the plot to look like? – jpsmith Mar 29 '23 at 14:37
  • `visdat::vis_mis()` is returning a `ggplot` object. So you may alternatively try customizing its output, if you otherwise are happy with the result. – Seth Mar 29 '23 at 14:42

1 Answers1

1

You could first transform your data to a longer format using pivot_longer. You could use geom_tile to create a heatmap like this:

library(tidyverse)
data.frame(a,b,c) %>%
  mutate(ID = row_number()) %>%
  pivot_longer(cols = a:c) %>%
  ggplot(aes(x = name, y = factor(ID), fill = value)) +
  geom_tile() +
  labs(fill = "Enabled", y = 'ID', x = "Name")

Created on 2023-03-29 with reprex v2.0.2

Quinten
  • 35,235
  • 5
  • 20
  • 53