Embedding a miniature plot within a plot

后端 未结 3 1619
梦如初夏
梦如初夏 2020-12-05 00:43

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(

相关标签:
3条回答
  • 2020-12-05 01:11

    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

    0 讨论(0)
  • 2020-12-05 01:20

    Check out the Teaching Demos package package TeachingDemos package - and the subplot() function It might work on the lattice as well - haven't tried it though.

    0 讨论(0)
  • 2020-12-05 01:36

    You could try the gridBase package which provides some functionality for integrating base and grid-based graphics (including lattice and ggplot2). The example below embeds a base graphics plot inside of a lattice plot.

    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 detail here: http://casoilresource.lawr.ucdavis.edu/drupal/node/1007 And here: http://cran.r-project.org/web/packages/gridBase/vignettes/gridBase.pdf

    0 讨论(0)
提交回复
热议问题