[R] newline in lattice axis label

Renaud Lancelot renaud.lancelot at cirad.fr
Thu Apr 7 07:35:23 CEST 2005


Sebastian Luque a écrit :

> 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,

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

-- 
Dr Renaud Lancelot, vétérinaire
C/0 Ambassade de France - SCAC
BP 834 Antananarivo 101 - Madagascar

e-mail: renaud.lancelot at cirad.fr
tel.:   +261 32 40 165 53 (cell)
         +261 20 22 665 36 ext. 225 (work)
         +261 20 22 494 37 (home)




More information about the R-help mailing list