0

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!

  • Baptsite's code from the link in your question runs without error, so can you share an minimal example of `myplot` please. or perhaps you just need `library(grid)` ? – user20650 Mar 07 '19 at 16:43
  • Possible duplicate of [Align grob at fixed top/center position, regardless of size](https://stackoverflow.com/questions/32106333/align-grob-at-fixed-top-center-position-regardless-of-size) – divibisan Mar 08 '19 at 16:23
  • If you solved the issue, you can post it as an answer to your own question. That lets others see what you did – camille Mar 08 '19 at 16:23
  • Or if baptiste's answer on the linked question solved your problem, give that answer an upvote (once you have 15 rep) – divibisan Mar 08 '19 at 16:23

0 Answers0