3

I 've updated my R version including all packages and the function arrangeGrob (Package gridExtra) has changed.

On my old version R version 3.1.3 I used it as the following to make corner labels:

loading r packages

library(ggplot2)
library(grid)
library(gridExtra)

example data

a <- 1:20
b <- sample(a, 20)
c <- sample(b, 20)
d <- sample(c, 20)

create a data frame

mydata   <- data.frame(a, b, c, d)

create example plots

myplot1  <- ggplot(mydata, aes(x=a, y=b)) + geom_point()
myplot2  <- ggplot(mydata, aes(x=b, y=c)) + geom_point()
myplot3  <- ggplot(mydata, aes(x=c, y=d)) + geom_point()
myplot4  <- ggplot(mydata, aes(x=d, y=a)) + geom_point()

set corner labels

 myplot1 <- arrangeGrob(myplot1, main = textGrob("A", x = unit(0, "npc")
     , y   = unit(1, "npc"), just=c("left","top"),
     gp=gpar(col="black", fontsize=18, fontfamily="Times Roman")))

 myplot2 <- arrangeGrob(myplot2, main = textGrob("B", x = unit(0, "npc")
     , y = unit(1, "npc"), just=c("left","top"),
     gp=gpar(col="black", fontsize=18, fontfamily="Times Roman")))

 myplot3 <- arrangeGrob(myplot3, main = textGrob("C", x = unit(0, "npc")
    , y  = unit(1, "npc"), just=c("left","top"),
    gp=gpar(col="black", fontsize=18, fontfamily="Times Roman")))

 myplot4 <- arrangeGrob(myplot4, main = textGrob("D", x = unit(0, "npc")
    , y = unit(1, "npc"), just=c("left","top"),
    gp=gpar(col="black",    fontsize=18, fontfamily="Times Roman")))

 grid.arrange(myplot1, myplot2, myplot3, myplot4) 

and I got the following plot, which was fine:

enter image description here

but under the new R version 3.2.2 the image looks like this:

enter image description here

arrangeGrob opens for every textGrob a new image and I got eight images on one page instead of four. How can I fixed it that the plot looks like in the old version of R and gridExtra?

Community
  • 1
  • 1
Kev
  • 425
  • 3
  • 8
  • 6
    There has been a rewrite of gridExtra, that is not (fully) backward compatible - may be the issue. Have a look at the new wiki https://cran.r-project.org/web/packages/gridExtra/vignettes/arrangeGrob.html . Try changing `main` to `top` – user20650 Oct 02 '15 at 21:34
  • Thank very much, it works!!! – Kev Oct 03 '15 at 09:11
  • Great stuff, please feel free to write it up as an answer – user20650 Oct 03 '15 at 09:52
  • When I tried to save the result as an object `g <-arrangeGrob(myplot1, myplot2, myplot3, myplot4)` I ended up with a TableGrob that prints as text, and needed a `plot(g)` to view it. – Dave X Oct 07 '15 at 18:03
  • Doh -- http://stackoverflow.com/questions/31458051/store-arrangegrob-to-object-does-not-create-printable-object says you need `grid.draw(g)` instead. – Dave X Oct 07 '15 at 18:12

1 Answers1

1

From Kev's comment:

There has been a rewrite of gridExtra, that is not (fully) backward compatible - may be the issue. Have a look at the new wiki cran.r-project.org/web/packages/gridExtra/vignettes/… . Try changing main to top – user20650

Nelson Auner
  • 1,421
  • 1
  • 15
  • 21