6

I would like to fit a whole lattice plot in a small region of an existing plot.

xyplot(decrease ~ treatment, OrchardSprays, groups = rowpos, type = "a")
pushViewport(viewport(.2, .7, .2, .2))
grid.rect(gp=gpar(fill="white"))

gives me this:

enter image description here

So viewport is pushed. But when if a lattice function is called again, it uses the whole device, as if calling grid.newpage():

xyplot(decrease ~ treatment, OrchardSprays, groups = rowpos, type = "a")

Is there a way to limit lattice plots to a predefined region on a device like in my example above?

Richie Cotton
  • 118,240
  • 47
  • 247
  • 360
VitoshKa
  • 8,387
  • 3
  • 35
  • 59

1 Answers1

6

You have to directly call print with newpage argument set to FALSE (opposite to default value):

xyplot(decrease ~ treatment, OrchardSprays, groups = rowpos, type = "a")
pushViewport(viewport(.2, .7, .2, .2))
print(xyplot(decrease ~ treatment, OrchardSprays, groups = rowpos, type = "a"), newpage=FALSE)

You could find it in grid manual (r_instalation_path/library/grid/doc/grid.pdf), section "Adding lattice to grid".

enter image description here

Marek
  • 49,472
  • 15
  • 99
  • 121