baptiste / gridExtra

Miscellaneous Functions for "Grid" Graphics
http://cran.r-project.org/web/packages/gridExtra/index.html
15 stars 4 forks source link

length(widths) == ncol is not True when using rmarkdown #29

Closed aliarsalankazmi closed 8 years ago

aliarsalankazmi commented 8 years ago

I am copy-pasting the code found in this github page (https://github.com/baptiste/gridextra/wiki/arranging-ggplot)

The code snippet follows:

```{r try, fig.align='center',fig.width=9,fig.height=7}

library(ggplot2)
p1 <- qplot(mpg, wt, data=mtcars, colour=cyl)
p2 <- qplot(mpg, data = mtcars) + ggtitle("title")
p3 <- qplot(mpg, data = mtcars, geom = "dotplot")
p4 <- p1 + facet_wrap(~carb, nrow=1) + theme(legend.position="none") +
  ggtitle("facetted plot")

library(gtable)
g2 <- ggplotGrob(p2)
g3 <- ggplotGrob(p3)
g <- rbind(g2, g3, size="first")
g$widths <- unit.pmax(g2$widths, g3$widths)
grid.newpage()
grid.draw(g)

When I copy-paste this code in console, it runs fine, printing the plots as expected. But when I knit my rmarkdown document in which this code is pasted, it gives an error of length(widths) == ncol is not TRUE.

The versions for the packages in use are: rmarkdown: 0.9.5 knitr: 1.12.3 gtable: 0.2.0

baptiste commented 8 years ago

Please post your question on stackoverflow with the gtable and/or ggplot2 tag. This isn't related to the gridExtra package (that wiki page should not really be here, but I don't know where to put it). FWIW I'm guessing there is a problem in your rmarkdown document, try to make a minimal reproducible example.