Liaw, Andy
2006-Jun-29 13:53 UTC
[R] boxplot of subset of factors, in an order of my choice [B roadcast]
1. Use something like with(testResults, boxplot(score[test == "rTest"])) 2. testResults$test <- factor(as.character(testResults$test), levels=c("rTest", "gTest", "fTest")) [Substitute any order you like in the last line.] Andy From: Sumitrajit Dhar> > Hi Folks, > > Say I am working with the following data set: > testResults: > stud test score > 1 1 fTest 43 > 2 1 rTest 39 > 3 1 gTest 43 > 4 2 fTest 23 > 5 2 rTest 33 > 6 2 gTest 41 > . > . > . > N n gTest 47 > > I would like to generate a boxplot of rTest only. Here is > what I have done after reading the data in and attaching the object. > > test <- factor(test) > > Now when I try > > boxplot(score ~ test, subset = test=="rTest") > > 1. I still see the tick marks for the other factors on the > x-axis although no data are plotted. Can I eliminate these > extra markers (and the space for these faactors) and just > have the tick marker and the label for "rTest"? > > 2. I would also like to be able to rearrange the tests as > they appear from left to right on the graph. I read the hints > and help about reorder.factor but it does not seem to be the > solution in this case. > I am wanting to re-order the boxes without any logic > (statistical anyways). Can this be done? > > Thanks in advance, > Sumit > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! > http://www.R-project.org/posting-guide.html > >