Chris Bergstresser
2006-May-13 23:05 UTC
[R] Adding error bars to a trellis barchart display
Hi all -- I'm using trellis to generate bar charts, but there's no built-in function to generate error bars or confidence intervals, as far as I can tell. I assumed I could just write my own panel function to add them, so I searched the archive, and found a posting from the author of the package stating "... placing multiple bars side by side needs specialized calculations, which are done within panel.barchart. To add bars to these, you will need to reproduce those calculations." Just so I'm clear on this -- there's no capacity to add bars to the plot, nor to find out the coordinates of the bars in the graphs themselves. If you want them, you have to completely rewrite panel.barchart. Is this correct? Are there really so few people using error bars with bar charts? -- Chris
Chris Bergstresser wrote:> Hi all -- > > I'm using trellis to generate bar charts, but there's no built-in > function to generate error bars or confidence intervals, as far as I > can tell. I assumed I could just write my own panel function to add > them, so I searched the archive, and found a posting from the author > of the package stating "... placing multiple bars side by side needs > specialized calculations, which are done within panel.barchart. To add > bars to these, you will need to reproduce those calculations." > Just so I'm clear on this -- there's no capacity to add bars to the > plot, nor to find out the coordinates of the bars in the graphs > themselves. If you want them, you have to completely rewrite > panel.barchart. Is this correct? Are there really so few people > using error bars with bar charts?One of our projects does confidence intervals on bar cahrts produced using teh lattice library. It is quite feasible without too much effort - see: http://members.optusnet.com.au/tchur/NetEpi-Analysis-0-8-Screenshot-5.png Sorry I don't have time to extract the code which does this right now, but you can dissect it out yourself from the NetEpi-Analysis-0.8 tarball at http://sourceforge.net/project/showfiles.php?group_id=123700 - although the R code is embedded in Python classes, which might make extrication a bit more difficult (and which is why I don't have time to do it right now). But from memory the chunk of R code which overrides the default panel function is fairly self-contained and you should be able to identify it fairly easily - just grep the source code for likely strings such as "panel.barchart" to discover where it is. Other screenshots can be downloaded from http://sourceforge.net/project/showfiles.php?group_id=123700 if anyone is interested. Tim C
On 5/13/06, Chris Bergstresser <chris at subtlety.com> wrote:> Hi all -- > > I'm using trellis to generate bar charts, but there's no built-in > function to generate error bars or confidence intervals, as far as I > can tell. I assumed I could just write my own panel function to add > them, so I searched the archive, and found a posting from the author > of the package stating "... placing multiple bars side by side needs > specialized calculations, which are done within panel.barchart. To add > bars to these, you will need to reproduce those calculations." > Just so I'm clear on this -- there's no capacity to add bars to the > plot, nor to find out the coordinates of the bars in the graphs > themselves. If you want them, you have to completely rewrite > panel.barchart. Is this correct? Are there really so few people > using error bars with bar charts?I would hope so, since bar charts with error bars are horrible things, in my opinion. Lattice comes with an example of (standard) confidence intervals (new in R 2.3.0) that can be accessed by running library(lattice) demo(intervals) The Hmisc package also has high level interfaces that support confidence intervals (I'm not familiar with the details). -Deepayan