【问题标题】:Is it possible to add a small graph at the corner of the plotting region with ggplot in r是否可以在绘图区域的角落添加一个小图,在 r 中使用 ggplot
【发布时间】:2020-08-22 09:32:39
【问题描述】:

我希望使用 ggplot2 实现以下绘图配置,其中红色区域是绘图的“主”图,而蓝色区域是完全不同的图,我希望将其包含在大致显示的比例中。两张图都设计为方形。

我知道这在 base r 中是可能的,但不知道这对于 ggplot 是否可行。这甚至可能吗?如果是这样,我怎样才能在一个图中得到两个像这样配置的空白图?

【问题讨论】:

  • patchwork, cowplot
  • ... 和 gridExtra :使用 layout_matrix arg
  • stackoverflow.com/q/1249548/3358272 是一个好的开始,它包括grid 和对cowplot 的提及(即使它说“并排”,而不是“在拐角处”)问题说)。

标签: r ggplot2


【解决方案1】:

这是gridExtra::grid.arrange 方法。您可以设置 layout_matrix 参数,因为您希望绘图出现;空格使用NA

library(ggplot2)
library(gridExtra)

# We have two plots which are indexed 1 & 2
# the repeats of values give the space each plot will inhabit
lay = rbind(c(NA,NA,NA,1,1),
            c(NA,NA,NA,1,1),
            c(2,2,2,2,NA),
            c(2,2,2,2,NA),
            c(2,2,2,2,NA),
            c(2,2,2,2,NA))

grid.arrange(ggplot(), ggplot(), layout_matrix=lay)

【讨论】:

    猜你喜欢
    • 2012-09-01
    • 2014-11-12
    • 1970-01-01
    • 1970-01-01
    • 2012-08-20
    • 1970-01-01
    • 1970-01-01
    • 2014-10-09
    • 1970-01-01
    相关资源
    最近更新 更多