我正在尝试使用 ggplot 和 gridExtra 绘制表的子集。
但我遇到了以下错误 EXPR 必须是长度为 1 的向量。
我可以想出任何办法。任何帮助都会有用的。
这是我正在尝试执行的一个小示例:
# the table
dt1 <- data.table(parkName=rep(c("Zone A","Zone B", "Zone C" ,
"Zone D"),5), boundary=rep(0:1,10),v=1:20, w=rnorm(20))[]
# criteria for subsetting the table
dt2 <- data.table(zone1 = c("Zone A","Zone B"), zone2 =c("Zone B","Zone C"))
# function for subsetting the table and plotting
p <- function(sd1,sd2){
dlist <- dt1[parkName==sd1 | parkName==sd2]
b <- dt1[parkName %in% dlist]
a <- ggplot(
b,
aes(v,w)) + geom_line()
return(a)
}
mplot <- mapply(p,dt2[,zone1],dt2[,zone2])
cairo_pdf("myplot1.pdf")
do.call(marrangeGrob, c(mplot, list(nrow=2, ncol=2)))
dev.off()
# results
Error in switch(ct, ggplot = ggplotGrob(grobs[[ii.table]]), trellis =
latticeGrob(grobs[[ii.table]]), : EXPR must be a length 1 vector