Skip to content

newline in lattice axis label

3 messages · Sébastien Bihorel, Renaud Lancelot

#
Hi,

I have a 3 panel xyplot with different variables in the y axis. I'm trying
to insert a newline after "Width (cm)," in the ylab argument as in the
example below. My goal is to have the y axis label broken into two lines,
split after the string just mentioned.

plotfun <- function() {
  fakedf <- data.frame(A = sample(1:100, 50),
                       B = rnorm(50),
                       C = rnorm(50),
                       D = rnorm(50))
  myplot <- xyplot(B + C + D ~ A, data = fakedf,
                   outer = TRUE, allow.multiple = TRUE, layout = c(1,3),
                   ylab = list(expression(paste(
                       "VarB (cm" ^2, "), VarC (cm),\n or VarD (cm)"))),
                   xlab = list("VarA (d)"))
  postscript("testfig.eps")
  print(myplot)
  dev.off()
}

As you can see, this is not producing the desired result, which is
probably associated with 3 warnings:

Warning messages: 
1: font metrics unknown for character 10 
2: font metrics unknown for character 10 
3: font metrics unknown for character 10 

Any help defining the ylab argument in this case is greatly appreciated.

Thanks in advance,
#
Sebastian Luque <sluque at mun.ca> wrote:

            
Sorry, that should be "VarC (cm)," in the hypothetical example below!
#
Sebastian Luque a ?crit :
library(lattice)
plotfun <- function() {
   fakedf <- data.frame(A = sample(1:100, 50),
                        B = rnorm(50),
                        C = rnorm(50),
                        D = rnorm(50))
   myplot <- xyplot(B + C + D ~ A, data = fakedf,
    outer = TRUE, allow.multiple = TRUE, layout = c(1,3),
    ylab = expression(atop(paste("VarB (", cm^2, "), VarC (cm)"),
                           "VarD (cm)")),
                    xlab = "VarA (d)")
   postscript("testfig.eps")
   print(myplot)
   dev.off()
}

plotfun()

Best,

Renaud