[R] Mtext and xyplot

Yang, Richard
Mon, 03 Feb 2003 22:49:05 -0000

Dear all;

I wish to create a graphic object combing an xyplot() and an mtext(). My
code looks like following,

gmv <-  {
         trellis.device("windows", bg="white", width = 7,
height = 7)

  xyplot(Mvol  ~ Age | Nl * Th , data = Hft1,

  prepanel = function(x, y) prepanel.loess(x, y, span = 1),
        xlab =list(label = "Age (Years)", font = 2),
        ylab = " ",
#        ylab = list(expression(paste("Volume ( ", paste(m^3/ha,
")"), sep" ")), font=2),
         main = list(" Volume"),
         par.strip.text = list(cex=1.0, font = 2),
       panel = function(x, y)  {
         panel.grid ()
         panel.xyplot(x,y, col= "black")
         panel.lmline(x, y, lty = 2, lwd = 2)
         panel.loess(x, y, span = 1, degree = 1, lty=1, lwd=2) } )
         mtext(expression(paste("Volume ( ", paste(m^3/ha,
")"), sep = "
")), outer=T,
font = 2, side = 2, line = -1 )
         }

The mtext() is to replace the ylab because the font = 2 in the above
commented line does not result in a bold font as in the xlab. The code
within the outmost { } works fine on a windows device  but generates error
when it runs as a function:

Error in mtext(expression(paste("Volume ( ", paste(m^3/ha,
")"),  :
        plot.new has not been called yet

Any suggestions to rectify the error?

TIA,

Richard