How to place grobs with annotation_custom() at precise areas of the plot region?

Here’s how I would approach this, library(gtable) library(ggplot2) library(plyr) set.seed(1) d <- data.frame(x=rep(1:10, 5), y=rnorm(50), g = gl(5,10)) # example plot p <- ggplot(d, aes(x,y,colour=g)) + geom_line() + scale_x_continuous(expand=c(0,0))+ theme(legend.position=”top”, plot.margin=unit(c(1,0,0,0),”line”)) # dummy data for the legend plot # built with the same y axis (same limits, same expand factor) d2 <- ddply(d, “g”, summarise, … Read more

R return corrplot as object

The recent gridGraphics package could probably do what you asked: return the plot as a grob. mat <- matrix(rnorm(100), ncol=10) library(corrplot) corrplot(cor(mat)) library(gridGraphics) grab_grob <- function(){ grid.echo() grid.grab() } g <- grab_grob() library(gridExtra) grid.newpage() grid.arrange(g,g,g,g)