[R] Mtext and xyplot

Deepayan Sarkar
Mon, 03 Feb 2003 23:35:03 -0000

On Monday 03 February 2003 03:47 pm, Yang, Richard
wrote:
> Dear all;
>
> I wish to create a graphic object combing an xyplot() and an mtext().

You cannot. xyplot() uses grid for all its graphics, and grid graphics cannot
be used in conjunction with base R graphics functions.

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

And it does inside mtext ? (I don't see that on Linux, maybe it does on
Windows.)

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

maybe something like

  ylab = list(expression(bold("Volume...

(read ?plotmath)



> TIA,
>
> Richard
>
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> http://www.stat.math.ethz.ch/mailman/listinfo/r-help