[R] select data for boxplot

Peter Ehlers ehlers at ucalgary.ca
Mon Jan 10 18:41:42 CET 2011


On 2011-01-10 07:38, David A. wrote:
>
> Dear list, havig the following matrix
>
> "Value"  "Class"
> 13.00    1
> 12.80    1
> 11.78    1
> 11.70    2
> 11.61    2
> 11.95    2
> 11.55    2
> 12.40    3
> 11.40    1
> 12.27    1
> 12.49    3
> 11.39    4
> 11.80    4
> 12.39    3
> 12.72    3
> 12.18    3
> 11.64    3
> 11.50    4
> 12.81    4
> 11.31    4
> 11.95    2
> 12.65    2
> 11.66    2
> 12.19    3
> 12.84    1
> 11.90    1
> 11.11    4
> 12.75    4
>
> how can I specify that I want a boxplot of values for class 1 in one box and class 2 and 4 together in another box, without showing class 3?
>

I hope that's a data frame, not a matrix.
Let's call it dat.

Form an appropriate factor variable, e.g.

  dat$grp <- factor(dat$Class)
  levels(dat$grp) <- list(a=1, b=c(2,4))
  boxplot(Value~grp, data=dat)

I trust that your real data is more extensive; boxplots
for groups of size 7 are not greatly informative.
Consider stripchart().

Peter Ehlers

> Thanks in advance
>
> D.



More information about the R-help mailing list