1

I know that grid.arrange allows me to put two, or more, graphs beside each other with ggplot. How do I put a graph inside of another graph? If you can remember back to the 1990's this used to be called PIP Picture-In-Picture. Let's use this as our reproducible data.

library(ggplot2)
(plotx <- ggplot(mpg, aes(displ, hwy)) + geom_point())

In case you're not clear on what I want I'll try and ASCII it out below:

---------------------------------
|                               |
|                   ---------   |
|                   | plotx |   |
|                   ---------   |
|      same plotx               |
|                               |
---------------------------------
stackinator
  • 5,429
  • 8
  • 43
  • 84
  • 3
    Have a look at the [`egg` package](https://cran.r-project.org/web/packages/egg/). There is a function called `annotation_custom` that you might find useful. An example would be `library(egg); plotx + annotation_custom(ggplotGrob(plotx), xmin = 4.5, xmax = 6.5, ymin = 25, ymax = 40)` – markus Jun 14 '18 at 20:52

0 Answers0