[R] Struggling trying to plot points on boxplot

Sarah Goslee sarah.goslee at gmail.com
Thu Jun 2 17:48:52 CEST 2016


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



More information about the R-help mailing list