I am trying plot the subsets of a table using ggplot and gridExtra. But I have bumbed in the following error EXPR must be a length 1 vector.
I could come up with any side step. Any help would be useful.
Here is a little example of what I'm trying to perform:
# 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