2
votes

I'm having difficulties to write correctly a strip name in a lattice plot. Here is a data example:

    resposta<-rnorm(90)
    preditor1<-rep(rep(c("a","b"),each=15),3)
    preditor2<-rep(c("sp1","sp2","sp3"),each=30)

And I'm doing the following plot:

    library(lattice)
    bwplot(resposta~preditor1|preditor2,layout=c(3,1),
           strip=strip.custom(
               factor.levels=c(
                   expression(atop(italic("P. paradoxa"),"outra info")),
                   expression(atop(italic("H. raniceps"),"outra info")),
                   expression(atop(italic("P. azurea"),"outra info")))
           ),
           par.settings=list(layout.heights=list(strip=2.5))
           )

My question is, are there a way to get a smaller space between the species name and "outra info". This problem started because, as the title are species names, they need to be in italic, but I also need to add some extra information on the title, and this should not be in italic. I saw on Google the possibility to use atop inside an expression to get 2 lines of text, but I get a too big space between the species name and the next line. I would like them to be closer together, but I don't know if it is possible, and if so, how to do it.

Does anyone know how to skip lines in the strip name, keeping the expression for the italics but not make too much space between names? It's not so bad on the plot, but when I use tiff() to save to a image with a greater size, the strip names are missing some parts, basically due to the distance between the lines, I think.

1

1 Answers

2
votes

As explained by Duncan Murdoch via the R-help mailing list, this problem cannot be easily solved without employing atop (which results, in your particular case, in undesirably large line spacing). However, you could achieve your goal manually by navigating to the respective strip panels using downViewport and subsequently inserting the two lines of text separately using grid.text.

## create plot with invisible strip labels
bwplot(resposta ~ preditor1 | preditor2, layout = c(3, 1),
       par.settings = list(layout.heights = list(strip = 2.5)), 
       par.strip.text = list(col = "transparent")
)

## add species labels
lbl <- c("P. paradoxa", "H. raniceps", "P. azurea")

for (i in 1:3) {
  # navigate to i-th strip
  vp <- paste0("plot_01.strip.", i, ".1.vp")
  downViewport(vp)

  # add first and second line of text
  grid.text(bquote(italic(.(lbl[i]))), vjust = ifelse(i %in% 1:2, 0, -.25))
  grid.text("outra info", vjust = 1.1)

  # navigate to top level
  upViewport(0)
}

paneled_plot

Also, make sure to have a look at current.vpTree() which returns the current panel structure of your trellis graph. Once you redefine the panel layout, add another group, etc., you will most likely have to adjust the creation of the panel name to navigate to (object "vp") inside the for loop.