【问题标题】:ggplot2 add two plots in grid.arrange with an inset in the second one in Rggplot2在grid.arrange中添加两个图,在R中的第二个中添加一个插图
【发布时间】:2016-10-31 21:05:45
【问题描述】:

我能够打印插图并从 ggplots 中的绘图创建网格。但是我无法创建一个网格,左边有一个图,右边有两个图,一个全尺寸,另一个在“插图”中。

a_plot <- ggplot(cars, aes(speed, dist)) + geom_line()

#The inset 
print(a_plot);print(a_plot, vp = vp)

# the Grid
lay <- rbind(c(1,1,1,2,2,2),
             c(1,1,1,2,2,2),
             c(1,1,1,2,2,2),
             c(1,1,1,2,2,2))
grid.arrange(a_plot, a_plot,layout_matrix = lay)

但我想要这个:

我该怎么做?

这行不通

grid.arrange(a_plot, a_plot,print(a_plot, vp = vp),layout_matrix = lay)

我试过this,也没用。

【问题讨论】:

  • 我可以使用它来创建插图,但之后不能将其放在网格上......

标签: r ggplot2 grid insets


【解决方案1】:
a_plot <- ggplot(cars, aes(speed, dist)) + geom_line()
b_plot <- a_plot + annotation_custom(grob = rectGrob(), 
                      xmin = 15, xmax = Inf, ymin=-Inf, ymax=25)


grid.arrange(a_plot, b_plot, ncol=2)

【讨论】:

  • b_plot coord_cartesian() 可能是如果对象是地图,则需要。代替reacGrob(),使用ggplotGrob()
猜你喜欢
  • 1970-01-01
  • 2014-04-12
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-04-11
  • 2019-11-09
  • 2016-08-01
  • 2021-04-16
相关资源
最近更新 更多