grob
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)
Seeking workaround for gtable_add_grob code broken by ggplot 2.2.0
Indeed, ggplot2 v2.2.0 constructs complex strips column by column, with each column a single grob. This can be checked by extracting one strip, then examining its structure. Using your plot: library(ggplot2) library(gtable) library(grid) # Your data df = structure(list(location = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, … Read more