Hello, I have a data-frame in which one-column is a factor:> str(data);`data.frame': 194 obs. of 8 variables: $ Type : Factor w/ 3 levels "Nuclear-Rec..",..: 1 2 2 2 2 2 2 2 2 2 ... $ Locus : num 0.000571 0.004000 0.001429 0.004857 0.007429 ... And I'd like to make a boxplot of the data$Locus values, where each level of the factor gets its own box-and-whiskers plot. I'm weak in R, but I thought there might be some shortcut to automating this instead of just creating a new data-structure with all the separate values? Any suggestions much appreciated! Paul
On Tue, 24 Aug 2004, Paul Boutros wrote:> Hello, > > I have a data-frame in which one-column is a factor: > > > str(data); > `data.frame': 194 obs. of 8 variables: > $ Type : Factor w/ 3 levels "Nuclear-Rec..",..: 1 2 2 2 2 2 2 2 2 2 > ... > $ Locus : num 0.000571 0.004000 0.001429 0.004857 0.007429 ... > > And I'd like to make a boxplot of the data$Locus values, where each level of > the factor gets its own box-and-whiskers plot. I'm weak in R, but I thought > there might be some shortcut to automating this instead of just creating a > new data-structure with all the separate values?There are two. The simpler is boxplot(Locus ~ Type, data=data) and you can also use with(data, boxplot(split(Locus, Type))) (split() does automate the construction of a suitable data structure.) -- Brian D. Ripley, ripley at stats.ox.ac.uk Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UK Fax: +44 1865 272595
On 24 Aug 2004 at 2:12, Paul Boutros wrote:> Hello, > > I have a data-frame in which one-column is a factor: > > > str(data); > `data.frame': 194 obs. of 8 variables: > $ Type : Factor w/ 3 levels "Nuclear-Rec..",..: 1 2 2 2 2 2 2 > 2 2 2 > ... > $ Locus : num 0.000571 0.004000 0.001429 0.004857 0.007429 > ... > > And I'd like to make a boxplot of the data$Locus values, where each > level of the factor gets its own box-and-whiskers plot. I'm weak in > R, but I thought there might be some shortcut to automating this > instead of just creating a new data-structure with all the separate > values?Hi You have at least 2 options: boxplot(data$Locus~data$Type) boxplot(split(data$Locus,data$Type)) See ?boxplot for further options. Cheers Petr> > Any suggestions much appreciated! > Paul > > ______________________________________________ > 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.htmlPetr Pikal petr.pikal at precheza.cz