I am looking to create what I would call a "simple variation" on the boxplot. What I would like to do is to be able to plot the upper and lower confidence limits as the "box" and the 10th and 90th percentile as the whiskers. What I have done is write the code to create a dataframe, the columns of which are the mean, sd, 10th percentile, 90th percentile, lower confidence limit of the mean, and upper confidence limit of the mean, the rows are the groups. I have exported this to excel and get the graph I want by using the stock graphs in excel that plot open, close, high and low but I would much prefer to do this in R for reason too numerous to enumerate. I have looked high and low and even took a brief look at the bwplot code in the lattice package. Given my experience level it would take quite a while for me to modify the bwplot code to get what I want and create a new graph type, assuming I could get it to work at all. Does anyone know of an easier way to get what I want, with and example? Lattice, grid, base, whatever, I don't especially care what tools I need to use. My only constrante is that I feed it the values required as a dataframe rather than calculate it on the fly so if we change our minds about UCL method or percentiles there is no problem. Thanks in advance, Mike Michael Bock PhD ENVIRON International Corporation 136 Commerical Street, Suite 402 Portland, ME 04101 phone: not active yet fax: not active yet [[alternative HTML version deleted]]
Hi Mike Bock wrote:> I am looking to create what I would call a "simple variation" on the > boxplot. What I would like to do is to be able to plot the upper and > lower confidence limits as the "box" and the 10th and 90th percentile as > the whiskers. What I have done is write the code to create a dataframe, > the columns of which are the mean, sd, 10th percentile, 90th percentile, > lower confidence limit of the mean, and upper confidence limit of the > mean, the rows are the groups. I have exported this to excel and get the > graph I want by using the stock graphs in excel that plot open, close, > high and low but I would much prefer to do this in R for reason too > numerous to enumerate. > > I have looked high and low and even took a brief look at the bwplot code > in the lattice package. Given my experience level it would take quite a > while for me to modify the bwplot code to get what I want and create a > new graph type, assuming I could get it to work at all. Does anyone know > of an easier way to get what I want, with and example? Lattice, grid, > base, whatever, I don't especially care what tools I need to use. My > only constrante is that I feed it the values required as a dataframe > rather than calculate it on the fly so if we change our minds about UCL > method or percentiles there is no problem.Can you put the Excel-generated version up somewhere for us to see the final output you want? Then we could make some specific suggestions. Paul -- Dr Paul Murrell Department of Statistics The University of Auckland Private Bag 92019 Auckland New Zealand 64 9 3737599 x85392 paul at stat.auckland.ac.nz http://www.stat.auckland.ac.nz/~paul/
The first example on this page is pretty close to what I want, but the x-axis would be a category (like location), and the true range anotations are left out. I don't; have a place to post but can e-mail a pdf of my excel version by request. http://www.stockcharts.com/education/IndicatorAnalysis/indic_ATR.html Mike> -----Original Message----- > From: Paul Murrell [mailto:p.murrell at auckland.ac.nz] > Sent: Wednesday, October 19, 2005 3:04 PM > To: Mike Bock > Cc: r-help at stat.math.ethz.ch > Subject: Re: [R] Range plots (lattice or base?) > > > Hi >Delete orginal message for brevity> > Can you put the Excel-generated version up somewhere for us > to see the > final output you want? Then we could make some specific suggestions. > > Paul > -- > Dr Paul Murrell > Department of Statistics > The University of Auckland > Private Bag 92019 > Auckland > New Zealand > 64 9 3737599 x85392 > paul at stat.auckland.ac.nz > http://www.stat.auckland.ac.nz/~paul/ > >
Using base graphics you can use the bxp function. This is what boxplot calls to do the actual plotting. Look at the return value for boxplot in the help for boxplot to see the form of the data that needs to be passed to bxp (also look at the help for bxp) You could write a simple function that takes your data frame and extracts the appropriate numbers into a matrix within a list to pass to bxp. hope this helps, Greg Snow, Ph.D. Statistical Data Center, LDS Hospital Intermountain Health Care greg.snow at ihc.com (801) 408-8111>>> "Mike Bock" <mbock at Environcorp.com> 10/19/05 12:53PM >>>I am looking to create what I would call a "simple variation" on the boxplot. What I would like to do is to be able to plot the upper and lower confidence limits as the "box" and the 10th and 90th percentile as the whiskers. What I have done is write the code to create a dataframe, the columns of which are the mean, sd, 10th percentile, 90th percentile, lower confidence limit of the mean, and upper confidence limit of the mean, the rows are the groups. I have exported this to excel and get the graph I want by using the stock graphs in excel that plot open, close, high and low but I would much prefer to do this in R for reason too numerous to enumerate. I have looked high and low and even took a brief look at the bwplot code in the lattice package. Given my experience level it would take quite a while for me to modify the bwplot code to get what I want and create a new graph type, assuming I could get it to work at all. Does anyone know of an easier way to get what I want, with and example? Lattice, grid, base, whatever, I don't especially care what tools I need to use. My only constrante is that I feed it the values required as a dataframe rather than calculate it on the fly so if we change our minds about UCL method or percentiles there is no problem. Thanks in advance, Mike Michael Bock PhD ENVIRON International Corporation 136 Commerical Street, Suite 402 Portland, ME 04101 phone: not active yet fax: not active yet [[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
On 10/19/05, Mike Bock <mbock at environcorp.com> wrote:> I am looking to create what I would call a "simple variation" on the > boxplot. What I would like to do is to be able to plot the upper and > lower confidence limits as the "box" and the 10th and 90th percentile as > the whiskers. What I have done is write the code to create a dataframe, > the columns of which are the mean, sd, 10th percentile, 90th percentile, > lower confidence limit of the mean, and upper confidence limit of the > mean, the rows are the groups. I have exported this to excel and get the > graph I want by using the stock graphs in excel that plot open, close, > high and low but I would much prefer to do this in R for reason too > numerous to enumerate. > > I have looked high and low and even took a brief look at the bwplot code > in the lattice package. Given my experience level it would take quite a > while for me to modify the bwplot code to get what I want and create a > new graph type, assuming I could get it to work at all. Does anyone know > of an easier way to get what I want, with and example? Lattice, grid, > base, whatever, I don't especially care what tools I need to use. My > only constrante is that I feed it the values required as a dataframe > rather than calculate it on the fly so if we change our minds about UCL > method or percentiles there is no problem.Is your UCL method guaranteed to work separately on groups (e.g. if the s.d. is estimated per group) or does it share information across groups (e.g. some sort of pooled estimate of s.d.)? In the former case, you could try writing a replacement for boxplot.stats and use that in panel.bwplot. Deepayan
I have gotten what I want by following Deepayan's advice. I have written the following replacement for boxplot.stats. When I run bwplot, I get exactly what I want. This function is lacking sufficient error checking but here it is. The bootstrapping makes it a bit slow. What I would like to do is write a new function (ciplot) that stores the original boxplot.stats fucntion, replaces it with my new stats function, calls bwplot, and then return boxplot.stats to its original. boxplot.stats <-function (x,coef = 1.5, do.conf=TRUE, do.out=TRUE) { Mean <- mean(x,na.rm = TRUE) Sd <- sd(x,na.rm = TRUE) lp <- (quantile(x,0.10, na.rm = TRUE)[[1]]) up <- (quantile(x,0.90, na.rm = TRUE) [[1]]) sizen <- sum(!is.na(x)) lci <- 0 uci <- 0 if (sizen > 5) {CI <- try((boot.ci(boot(x, function(x,i) mean(x[i]), R = 5000) ,conf = c(0.95), type = c("norm")))$normal[-1]) lci <- CI[1] uci <- CI[2]} lconf <- 0 uconf <- 0 stats <- c(lp,lci,Mean,uci,up) n<-sizen conf <-c(lconf,uconf) result <- list(stats = stats,n=n,conf=conf,out = NA) return(result) }> -----Original Message----- > From: Deepayan Sarkar [mailto:deepayan.sarkar at gmail.com] > Sent: Wednesday, October 19, 2005 3:34 PM > To: Mike Bock > Cc: r-help at stat.math.ethz.ch > Subject: Re: Range plots (lattice or base?) > > > > > On 10/19/05, Mike Bock <mbock at environcorp.com> wrote: > > I am looking to create what I would call a "simple > variation" on the > > boxplot. What I would like to do is to be able to plot the > upper and > > lower confidence limits as the "box" and the 10th and 90th > percentile > > as the whiskers. What I have done is write the code to create a > > dataframe, the columns of which are the mean, sd, 10th percentile, > > 90th percentile, lower confidence limit of the mean, and upper > > confidence limit of the mean, the rows are the groups. I > have exported > > this to excel and get the graph I want by using the stock graphs in > > excel that plot open, close, high and low but I would much > prefer to > > do this in R for reason too numerous to enumerate. > > > > I have looked high and low and even took a brief look at the bwplot > > code in the lattice package. Given my experience level it > would take > > quite a while for me to modify the bwplot code to get what > I want and > > create a new graph type, assuming I could get it to work at > all. Does > > anyone know of an easier way to get what I want, with and example? > > Lattice, grid, base, whatever, I don't especially care what tools I > > need to use. My only constrante is that I feed it the > values required > > as a dataframe rather than calculate it on the fly so if we > change our > > minds about UCL method or percentiles there is no problem. > > Is your UCL method guaranteed to work separately on groups > (e.g. if the s.d. is estimated per group) or does it share > information across groups (e.g. some sort of pooled estimate > of s.d.)? In the former case, you could try writing a > replacement for boxplot.stats and use that in panel.bwplot. > > Deepayan >
Apparently Analagous Threads
- Hmisc or Lattice plot with error bars, Depth (independent variable) on Y axis
- Cumulative Density Plots (Hmisc/lattice)
- Summary functions to dataframe
- PCA, Source analysis and Unmixing, environmental forensics
- bwplot change whiskers position to percentile 5 and P95