Skip to content
Prev 256132 / 398503 Next

Adding text to page margin with lattice graphics

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:
--
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.