[R] Adding error bars to xyplot()
David Winsemius
dwinsemius at comcast.net
Fri Apr 23 22:05:59 CEST 2010
On Apr 23, 2010, at 3:56 PM, Jon Zadra wrote:
> I took a look at xYplot() but it is beyond over-complex, at least
> for my level, and the documentation isn't too clear.
>
> Is there a simple way to make functions like plotCI() and errbar()
> use the lattice reference rather than base graphics?
Don't know about simple. You seem to be rejecting one by one the
"simple" methods people have offered. Why not do a bit of searching on
your own, since you have a different standard for "simple" than some
of the rest of us:
RSiteSearch("lattice error bars")
RSiteSearch("lattice confidence intervals")
--
David.
>
> It seems like creating a plot of two lines across three time points
> separated into two groups should be a very basic, simple thing for a
> statistics program to do. Is there really no way to simply pass a
> model to a plotting function and get something that includes error
> bars? I just wonder if I"m missing how to do this "the easy way."
>
> Thanks,
>
> Jon
> Jon Zadra
> Department of Psychology
> University of Virginia
> P.O. Box 400400
> Charlottesville VA 22904
> (434) 982-4744
> email: zadra at virginia.edu
> <http://www.google.com/calendar/embed?src=jzadra%40gmail.com>
>
> On 4/21/2010 6:47 PM, David Winsemius wrote:
>>
>> On Apr 21, 2010, at 6:24 PM, Jon Zadra wrote:
>>
>>> Hi,
>>>
>>> I want to add error bars to a plot generated with xyplot. I've
>>> tried both errbar() and plotCI(), but in both cases the points are
>>> not in the same place. It's as if the two functions are using a
>>> different frame of reference for the plotting area.
>>
>> Yes. plotCI uses base graphics while xyplot is a lattice function.
>>
>>>
>>> for example:
>>> means <- c(92.5, 92.25, 90.9, 91.0, 94.15, 90.05) #means
>>> time <- c(1,1,2,2,3,3) #occasion variable
>>> group <- rep(c("n","u"),3) #grouping variable
>>> SE <- c(2.22, 1.66, 2.10, 1.43, 2.31, 1.57) #standard errors
>>>
>>> #Plot the graph
>>> xyplot(means ~ time, groups=group, type="o", lwd=3, main="Change
>>> Over Time by Condition", scale=list(cex=2), xlab="Test Number",
>>> auto.key=T)
>>>
>>> #first attempt
>>> require(Hmisc)
>>> errbar(x = time, y = means, yplus = means + SE, yminus = means -
>>> SE, add=T, col=c("blue", "hotpink"))
>>
>> A base graphics function.
>>>
>>> #second attempt, same result
>>> require(gplots)
>>> plotCI(x = time, y = means, uiw = SE, add=T)
>>
>> Another base graphics function.
>>
>> Since you already have Hmisc why not check out Harrell's xYplot
>> which provides CI's in a grid function:
>> From the xYplot examples:
>>
>> require(Hmisc)
>> dfr <- expand.grid(month=1:12, continent=c('Europe','USA'),
>> sex=c('female','male')) set.seed(1)
>> dfr <- upData(dfr, y=month/10 + 1*(sex=='female') +
>> 2*(continent=='Europe') +
>> runif(48,-.15,.15),
>> lower=y - runif(48,.05,.15),
>> upper=y + runif(48,.05,.15))
>> xYplot(Cbind(y,lower,upper) ~ month|continent,
>> subset=sex=='male',data=dfr)
>>>
>>>
>>> Thanks in advance!
>>>
>>> - Jon
>>>
>>> --
>>> Jon Zadra
>>> Department of Psychology
>>> University of Virginia
>>> P.O. Box 400400
>>> Charlottesville VA 22904
>>> (434) 982-4744
>>> email: zadra at virginia.edu
>>> <http://www.google.com/calendar/embed?src=jzadra%40gmail.com>
>>>
>>> ______________________________________________
>>> R-help at r-project.org mailing list
>>> https://stat.ethz.ch/mailman/listinfo/r-help
>>> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
>>> and provide commented, minimal, self-contained, reproducible code.
>>
>> David Winsemius, MD
>> West Hartford, CT
>>
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
David Winsemius, MD
West Hartford, CT
More information about the R-help
mailing list