I have generated a series of plots using ggplot
and lapply
, like so:
makeplot <- function(data){
require(ggplot2)
require(dplyr)
ggplot(data,aes(x=num,y=cat3, fill=cat3)) +
facet_wrap(~cat2)
# etc...
}
plot_list <- lapply(split(data, interaction(data[,c("province","cat1")]), drop = TRUE), makeplot)
I am using a large data frame that could be simplified to:
data <- data.frame(
province = sample(c("1","2","3","4")),
cat1 = sample(c("health","education","banks","etc")),
cat2 = sample(c("winter","spring","summer","fall")),
cat3 = sample(c("1 hour","2 hours","4 hours","8 hours")),
Y = sample(1:100))
This generates a list of plots like so:
I am attempting to print or ggsave
out this list, as per here: Saving plots within lapply.
However, all attempts to export/print the resulting plots, whether with an lapply
loop or a simple print
statement return the following error.
lapply(plot_list,print)
Error: `quo` must be a quosure
Call `rlang::last_error()` to see a backtrace
I'm afraid the R documentation on quosures didn't yield any helpful insights. I'm not a developer and don't really understand most of the documentation. Can anyone help me out?
I originally posted this without much of the complex lapply
filtering happening earlier, as it seemed a distracting irrelevance. I'm providing that now in case it's helpful. For reference, the actual data frame head
looks like:
~season, ~fac_type, ~trav_cat, ~avg_pc_pop, ~loop,
"Monsoon season", "All financial institutions", "0 to 30 minutes", 0.41395948733655, "Monsoon season All financial institutions",
"Normal season", "All health facilities", "0 to 30 minutes", 0.426855030030894, "Monsoon season All health facilities",
"Other season", "All hospitals", "1 to 2 hours", 0.301967752836744, "Monsoon season All hospitals",
"Monsoon season", "Commercial and development banks", "4 to 8 hours", 0.385783483483483, "Monsoon season Commercial and development banks",
"Normal season", "District Headquarters", "16 to 32 hours", 0.270673828371869, "Monsoon season District Headquarters",
"Other season", "Government hospitals", "1 to 2 hours", 0.263825993199371, "Monsoon season Government hospitals"