我使用ggplot
and生成了一系列图lapply
,如下所示:
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)
我正在使用一个可以简化为的大型数据框:
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))
这会生成一个图列表,如下所示:
我正在尝试打印或ggsave
输出此列表,如下所示:在 lapply 中保存绘图。
但是,所有导出/打印结果图的尝试,无论是使用lapply
循环还是简单print
语句,都会返回以下错误。
lapply(plot_list,print)
Error: `quo` must be a quosure
Call `rlang::last_error()` to see a backtrace
恐怕关于 quosures 的 R 文档没有产生任何有用的见解。我不是开发人员,也不太了解大部分文档。谁能帮我吗?
我最初发布此内容时并没有之前发生太多复杂的lapply
过滤,因为这似乎是一种分散注意力的无关紧要的事情。我现在提供它以防万一。作为参考,实际的数据框head
如下所示:
~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"