[R] panel.text and saving to pdf

willem vervoort willemvervoort at gmail.com
Mon Jun 29 00:44:47 CEST 2009


Hi all,
IN the end the page() function was what I wanted. I was using
levelplot in the actual code and I wanted different text in each of
the panels. That was only possible with the paeg function or with
trellis.focus()

Thanks for the tips
Willem

On Sat, Jun 27, 2009 at 3:14 AM, Deepayan
Sarkar<deepayan.sarkar at gmail.com> wrote:
> On Fri, Jun 26, 2009 at 1:53 AM, Dieter
> Menne<dieter.menne at menne-biomed.de> wrote:
>> Willem Vervoort <w.vervoort <at> usyd.edu.au> writes:
>>
>>> I am not sure what I am doing wrong, but I have some unexplained behaviour
>> when saving a lattice graph
>>> including text to a pdf file. The text seems to move around. It must have
>> something to do with the way
>>> coordinates are set in devices other than jpg.
>>>
>>> today <- format(Sys.Date(),"%Y%m%d")
>>>
>>> x <- runif(500)
>>> y <- rnorm(500)
>>>
>>> foo <- data.frame(x = x, y = y, z = rep(c("a","b"),250))
>>> require(lattice)
>>>
>>> xyplot(x~y|z,data=foo)
>>> panel.text(370,470,"silly graph",cex=1.2,font=2)
>>
>> Take this plot, resize its window: you will note that the "silly graph" moves
>> relative to the graphics. The same is true for the higher-resolution pdf output.
>
> Yes, and that this even works at all is an accident of implementation.
> Once a lattice graph is drawn, the only officially supported way to
> add to it is to use trellis.focus() (or it's underlying grid
> equivalent downViewport()), e.g.;
>
> xyplot(1:10 ~ 1:10)
> trellis.focus("toplevel") ## has coordinate system [0,1] x [0,1]
> panel.text(0.5, 0.2, "silly graph", cex = 1.2, font = 2)
> trellis.unfocus()
>
> If you know beforhand what you want to add, another option is to use
> the page argument:
>
> xyplot(1:10 ~ 1:10,
>       page = function(n) {
>           panel.text(0.5, 0.2, "silly graph", cex = 1.2, font = 2)
>       })
>
> -Deepayan
>



-- 
http://blogs.usyd.edu.au/waterhydrosu/




More information about the R-help mailing list