[R] panel.rect and log scale in lattice plot
Ebert,Timothy Aaron
tebert @end|ng |rom u||@edu
Wed Mar 23 11:15:23 CET 2022
Have you tried the ggplot2 package?
http://www.sthda.com/english/wiki/ggplot2-add-straight-lines-to-a-plot-horizontal-vertical-and-regression-lines
Tim
-----Original Message-----
From: R-help <r-help-bounces using r-project.org> On Behalf Of Garbade, Sven via R-help
Sent: Wednesday, March 23, 2022 5:39 AM
To: r-help using r-project.org
Subject: [R] panel.rect and log scale in lattice plot
[External Email]
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:
library(lattice)
set.seed(1)
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)
panel.xyplot(x,y,...)
},
scales=list(y=list(log=FALSE))
)
However, when log=TRUE, the rectangle disappears.
Are there any ideas? Thanks, Sven
<https://urldefense.proofpoint.com/v2/url?u=https-3A__mail.med.uni-2Dheidelberg.de_questions_tagged_-2CDanaInfo-3Dstackoverflow.com-2CSSL-2Br&d=DwICAg&c=sJ6xIWYx-zLMB3EPkvcnVg&r=9PEhQh2kVeAsRzsn7AkP-g&m=FpPsvaC4RAcwCFXTkiSHekD-Kq42a0hxUJvGstcn9J-97cF_sKhux4I2Q2Xoys4N&s=zoK3I2T0bpTMEgeKFzwh3IGQsunArwGKt734uAuYKY4&e= >
[[alternative HTML version deleted]]
______________________________________________
R-help using r-project.org mailing list -- To UNSUBSCRIBE and more, see https://urldefense.proofpoint.com/v2/url?u=https-3A__stat.ethz.ch_mailman_listinfo_r-2Dhelp&d=DwICAg&c=sJ6xIWYx-zLMB3EPkvcnVg&r=9PEhQh2kVeAsRzsn7AkP-g&m=FpPsvaC4RAcwCFXTkiSHekD-Kq42a0hxUJvGstcn9J-97cF_sKhux4I2Q2Xoys4N&s=Ah56En_K57pgqMo-alPPK_pxyzmHpZt4xF7hO3DDpS4&e=
PLEASE do read the posting guide https://urldefense.proofpoint.com/v2/url?u=http-3A__www.R-2Dproject.org_posting-2Dguide.html&d=DwICAg&c=sJ6xIWYx-zLMB3EPkvcnVg&r=9PEhQh2kVeAsRzsn7AkP-g&m=FpPsvaC4RAcwCFXTkiSHekD-Kq42a0hxUJvGstcn9J-97cF_sKhux4I2Q2Xoys4N&s=Sf4-2puTGAtpoZr1CNzG7wyOZFcVptczggv4aoWUji0&e=
and provide commented, minimal, self-contained, reproducible code.
More information about the R-help
mailing list