[R] current.panel.limits() of lattice returning NaN limits - why?

Fredrik Karlsson dargosch at gmail.com
Fri Aug 12 08:45:05 CEST 2011


Hi,

I need a custom axis function for a plot, but it seems
that current.panel.limits() sometimes returns NaN limits for the plot, which
it much harder to calculate anything sensible.
An illustration:

Given this axis function:


vs.axis <- function(...){
   xlim <- current.panel.limits()$xlim
   ylim <- current.panel.limits()$ylim

   # Debug code
   print(list(ylim=ylim,xlim=xlim))

   xat <- pretty(seq(xlim[1],xlim[2],100),n=5)
   yat <- pretty(seq(ylim[1],ylim[2],100),n=4)
   xlab <- sub("-","",as.character(xat))
   ylab <- sub("-","",as.character(yat))
   panel.axis(side="top",at=xat,labels=xlab)
   panel.axis(side="right",at=yat,labels=ylab)
}

and the attached data set, I get this output:

> xyplot(F1 ~F2,data=pb,axis=vs.axis)
$ylim
[1] NaN NaN

$xlim
[1]  346.5 3823.5

Error in if (del == 0 && to == 0) return(to) :
  missing value where TRUE/FALSE needed

What's wrong? Is there a more robust way of getting the x- and y- limits?

/Fredrik

-- 
"Life is like a trumpet - if you don't put anything into it, you don't get
anything out of it."


More information about the R-help mailing list