[R] Settings of lattice graphs

Paul Murrell p.murrell at auckland.ac.nz
Wed Oct 30 22:48:53 CET 2002


Hi


Deepayan Sarkar wrote:
> 
> On Wednesday 30 October 2002 06:16 am, hgoehlmann at gmx.de wrote:
> > I am trying to modify the outer margin of a lattice graph and I am just not
> > sure whether this is possible or not - something like
> >
> > par(c(5, 4, 4, 2) + 0.1)
> >
> > Is there such a thing?
> 
> No, as far as lattice is concerned. par() settings do not affect grid (hence
> lattice) graphics. If you want to leave out space outside the plot, use the
> position argument in print.trellis.


It is also possible to place lattice plots within generic grid
viewports, which allow you to manipulate the space around the plot in
many different ways.  See the last example in example(print.trellis) --
the important bit is the newpage=FALSE -- also, the following gives a
simple example where the margins could be increased by a number of lines
on each side of the lattice plot ...

    library(lattice)
    x <- y <- 1:10
    myplot <- xyplot(y ~ x)
    
    grid.newpage()
    grid.rect(gp=gpar(col=NULL, fill=trellis.par.get("background")$col))
    push.viewport(plotViewport(c(5, 4, 4, 2) + 0.1))
    print(myplot, newpage=FALSE)
    # Just to show where the extra margin starts
    grid.rect(gp=gpar(lty="dashed"))
    pop.viewport()

... and here's a more complex example that gives a bit of an idea of the
flexibility you can get if you work a bit harder ...

    # Grid viewport to place lattice plot within within
    widths <- unit(c(1, 1, 3), c("inches", "null", "lines"))
    heights <- unit(c(0.1, 1, 1), c("npc", "null", "cm"))
    push.viewport(viewport(layout=grid.layout(3, 3,
                             widths=widths,
                             heights=heights)))
    # Draw the lattice plot
    push.viewport(viewport(layout.pos.col=2,
                           layout.pos.row=2))
    print(myplot, newpage=FALSE)
    pop.viewport()
    # Some annotation of the margins
    push.viewport(viewport(layout.pos.col=1,
                           layout.pos.row=2))
    grid.text("1 inch")
    pop.viewport()
    push.viewport(viewport(layout.pos.col=3,
                           layout.pos.row=2))
    grid.text("3 lines")
    pop.viewport()
    push.viewport(viewport(layout.pos.col=2,
                           layout.pos.row=3))
    grid.text("1 cm", rot=90)
    pop.viewport()
    push.viewport(viewport(layout.pos.col=2,
                           layout.pos.row=1))
    grid.text("0.1 npc", rot=90)
    pop.viewport(2)

Hope that helps :)

Paul
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list