1

I'm able to print an inset and to create a grid from plots in ggplots. But I'm not able to create a grid with a plot on the left and 2 plots on the right one full size and the other in "inset".

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

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

enter image description here

# 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)

enter image description here

But I would like to have this:

enter image description here

How can I do this?

This doesn't work

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

I tried this and it didn't work either.

Community
  • 1
  • 1
M. Beausoleil
  • 3,141
  • 6
  • 29
  • 61

1 Answers1

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)

enter image description here

baptiste
  • 75,767
  • 19
  • 198
  • 294
  • b_plot <- a_plot+coord_cartesian() + annotation_custom(grob = ggplotGrob(a_plot), xmin = -90.2, xmax = Inf, ymin=-Inf, ymax=-0.8) `coord_cartesian()` might be needed if the object is a map. Instead of `reacGrob()`, use `ggplotGrob()` – M. Beausoleil Oct 31 '16 at 23:58