Attaching a miniature plot to the plot

Does anyone know a general way to embed graphs in other graphs to create something like the layout below?

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

A mockup of an embedded plot

Thanks in advance!

+19
r plot lattice
Oct 17 2018-11-12T00:
source share
3 answers

You can try the gridBase package, which provides some functions for integrating base and grid graphics (including grid and ggplot2). In the example below, a basic graphic is embedded within the grid area.

 library(lattice) library(gridBase) library(grid) plot.new() pushViewport(viewport()) xvars <- rnorm(25) yvars <- rnorm(25) xyplot(yvars~xvars) pushViewport(viewport(x=.6,y=.8,width=.25,height=.25,just=c("left","top"))) grid.rect() par(plt = gridPLT(), new=TRUE) plot(xvars,yvars) popViewport(2) 

More details here: http://casoilresource.lawr.ucdavis.edu/drupal/node/1007 And here: http://cran.r-project.org/web/packages/gridBase/vignettes/gridBase.pdf

+17
Oct. 17 '11 at 2:55 a.m.
source share

And here is a way to do it the other way around, the ggplot2 graphic file in the 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

+24
Oct 17 2018-11-17T00:
source share

Take a look at the TeachingDemos package, a package of training packages - and the subplot() function. It can work on a grid as well - you don't need to try it, though.

+3
Oct 17 2018-11-11T00:
source share



All Articles