[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 10:38:34 CET 2022

Dear all,

I posted this on Stack Overflow, but there is no response, so I try it here again.

I'm wondering about how to draw a highlighted rectangle with log y-axis in a trellis/lattice plot. My idea was to use panel.rect(), which works without a log scale:



y <- runif(100, min=1, max=1000)
x <- seq_along(y)

xyplot(y ~ x,
       panel=function(x,y,...) {
           cpl <- current.panel.limits()
           panel.rect(xleft=cpl$xlim[1], ybottom=10,
                      xright=cpl$xlim[2], ytop=500,
                      fill="lightgray", border="lightgray", alpha=.6)


However, when log=TRUE, the rectangle disappears.

Are there any ideas? Thanks, Sven


	[[alternative HTML version deleted]]

More information about the R-help mailing list