I know that when you use par( fig=c( ... ), new=T )
, you can create inset graphs. However, I was wondering if it is possible to use ggplot2 library to create 'inset' graphs.
UPDATE 1: I tried using the par()
with ggplot2, but it does not work.
UPDATE 2: I found a working solution at ggplot2 GoogleGroups using grid::viewport()
.
Section 8.4 of the book explains how to do this. The trick is to use the
grid
package'sviewport
s.Alternatively, can use the
cowplot
R package by Claus O. Wilke (cowplot
is a powerful extension ofggplot2
). The author has an example about plotting an inset inside a larger graph in this intro vignette. Here is some adapted code:I prefer solutions that work with ggsave. After a lot of googling around I ended up with this (which is a general formula for positioning and sizing the plot that you insert.
Much simpler solution utilizing
ggplot2
andegg
. Most importantly this solution works withggsave
.