反正有没有让grid.arrange()充当split.screen()?我想安排一张桌子直接位于图例下方.
#create histogram
my_hist<-ggplot(diamonds, aes(clarity, fill=cut)) + geom_bar()
#create inset table
my_table<- tableGrob(head(diamonds)[,1:3],gpar.coretext =gpar(fontsize=8),gpar.coltext=gpar(fontsize=8), gpar.rowtext=gpar(fontsize=8))
grid.arrange(my_hist,my_table, ncol=2)
Run Code Online (Sandbox Code Playgroud)
生产:

但我希望它看起来像这样:

我尝试了split.screen()但它似乎不适用于ggplot类型的图形.有什么建议?谢谢.
我想要两个情节+他们的传奇的组合情节如下:
library(ggplot2)
library(grid)
library(gridExtra)
dsamp <- diamonds[sample(nrow(diamonds), 1000), ]
p1 <- qplot(price, carat, data=dsamp, colour=clarity)
p2 <- qplot(price, depth, data=dsamp, colour=clarity)
g <- ggplotGrob(p1 + theme(legend.position="bottom"))$grobs
legend <- g[[which(sapply(g, function(x) x$name) == "guide-box")]]
grid.arrange(arrangeGrob(p1+theme(legend.position="right"),p2+theme(legend.position="none"),legend,ncol=3,widths=c(3/7,3/7,1/7)))
Run Code Online (Sandbox Code Playgroud)
但是我不想猜测图和图例的宽度(并指定ncol)但是从中提取p1并p2 如此处所示.
所以我希望我需要这样的东西(来自链接的改编代码):
grid_arrange_shared_legend_row <- function(...) {
plots <- list(...)
g <- ggplotGrob(plots[[1]] + theme(legend.position="right"))$grobs
legend <- g[[which(sapply(g, function(x) x$name) == "guide-box")]]
lwidth <- sum(legend$width)
grid.arrange(
do.call(arrangeGrob, lapply(plots, function(x)
x + theme(legend.position="none"))),
legend,
ncol = length(plots)+1,
widths = unit.c(rep(unit(1, "npc") …Run Code Online (Sandbox Code Playgroud)