[R] panel.rect and log scale in lattice plot

Garbade, Sven Sven@G@rb@de @end|ng |rom med@un|-he|de|berg@de
Wed Mar 23 11:48:44 CET 2022


thanks, this do the trick!

xyplot(y ~ x,
       panel=function(x,y, ...) {
           cpl <- current.panel.limits()
           yseq <- log(c(100,1000))
           panel.rect(xleft=cpl$xlim[1],
                      ybottom=yseq[1],
                      xright=cpl$xlim[2],
                      ytop=yseq[2],
                      fill="lightgray", border="lightgray", alpha=.6)
           panel.xyplot(x,y,...)
       },
       scales=list(y=list(log=2))
       ) 

Best Regards, Sven
________________________________________
Von: Ivan Krylov <krylov.r00t using gmail.com>
Gesendet: Mittwoch, 23. März 2022 11:33
An: Garbade, Sven via R-help
Cc: Garbade, Sven
Betreff: Re: [R] panel.rect and log scale in lattice plot

On Wed, 23 Mar 2022 09:38:34 +0000
"Garbade, Sven via R-help" <r-help using r-project.org> wrote:

>            cpl <- current.panel.limits()

If you str() the return value of current.panel.limits() from the panel
function with log-scaling enabled, you can see that it contains the
logarithm of the y-values, as do the y values themselves. This is
consistent with ?xyplot saying:

>> Note that this is in reality a transformation of the data, not the
>> axes. Other than the axis labeling, using this feature is no
>> different than transforming the data in the formula; e.g.,
>> ‘scales=list(x = list(log = 2))’ is equivalent to ‘y ~ log2(x)’.

...although it could be more explicit.

If you take a logarithm of 10 and 500, lrect() should be able to
produce a rectangle in the right place.

--
Best regards,
Ivan



More information about the R-help mailing list