[R] boxplot with "cut"
Vining, Kelly
Kelly.Vining at oregonstate.edu
Mon Jul 9 21:51:58 CEST 2012
Dear UseRs,
I'm making box plots from a data set that looks like this:
Chr Start End GeneDensity ReadCount_Explant ReadCount_Callus ReadCount_Regen
1 1 1 10000 107.82 1.243 1.047 1.496
2 1 10001 20000 202.50 0.835 0.869 0.456
3 1 20001 30000 158.80 1.813 1.529 1.131
4 1 30001 40000 100.53 1.731 1.752 1.610
5 1 40001 50000 100.53 3.056 2.931 3.631
6 1 50001 60000 100.53 1.960 2.013 2.459
I'm breaking the "GeneDensity" column into deciles, then making a box plot of the relationship between the GeneDensity parameter and each of the three "ReadCount" columns. Here's an example of one of my boxplot commands:
boxplot(GeneDensity$ReadCount_Explant ~ cut(GeneDensitySorted$GeneDensity, breaks=10), ylim=c(0,40), ylab="RPKM", xlab="GENE DENSITY (LOW -> HIGH)", main="INTERNODE EXPLANT")
Right now, I'm making three separate graphs: one for each of the three "ReadCount" columns. I'd like to put all three sets on one graph, so that each decile is represented by three boxes, one for each ReadCount category, but don't know how to make that work. I tried this:
boxplot(GeneDensitySorted$ReadCount_Explant ~ cut(GeneDensitySorted$GeneDensity, breaks=10), GeneDensitySorted$ReadCount_Callus ~ cut(GeneDensitySorted$GeneDensity, breaks=10), GeneDensitySorted$ReadCount_Regen ~ cut(GeneDensitySorted$GeneDensity, breaks=10), ylim=c(0,40), ylab="RPKM", xlab="GENE DENSITY (LOW -> HIGH)")
Not surprisingly, I got this error:
Error in as.data.frame.default(data) :
cannot coerce class '"formula"' into a data.frame
Does anyone know how to accomplish this box plot?
Any help is much appreciated.
--Kelly V.
More information about the R-help
mailing list