Hi, Is it possible to produce box-and-whisker plots given that I have the median, interquartile and 5/95th centile values, but not the data from which they come? It seems that it ought to be possible to coerce bxp to do what I want, but I can't quite see how. Thanks, Matthew -- Matthew Vernon, Research Fellow Ecology and Epidemiology Group, University of Warwick http://blogs.warwick.ac.uk/mcvernon
It would seem that simply running the boxplot on the relevent numbers will give you a boxplot (Assuming you are not beyond the fences). set.seed(10) x = rnorm(100) boxplot(x) boxplot(summary(x)[-4]) # If beyond the fences - it won't work set.seed(10) x = c(rnorm(100), 10) boxplot(x) boxplot(summary(x)[-4]) Cheers, Tal ----------------Contact Details:------------------------------------------------------- Contact me: Tal.Galili@gmail.com | 972-52-7275845 Read me: www.talgalili.com (Hebrew) | www.biostatistics.co.il (Hebrew) | www.r-statistics.com (English) ---------------------------------------------------------------------------------------------- On Fri, Dec 17, 2010 at 3:05 PM, Matthew Vernon <M.C.Vernon@warwick.ac.uk>wrote:> Hi, > > Is it possible to produce box-and-whisker plots given that I have the > median, interquartile and 5/95th centile values, but not the data from > which they come? It seems that it ought to be possible to coerce bxp > to do what I want, but I can't quite see how. > > Thanks, > > Matthew > -- > Matthew Vernon, Research Fellow > Ecology and Epidemiology Group, > University of Warwick > http://blogs.warwick.ac.uk/mcvernon > > ______________________________________________ > R-help@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]]
Can you show us what you tried and how it differs from what you expect? The boxplot function calculates the summaries, then calls the bxp function to do the plotting. So you should be able to create a list similar to what boxplot does that you can then pass directly to bxp. If you have tried this and it is not working, then it is difficult for us to guess where the problem is without some idea of the code you are using and the error you are getting. -- Gregory (Greg) L. Snow Ph.D. Statistical Data Center Intermountain Healthcare greg.snow at imail.org 801.408.8111> -----Original Message----- > From: r-help-bounces at r-project.org [mailto:r-help-bounces at r- > project.org] On Behalf Of Matthew Vernon > Sent: Friday, December 17, 2010 6:06 AM > To: r-help at stat.math.ethz.ch > Subject: [R] box-and-whisker plots based on summary not data > > Hi, > > Is it possible to produce box-and-whisker plots given that I have the > median, interquartile and 5/95th centile values, but not the data from > which they come? It seems that it ought to be possible to coerce bxp > to do what I want, but I can't quite see how. > > Thanks, > > Matthew > -- > Matthew Vernon, Research Fellow > Ecology and Epidemiology Group, > University of Warwick > http://blogs.warwick.ac.uk/mcvernon > > ______________________________________________ > 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.
Matthew Vernon <M.C.Vernon at warwick.ac.uk> writes:> Is it possible to produce box-and-whisker plots given that I have the > median, interquartile and 5/95th centile values, but not the data from > which they come?The answer, which came from Steve Ellison (thanks!) is to note that "stats" is the only bit of the "z" argument to bxp that has to be present, so given a data file with columns year,mean,median,centiles, something like this works: # transform data so the rows are the various centiles in order # there's probably a more elegant approach! bsr <- matrix(allobs[,c(4,5,3,6,7)],nrow=5,byrow=TRUE) # column 1 is the year, which is our factor bsbox <- list( stats=bsr,names=allobs$V1) bxp(bsbox,xlab="Year",ylab="Number of cattle per batch") I thought I'd follow-up so the answer to my question will be in the archives. Thanks, Matthew -- Matthew Vernon, Research Fellow Ecology and Epidemiology Group, University of Warwick http://blogs.warwick.ac.uk/mcvernon