Re: [R] boxplot with cut

2012-07-10 Thread Rui Barradas

Hello,

Maybe this iss what you're looking for. GD is your data.frame.



multi.boxplot - function(x, by, ...){
x - as.data.frame(x)
sp - split(x, by)
len - length(sp) - 1
n - ncol(x)
n1 - n + 1
boxplot(x[[ 1 ]] ~ by, at = 0:len*n1 + 1,
xlim = c(0, (len + 1)*n1), ylim = range(unlist(x)), xaxt = n, 
...)
for(i in seq_len(n)[-1])
boxplot(x[[i]] ~ by, at = 0:len*n1 + i, xaxt = n, add = TRUE, 
...)
axis(1, at = 0:len*n1 + n1/2, labels = names(sp), tick = TRUE)
}

cols - grep(ReadCount, names(GD))
multi.boxplot(GD[, cols], cut(GD$GeneDensity, breaks=10))


If this is it and you don't like those x-axis tick lables, use 
as.integer(cut(...etc...)).


Hope this helps,

Rui Barradas

Em 09-07-2012 20:51, Vining, Kelly escreveu:

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 1  107.82 1.2431.047   1.496
2   1 10001 2  202.50 0.8350.869   0.456
3   1 20001 3  158.80 1.8131.529   1.131
4   1 30001 4  100.53 1.7311.752   1.610
5   1 40001 5  100.53 3.0562.931   3.631
6   1 50001 6  100.53 1.9602.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.
__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.



__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] boxplot with cut

2012-07-09 Thread Vining, Kelly
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 1  107.82 1.2431.047   1.496
2   1 10001 2  202.50 0.8350.869   0.456
3   1 20001 3  158.80 1.8131.529   1.131
4   1 30001 4  100.53 1.7311.752   1.610
5   1 40001 5  100.53 3.0562.931   3.631
6   1 50001 6  100.53 1.9602.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.
__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.