Seeking a tidyverse esque way to replace a list column of plots that contain NA to a dummy plot? Something like ifelse().
I have a data frame that contains list columns (meta, do I call this a 'list column df' or what's the correct name for a var of this kind?).
Here's an example:
library(tidyverse) library(patchwork) exdata <- diamonds %>% group_by(cut) %>% nest %>% crossing(dummy = 1:3) %>% mutate(plots = map(.x = data, ~ ggplot(.x, aes(x = x, y = y)) + geom_point())) patchwork::wrap_plots(exdata$plots)
This outputs some plots in a grid:
But, if some of the plots are NA:
exdata$plots[] <- NA patchwork::wrap_plots(exdata$plots) # "Error: Only know how to add ggplots and/or grobs"
I would therefore like to replace any NAs with a dummy plot:
dummy_plot <- ggplot() + theme_void() # creates a blank plot
How can I integrate into my dplyr chain above that creates
exdata a ifelse where if plots is NA, then replace with dummy_plot, else leave as is?