Hi folks, I have a vaiable Y and an associated factor Z at several (13) levels. boxplot(Y~Z) produces a nice array of boxplots, one for each level of Z, and each duly labaelled with its level of Z. I would like to superpose on each boxplot the actual data points which it represents, i.e. do something conceptually (though not in real R) expressed as points(Y~Z) or points(Z,Y) It can be done "with bare hands" along the lines of B<-boxplot(Y~Z) x<-bxp(B) X<-rep(x,ngroups) points(X,Y) where ngroups is the number of data at each level of Z, *provided* the data are pre-sorted by level of Z and in the same order as these levels occurr in the boxplot. But of course they're not! OK, I could do this by hand as well, but now it's getting a bit tedious, and I'm wondering if there's a better way. Thanks for any suggestions, Ted. -------------------------------------------------------------------- E-Mail: (Ted Harding) <Ted.Harding at nessie.mcc.ac.uk> Fax-to-email: +44 (0)870 167 1972 Date: 04-May-04 Time: 15:48:23 ------------------------------ XFMail ------------------------------
Try: y = rnorm(50) z = factor(rep(1:5, each=10)) boxplot(y~z, horizontal=TRUE) stripchart(y~z, add=TRUE) HTH, Andy> -----Original Message----- > From: r-help-bounces at stat.math.ethz.ch > [mailto:r-help-bounces at stat.math.ethz.ch] On Behalf Of > Ted.Harding at nessie.mcc.ac.uk > Sent: Tuesday, May 04, 2004 10:48 AM > To: r-help at stat.math.ethz.ch > Subject: [R] Superposing data on boxplot > > > Hi folks, > > I have a vaiable Y and an associated factor Z at several (13) > levels. > > boxplot(Y~Z) > > produces a nice array of boxplots, one for each level of Z, > and each duly labaelled with its level of Z. > > I would like to superpose on each boxplot the actual data > points which it represents, i.e. do something conceptually > (though not in real R) expressed as > > points(Y~Z) > > or > > points(Z,Y) > > It can be done "with bare hands" along the lines of > > B<-boxplot(Y~Z) > x<-bxp(B) > X<-rep(x,ngroups) > points(X,Y) > > where ngroups is the number of data at each level of Z, > *provided* the data are pre-sorted by level of Z and in the > same order as these levels occurr in the boxplot. But of course > they're not! > > OK, I could do this by hand as well, but now it's getting a bit > tedious, and I'm wondering if there's a better way. > > Thanks for any suggestions, > Ted. > > > -------------------------------------------------------------------- > E-Mail: (Ted Harding) <Ted.Harding at nessie.mcc.ac.uk> > Fax-to-email: +44 (0)870 167 1972 > Date: 04-May-04 Time: 15:48:23 > ------------------------------ XFMail ------------------------------ > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://www.stat.math.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! > http://www.R-project.org/posting-guide.html > >
What about: y<-rnorm(100);z<-sample(1:7,100,T);boxplot(y~z);points(y~z) Peter Wolf Ted Harding wrote:>Hi folks, > >I have a vaiable Y and an associated factor Z at several (13) >levels. > > boxplot(Y~Z) > >produces a nice array of boxplots, one for each level of Z, >and each duly labaelled with its level of Z. > >I would like to superpose on each boxplot the actual data >points which it represents, i.e. do something conceptually >(though not in real R) expressed as > > points(Y~Z) > >or > > points(Z,Y) > >It can be done "with bare hands" along the lines of > > B<-boxplot(Y~Z) > x<-bxp(B) > X<-rep(x,ngroups) > points(X,Y) > >where ngroups is the number of data at each level of Z, >*provided* the data are pre-sorted by level of Z and in the >same order as these levels occurr in the boxplot. But of course >they're not! > >OK, I could do this by hand as well, but now it's getting a bit >tedious, and I'm wondering if there's a better way. > >Thanks for any suggestions, >Ted. > > >-------------------------------------------------------------------- >E-Mail: (Ted Harding) <Ted.Harding at nessie.mcc.ac.uk> >Fax-to-email: +44 (0)870 167 1972 >Date: 04-May-04 Time: 15:48:23 >------------------------------ XFMail ------------------------------ > >______________________________________________ >R-help at stat.math.ethz.ch mailing list >https://www.stat.math.ethz.ch/mailman/listinfo/r-help >PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html > >