Solved - be sure to send a list to lapply! Thanks Baptiste, and once again you rock!
Multiple questions have been asked about this, and this seems to be the accepted answer from Baptiste.
When I use the function provided in that answer:
justify <- function(x, hjust="center", vjust="center", draw=TRUE){
w <- sum(x$widths)
h <- sum(x$heights)
xj <- switch(hjust,
center = 0.5,
left = 0.5*w,
right=(unit(1,"npc") - 0.5*w))
yj <- switch(vjust,
center = 0.5,
bottom = 0.5*h,
top=(unit(1,"npc") - 0.5*h))
x$vp <- viewport(x=xj, y=yj)
if(draw) grid.draw(x)
return(x)
}
tgt <- lapply(myplot, justify, vjust="top", draw=FALSE)
I get the following error:
5.stop("both operands must be units")
4.Ops.unit(unit(1, "npc"), 0.5 * h)
3.FUN(X[[i]], ...)
2.lapply(myplot, justify, vjust = "top", draw = FALSE)
Ideas on how to fix this? I suspect I'm running on an updated "units" package, since most of the people who accepted this answer did so 2+ years ago.
Thanks!