wilkelab / cowplot

cowplot: Streamlined Plot Theme and Plot Annotations for ggplot2
https://wilkelab.org/cowplot/
704 stars 84 forks source link

Rewrite as_grob() for base graphics using echoGrob() #133

Closed clauswilke closed 5 years ago

clauswilke commented 5 years ago

The gridGraphics package has now an echoGrob() function that seems to work more reliably than my code in as_grob(): https://github.com/wilkelab/cowplot/blob/ffc3e3c9c49ccad54231ba7d7f438691ad1e8a79/R/as_gtable.R#L82-L88

It will also make the code simpler.

library(ggplot2)
library(cowplot)
library(gridGraphics)

plotfun <- function() {
  par(cex = .8)
  boxplot(mpg ~ cyl, xlab = "cyl", ylab = "mpg", data = mtcars)
}
g1 <- echoGrob(plotfun)
p2 <- ggplot(data = mtcars, aes(factor(cyl), mpg)) + geom_boxplot()

plot_grid(g1, p2)

Created on 2019-05-07 by the reprex package (v0.2.1)