Hello all: I've been beating my head on this for over a day and I have done a lot of Google'ing with no luck. I have generated a 'time-series' of boxplots (227), covering more than a 30-day period at 6-hour intervals, which summarize an ensemble forecast. What I want to do is over-plot the observed values over a portion of the forecast period to serve as a basis of comparison; so, there would be a boxplot and a single point value plotted at each 6-hour interval. The boxplots are generated: zz<-boxplot(ens$value ~ ens$valid_time,xlab="Date/Time (UTC)",ylab="Flow(cfs)",boxfill="cyan") which works fine, but the observed points will not display using: points(zz, obs$value,lty=3,lwd=1,col="red",pch=19) I've tried many variations of the latter, where either nothing happens and no error is returned or I have also gotten that x and y have different lengths. I suspect I am using the wrong 'x' type. I have observation values beginning with the first in the series of boxplots, which then end, with the most recent ensemble forecast. So, I always expect the number of observed values to be less than the number of boxplots. I have done this previously, years ago, but can not find my notes and can not reconstruct what I did. Help is appreciated. Regards, Tom [[alternative HTML version deleted]]
boxplot() turns the x variable into a factor, if it isn't already, so the x axis is calibrated as seq_len(nvalues). Whatever you're trying to do with using your boxplot object as the x variable in points won't work: zz is a list of length 6. There's an example in ?boxplot of adding points to a boxplot. Without a reproducible example, it's impossible to give you working code, but here's another example besides the one in ?boxplot: zz <- boxplot(runif(100) ~ sample(c(4, 9, 15), size=100, replace=TRUE)) points(seq_len(3), c(.8, .82, .9), col="red", pch=2) Notice that even though the boxplot labels are 4, 9, 15 the plot coordinates are 1, 2, 3. Sarah On Thu, Jun 2, 2016 at 11:36 AM, Thomas Adams <tea3rd at gmail.com> wrote:> Hello all: > > I've been beating my head on this for over a day and I have done a lot of > Google'ing with no luck. > > I have generated a 'time-series' of boxplots (227), covering more than a > 30-day period at 6-hour intervals, which summarize an ensemble forecast. > What I want to do is over-plot the observed values over a portion of the > forecast period to serve as a basis of comparison; so, there would be a > boxplot and a single point value plotted at each 6-hour interval. > > The boxplots are generated: > > zz<-boxplot(ens$value ~ ens$valid_time,xlab="Date/Time > (UTC)",ylab="Flow(cfs)",boxfill="cyan") > > which works fine, but the observed points will not display using: > > points(zz, obs$value,lty=3,lwd=1,col="red",pch=19) > > I've tried many variations of the latter, where either nothing happens and > no error is returned or I have also gotten that x and y have different > lengths. I suspect I am using the wrong 'x' type. I have observation values > beginning with the first in the series of boxplots, which then end, with > the most recent ensemble forecast. So, I always expect the number of > observed values to be less than the number of boxplots. I have done this > previously, years ago, but can not find my notes and can not reconstruct > what I did. > > Help is appreciated. > > Regards, > Tom
Does using zz<-bxp(boxplot(data,plot=FALSE)) do what you want? E.g., d <- transform(data.frame(t=1:15), x = sin(t)+log2(t), group paste("Group", t%/%4)) groupedX <- with(d, split(x, group)) zz <- bxp(boxplot(groupedX, plot=FALSE)) # bxp returns the x positions of the boxes points(col="blue", pch=15, zz, vapply(splitX, FUN=mean, FUN.VALUE=0)) Bill Dunlap TIBCO Software wdunlap tibco.com On Thu, Jun 2, 2016 at 8:36 AM, Thomas Adams <tea3rd at gmail.com> wrote:> Hello all: > > I've been beating my head on this for over a day and I have done a lot of > Google'ing with no luck. > > I have generated a 'time-series' of boxplots (227), covering more than a > 30-day period at 6-hour intervals, which summarize an ensemble forecast. > What I want to do is over-plot the observed values over a portion of the > forecast period to serve as a basis of comparison; so, there would be a > boxplot and a single point value plotted at each 6-hour interval. > > The boxplots are generated: > > zz<-boxplot(ens$value ~ ens$valid_time,xlab="Date/Time > (UTC)",ylab="Flow(cfs)",boxfill="cyan") > > which works fine, but the observed points will not display using: > > points(zz, obs$value,lty=3,lwd=1,col="red",pch=19) > > I've tried many variations of the latter, where either nothing happens and > no error is returned or I have also gotten that x and y have different > lengths. I suspect I am using the wrong 'x' type. I have observation values > beginning with the first in the series of boxplots, which then end, with > the most recent ensemble forecast. So, I always expect the number of > observed values to be less than the number of boxplots. I have done this > previously, years ago, but can not find my notes and can not reconstruct > what I did. > > Help is appreciated. > > Regards, > Tom > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see > 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]]
RICHARD M. HEIBERGER
2016-Jun-02 15:52 UTC
[R] Struggling trying to plot points on boxplot
something like this points(zz[1:length(obs$value)], obs$value,lty=3,lwd=1,col="red",pch=19) Sent from my iPhone> On Jun 2, 2016, at 11:36, Thomas Adams <tea3rd at gmail.com> wrote: > > points(zz, obs$value,lty=3,lwd=1,col="red",pch=19)
Bill, Thank you!! With some tweaking, this approach was exactly what I needed. Previously, I had been using bxp and had my code for it, but my data was structured completely differently from what I have now. I figured something like groupedX <- with(d, split(x, group)) existed, but how to find it?? This was the key for me and it's so powerful! Thanks to all for the suggestions! Tom On Thu, Jun 2, 2016 at 10:52 AM, William Dunlap <wdunlap at tibco.com> wrote:> Does using zz<-bxp(boxplot(data,plot=FALSE)) do what you want? E.g., > > d <- transform(data.frame(t=1:15), x = sin(t)+log2(t), group > paste("Group", t%/%4)) > groupedX <- with(d, split(x, group)) > zz <- bxp(boxplot(groupedX, plot=FALSE)) # bxp returns the x positions of > the boxes > points(col="blue", pch=15, zz, vapply(splitX, FUN=mean, FUN.VALUE=0)) > > > Bill Dunlap > TIBCO Software > wdunlap tibco.com > > On Thu, Jun 2, 2016 at 8:36 AM, Thomas Adams <tea3rd at gmail.com> wrote: > >> Hello all: >> >> I've been beating my head on this for over a day and I have done a lot of >> Google'ing with no luck. >> >> I have generated a 'time-series' of boxplots (227), covering more than a >> 30-day period at 6-hour intervals, which summarize an ensemble forecast. >> What I want to do is over-plot the observed values over a portion of the >> forecast period to serve as a basis of comparison; so, there would be a >> boxplot and a single point value plotted at each 6-hour interval. >> >> The boxplots are generated: >> >> zz<-boxplot(ens$value ~ ens$valid_time,xlab="Date/Time >> (UTC)",ylab="Flow(cfs)",boxfill="cyan") >> >> which works fine, but the observed points will not display using: >> >> points(zz, obs$value,lty=3,lwd=1,col="red",pch=19) >> >> I've tried many variations of the latter, where either nothing happens and >> no error is returned or I have also gotten that x and y have different >> lengths. I suspect I am using the wrong 'x' type. I have observation >> values >> beginning with the first in the series of boxplots, which then end, with >> the most recent ensemble forecast. So, I always expect the number of >> observed values to be less than the number of boxplots. I have done this >> previously, years ago, but can not find my notes and can not reconstruct >> what I did. >> >> Help is appreciated. >> >> Regards, >> Tom >> >> [[alternative HTML version deleted]] >> >> ______________________________________________ >> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see >> 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. >> > >-- Thomas E Adams, III 2330 Jack Warner PKWY, #334 Tuscaloosa, AL 35401 1 (513) 739-9512 (cell) [[alternative HTML version deleted]]