[R] Hopefully an easy error bar question

Martin Maechler maechler at stat.math.ethz.ch
Sat Sep 6 16:40:03 CEST 2008


>>>>> "FEH" == Frank E Harrell <f.harrell at vanderbilt.edu>
>>>>>     on Sat, 06 Sep 2008 07:19:33 -0500 writes:

    FEH> Brown, Heidi wrote:
    >> Hi im trying to add error bars to my barplots, there very basic, i have a few grapghs where the y variable is different but on all the X variable is Age (Adult and Juvenile) however this is split into two levels so i have males and females, so my graph basically has four bars on it.
    >> 
    >> I know how to add eror bars for instance when there is only one level eg lookng at the diffrence between male and female lizards and tree height and have used the code:
    >> 
   
    >> error.bars<-function(yv,z,nn) {
    >> xv<-
    >> barplot(yv,ylim=c(0,(max(yv)+max(z))),names=nn,ylab=deparse(substitute(yv)
    >> ))

    [ omitting the abomination ]

    >> Have then worked out the standard errors and added that using:
    >> 
    >> se<-c()
    >> 
    >> and then added the final bit of code:
    >> 
    >> labels<-as.character(levels(Sex2))
    >> ybar<-as.vector(tapply(Height2,Sex2,mean))
    >> error.bars(ybar,se,labels)
    >> 
    >> So i was wondering, in order to get error bars on my barplot with two levels do i need to change the last bit of code. For example im looking at mean body condition (y) against age (x) and sex (level), i tried to change the code to the following but it didnt work, any suggestions?
    >> 
    >> labels<-as.character(levels(list(sex,Age)))
    >> ybar<-as.vector(tapply(ConditionIndex,sex,Age,mean))
    >> error.bars(ybar,se,labels)

    FEH> See http://biostat.mc.vanderbilt.edu/DynamitePlots for many reasons not 
    FEH> to use dynamite plots.

Ah!  Very good!  Let's hope this eventually leads to progress 
i.e., to much less use of these..

Thank you, Frank!
Martin Maechler, ETH Zurich


    FEH> -- 
    FEH> Frank E Harrell Jr   Professor and Chair           School of Medicine
    FEH> Department of Biostatistics   Vanderbilt University

    FEH> ______________________________________________
    FEH> R-help at r-project.org mailing list
    FEH> https://stat.ethz.ch/mailman/listinfo/r-help
    FEH> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
    FEH> and provide commented, minimal, self-contained, reproducible code.



More information about the R-help mailing list