Re: [R] Adding text to page margin with lattice graphics

From: Jim Price <price_ja_at_hotmail.com>
Date: Thu, 07 Apr 2011 11:18:57 -0700 (PDT)

Hey Dennis,

As you've undoutedly discovered, par and lattice don't play well together, because they're different graphics systems.

Most of the par-esque functionality can be found in:

library(lattice)
names(trellis.par.get())

You can then drill down further using:

trellis.par.get('layout.heights')

for example.

To then use them in a call we need to use the par.settings parameter in xyplot:

library(lattice)
library(grid)

xyplot(

       1 ~ 1,
       par.settings = list(layout.heights = list(bottom.padding = 10)),
       page = function(page) grid.text('words', x = 0.5, y = 0.01)
)

For your second question - there's 2 pages going on - one is a parameter to the xyplot call, the second is the parameter to the (anonymous) function that's passed to the xyplot call. They're different things. When you specify the page parameter in the xyplot call, lattice calls the passed function each time it finishes drawing its page and passes it the current page number - but there's no requirement to call that parameter page if you don't want to:

xyplot(

       1 ~ 1,
       par.settings = list(layout.heights = list(bottom.padding = 10)),
       page = function(thepageparameter) grid.text('words', x = 0.5, y =
0.01)
)

One nice thing I've used in the past is something like this:

pager <- function(tot) function(current) grid.text(paste('Page', current, 'of', tot), x = 0.5, y = 0.01)

xyplot(

       1 ~ 1,
       par.settings = list(layout.heights = list(bottom.padding = 10)),
       page = pager(10)

)

So the pager function returns a function, and I use this returned function to give my proper page numbering.

Hope that helps,

Jim Price.
Cardiome Pharma Corp.

Dennis Fisher wrote:
>
> R: 2.12.1
> OS X
>
> Colleagues
>
> I am working with lattice graphics for the first time and I am confused by
> some aspects of controlling these graphics. The most pressing issue is
> the following:
>
> I can print the graphics without problems with the command:
> print(MYFUNCTION(SOMEOBJECT)
> However, I would like to add margin text (this terminology might not apply
> in this setting). I am able to do so with the following command:
> print(MYFUNCTION(SOMEOBJECT, page=function(page) grid.text("SOMETEXT",
> x=0.5, y=0.01)))
>
> Two issues:
> 1. The added text overlaps text in SOMEOBJECT. How do I reserve space at
> the margins of the page in which I can print the added text? (the
> equivalent of par(mar=c(1,1,1,1)))
>
> 2. I was able to construct the command with some assistance from a
> colleague. But, I remain at a loss to understand the syntax:
> page=function(page),
> i.e., page is a function of itself?
> Any help in interpreting the function would be appreciated.
>
> Dennis
>
> Dennis Fisher MD
> P < (The "P Less Than" Company)
> Phone: 1-866-PLessThan (1-866-753-7784)
> Fax: 1-866-PLessThan (1-866-753-7784)
> www.PLessThan.com
>
> ______________________________________________
> R-help_at_r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

--
View this message in context: http://r.789695.n4.nabble.com/Adding-text-to-page-margin-with-lattice-graphics-tp3433886p3434158.html
Sent from the R help mailing list archive at Nabble.com.

______________________________________________
R-help_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Received on Thu 07 Apr 2011 - 20:24:10 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Thu 07 Apr 2011 - 20:40:28 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive