Embedding a miniature plot within a plot

Backlin picture Backlin · Oct 17, 2011 · Viewed 8.8k times · Source

Does anybody know of a general way to embed plots into other plots to produce something like the mockup below?

I know that in lattice you can do it with print(..., more=TRUE, positions=...) as explained in this question, and I guess ggplot has a solution to it aswell (but I'm not very good with ggplot). The problem is that I want to embed a regular plot from the survival package that use the standard graphics package into a lattice plot.

A mockup of an embedded plot

Thanks in advance!

Answer

ROLO picture ROLO · Oct 17, 2011

And here is a way to do it the other way around, ggplot2 graphic in a base graphic:

require(ggplot2)
require(grid)

plot(sin, -pi, 2*pi)
qp <- qplot(mpg, wt, data=mtcars)
print(qp, vp=viewport(.8, .75, .2, .2))

enter image description here