[R] Adding text to page margin with lattice graphics
Jim Price
price_ja at hotmail.com
Thu Apr 7 20:18:57 CEST 2011
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.
More information about the R-help
mailing list