[R] Settings of lattice graphs
hgoehlmann@gmx.de
hgoehlmann at gmx.de
Thu Oct 31 11:56:31 CET 2002
Thanks for the replies already. Still, with all your help I have not been
able to get what I wanted. Ok, I should be a little more detailed.
(1) I would like to create a function which draws a levelplot with a
colorkey at the bottom to a vectorized file (win.metafile)
(2) this function will receive data from a matrix that can vary in number of
rows and will visualize the data in the matrix - I am trying to use
levelplot because I get a nice colorkey with it - unlike image
(3) the colorkey should have a fixed height at the bottom (say 40 pixels)
(4) as the number of rows increases or decreases the size of the graphic
should change accordingly
BUT... the colorkey dimensions should be fixed (in terms of height of the
colorkey = the 40 pixels) and the height of the rows in the levelplot should
be fixed as well. And this is where the problem starts... I can define the
canvas size according to nrow(matrix) + x (for the colorkey) and even split
the canvas into two sections (using viewport), but since the levelplot always
draws a margin around itself (even though I am setting scales=list(draw=F) ),
the height of the rows in the levelplot varies with the number of rows I am
feeding into levelplot...
I hope my writing is understandable (and reproducable)...
Thanks very much already for any further suggestion!
Cheers,
hinrich d8-)
> 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