An embedded and charset-unspecified text was scrubbed... Name: not available Url: https://stat.ethz.ch/pipermail/r-help/attachments/20051019/ebe11aee/attachment.pl
adding error bars to lattice plots
5 messages · Bert Gunter, Mario Aigner-Torres, Deepayan Sarkar
?llines, lsegments and the like can be used in the panel functions to draw any sort of error bar that you can compute from the x,y,... data of the panel. -- Bert Gunter Genentech Non-Clinical Statistics South San Francisco, CA "The business of the statistician is to catalyze the scientific learning process." - George E. P. Box
-----Original Message-----
From: r-help-bounces at stat.math.ethz.ch
[mailto:r-help-bounces at stat.math.ethz.ch] On Behalf Of Mario
Aigner-Torres
Sent: Wednesday, October 19, 2005 2:34 PM
To: r-help at stat.math.ethz.ch
Subject: [R] adding error bars to lattice plots
Dear R-Users,
how to include error bars within lattice?
How should the panel = function(x,y,...){
looks like?
Does panel.arrows works here as well?
I appreciate any help on this.
Regards,
Mario AT
[[alternative HTML version deleted]]
______________________________________________ R-help at stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
An embedded and charset-unspecified text was scrubbed... Name: not available Url: https://stat.ethz.ch/pipermail/r-help/attachments/20051020/f9b2993f/attachment.pl
On 10/20/05, Mario Aigner-Torres <mario.aignertorres at gmail.com> wrote:
Thanks Bert! I have right now a dataset that looks like this:
tail(partition, 3)
element run logfO2 TC buffer xAn sdXan Di Disigma 416 Al 36 -0.68 1180 AIR 0.734 0.007 2.10 0.02 417 Ca 36 -0.68 1180 AIR 0.734 0.007 1.29 0.02 418 Na 36 -0.68 1180 AIR 0.734 0.007 1.16 0.06 Basicaly I would like to insert error bars into a xyplot like this
How are your error bars defined?
xyplot(log10(Di) ~ TC | element.ord, groups=buffer.ord, #pch=16,
+ #subset=no1140, + data=partition, + auto.key=list(columns=3), + ) How could llines, lsegments or perhaps panel.arrows look like? I appreciate any help on this. Best regards, Mario On 10/19/05, Berton Gunter <gunter.berton at gene.com> wrote:
?llines, lsegments and the like can be used in the panel functions to
draw
any sort of error bar that you can compute from the x,y,... data of the panel. -- Bert Gunter Genentech Non-Clinical Statistics South San Francisco, CA "The business of the statistician is to catalyze the scientific learning process." - George E. P. Box
-----Original Message-----
From: r-help-bounces at stat.math.ethz.ch
[mailto:r-help-bounces at stat.math.ethz.ch] On Behalf Of Mario
Aigner-Torres
Sent: Wednesday, October 19, 2005 2:34 PM
To: r-help at stat.math.ethz.ch
Subject: [R] adding error bars to lattice plots
Dear R-Users,
how to include error bars within lattice?
How should the panel = function(x,y,...){
looks like?
Does panel.arrows works here as well?
I appreciate any help on this.
Regards,
Mario AT
[[alternative HTML version deleted]]
______________________________________________ R-help at stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[[alternative HTML version deleted]]
______________________________________________ R-help at stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
6 days later
On 10/20/05, Mario Aigner-Torres <mario.aignertorres at gmail.com> wrote:
[...]
I have right now a dataset that looks like this:
tail(partition, 3)
element run logfO2 TC buffer xAn sdXan Di Disigma 416 Al 36 -0.68 1180 AIR 0.734 0.007 2.10 0.02 417 Ca 36 -0.68 1180 AIR 0.734 0.007 1.29 0.02 418 Na 36 -0.68 1180 AIR 0.734 0.007 1.16 0.06 Basicaly I would like to insert error bars into a xyplot like this
[...]
Generally speaking, you need to pass some auxiliary variables to the
panel function. This is easy to do, since all unrecognized arguments
are passed to the panel function anyway. The trick is to figure out
inside the panel function which elements of these variables correspond
to the subset of data in that panel. This is done using the subscripts
argument. So, for example, you can define
prepanel.ci <- function(x, y, lx, ux, subscripts, ...)
{
x <- as.numeric(x)
lx <- as.numeric(lx[subscripts])
ux <- as.numeric(ux[subscripts])
list(xlim = range(x, ux, lx, finite = TRUE))
}
panel.ci <- function(x, y, lx, ux, subscripts, pch = 16, ...)
{
x <- as.numeric(x)
y <- as.numeric(y)
lx <- as.numeric(lx[subscripts])
ux <- as.numeric(ux[subscripts])
panel.abline(h = unique(y), col = "grey")
panel.arrows(lx, y, ux, y, col = 'black',
length = 0.25, unit = "native",
angle = 90, code = 3)
panel.xyplot(x, y, pch = pch, ...)
}
and then add these to your call, supplying suitable values for lx and
ux (the vectors of lower and upper limits). The one glitch with this
approach is that unlike variables in the formula (and groups, which is
treated specially because of its ubiquity but otherwise works on
exactly the same principle), lx and ly will not be evaluated in
'data'. I like to use 'with' to get around this. Here's an example
with the singer data, it should be easy to translate to your example.
singer.split <-
with(singer,
split(height, voice.part))
singer.ucl <-
sapply(singer.split,
function(x) {
st <- boxplot.stats(x)
c(st$stats[3], st$conf)
})
singer.ucl <- as.data.frame(t(singer.ucl))
names(singer.ucl) <- c("median", "lower", "upper")
singer.ucl$voice.part <-
factor(rownames(singer.ucl),
levels = rownames(singer.ucl))
## show the data frame
singer.ucl
with(singer.ucl,
xyplot(voice.part ~ median,
lx = lower, ux = upper,
prepanel = prepanel.ci,
panel = panel.ci))
-Deepayan