我有一个我想传递给 patchwork::wrap_plots 的地块列表:
library(tidyverse)
library(patchwork)
# plots with na
dummy_plot <- ggplot() + theme_void()
p <- ggplot(mtcars, aes(mpg, cyl)) + geom_point()
plots <- list(p, p, NA)
patchwork::wrap_plots(plots)
给出错误:
错误:只知道如何添加 ggplots 和/或 grobs
因此,我想预处理我的图列表,用上面的空白虚拟图替换任何 NA。
期望的结果:
plots <- list(p, p, NA)
... some magic r code here to replace NA with dummy plot ...
# now plots looks like this
plots <- list(p, p, dummy_plot)
如何将列表中的 NA 实例替换为我的虚拟图?