Lattice barchart with error bars
On Jul 5, 2013, at 11:15 AM, Shaun Jackman wrote:
Hi Bert, Dennis, I'll agree that using a barchart was a poor choice. I was in fact using a notched bwplot to show the median and confidence interval of the median. In this case it's the median and confidence interval that I want to highlight, and I find that the visual noise of the box and whiskers is detracting from the focus, and those wee notches are not much to focus on. So, I'd like to draw a stripplot with error bars, preferably in Lattice. Let's call this a TIE fighter plot. Any suggestions?
I like the TIE fighter label. Try this:
library(latticeExtra)
data(USCancerRates)
segplot(reorder(factor(county), rate.male) ~ LCL95.male + UCL95.male,
data = subset(USCancerRates, state == "Washington"),
draw.bands = FALSE, centers = rate.male,
segments.fun = panel.arrows, ends = "both",
angle = 90, length = 1, unit = "mm")
It's what Sarkar has recommended in the past when this request has been posted.
David > Cheers, > Shaun > > On 4 July 2013 18:00, Dennis Murphy <djmuser at gmail.com> wrote: > >> If you consult the lattice package help, you'll discover there is no >> panel_errorbar() function, which would imply the package developers >> have a distaste for that type of graphic. If you fish around the >> R-help archives, though, you might be able to find someone who wrote a >> function to do error bars in lattice. (Use a searchable archive such >> as Nabble to hunt for it.) >> >> Error bar plots are easier to do in the ggplot2 package, since there >> is a specific function to generate the error bar 'geometry' >> (geom_errorbar). See http://docs.ggplot2.org/current/ for an expanded >> version of the package help pages, which include the graphs generated >> by the code. I believe there's also a base graphics version that you >> can get from the gplots package, but I don't know a lot about it. >> >> Dennis >> >> On Thu, Jul 4, 2013 at 2:53 PM, Shaun Jackman <sjackman at gmail.com> wrote: >>> Hi, >>> >>> I'd like to draw a lattice barchart of means with error bars to show >>> the standard deviation. I have the barchart, how do I add the error >>> bars? >>> >>> require(datasets) >>> require(lattice) >>> x <- aggregate(weight ~ Diet, ChickWeight, function(x) c(mean=mean(x), >>> sd=sd(x))) >>> barchart(weight[,'mean'] ~ Diet, x) >>> >>> Thanks, >>> Shaun >>> >>> ______________________________________________ >>> 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. >> > > [[alternative HTML version deleted]] > > ______________________________________________ > 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 Alameda, CA, USA