Skip to content
Prev 76837 / 398502 Next

Leading in line-wrapped Lattice axis value and panel labels

Hi
Tim Churches wrote:
I don't think lattice explicitly sets lineheight so you could try 
something like the following (push a [full-page] grid viewport that sets 
lineheight then draw lattice plot within that) ...

library(grid)
library(lattice)
states <- data.frame(state.x77,
                      state.name = dimnames(state.x77)[[1]],
                      state.region = factor(state.region))
levels(states$state.region) <-
     c("Northeast", "South", "North\n Central",  "West")
xyp <- xyplot(Murder  ~ Population | state.region, data = states,
        groups = as.character(state.name),
        panel = function(x, y, subscripts, groups)
        ltext(x = x, y = y, label = groups[subscripts], srt = -50,
              col = "blue",
              cex=.9, fontfamily = "HersheySans"),
        par.strip.text = list(cex = 1.3, font = 4, col = "brown",
                              lines = 2),
        xlab = "Estimated Population\nJuly 1, 1975",
        ylab = "Murder Rate \n(per 100,000 population)\n 1976",
        main = "Murder Rates in US states")
# default line height for comparison
print(xyp)
# control line height
grid.newpage()
pushViewport(viewport(gp=gpar(lineheight=0.8)))
print(xyp, newpage=FALSE)
popViewport()

... this does not work perfectly for me, but I'm not sure (yet) whether 
that is a problem in grid, a problem in lattice, or a problem with 
Hershey fonts (that are used in this example) so your mileage may vary.

Paul