I have a dataframe in the general format: chr1 0.5 chr1 0 chr1 0.75 chr2 0 chr2 0 chr3 1 chr3 1 chr3 0.5 chr7 0.75 chr9 1 chr9 1 chr22 0.5 chr22 0.5 where the first column is the chromosome location and the second column is some value. What I'd like to do is have a histogram created for each chr location (i.e. a separate histogram for chr1, chr2, chr3, chr7, chr9, and chr22). I am just having a hard time getting everything to work out and am hoping for some suggestions. -- View this message in context: http://r.789695.n4.nabble.com/Histogram-for-each-ID-value-tp3911791p3911791.html Sent from the R help mailing list archive at Nabble.com.
Hi, On Mon, Oct 17, 2011 at 8:07 AM, a217 <ajn21 at case.edu> wrote:> I have a dataframe in the general format: > > chr1 0.5 > chr1 0 > chr1 0.75 > chr2 0 > chr2 0 > chr3 1 > chr3 1 > chr3 0.5 > chr7 0.75 > chr9 1 > chr9 1 > chr22 0.5 > chr22 0.5Using dput to give us some reproducible data would be even better.> where the first column is the chromosome location and the second column is > some value. What I'd like to do is have a histogram created for each chr > location (i.e. a separate histogram for chr1, chr2, chr3, chr7, chr9, and > chr22). I am just having a hard time getting everything to work out and am > hoping for some suggestions.And telling us what you've tried would also help. par(mfrow=c(2,3)) hist(mydata[mydata[,1] == "chr1", 2]) hist(mydata[mydata[,1] == "chr2", 2]) hist(mydata[mydata[,1] == "chr3", 2]) hist(mydata[mydata[,1] == "chr7", 2]) hist(mydata[mydata[,1] == "chr9", 2]) hist(mydata[mydata[,1] == "chr22", 2]) So obviously that is completely untested because I don't have your sample data, but might give you the idea. Sarah -- Sarah Goslee http://www.functionaldiversity.org
> where the first column is the chromosome location and the second column is > some value. What I'd like to do is have a histogram created for each chr > location (i.e. a separate histogram for chr1, chr2, chr3, chr7, chr9, and > chr22). I am just having a hard time getting everything to work out and am > hoping for some suggestions.ggplot and looping combined with traditional graphics have already been mentioned, so I'll add the lattice solution for completeness: histogram(~foo | choromosome, dat) This assumes that your dataframe is called "dat" and contains two columns called "foo" (your numeric value) and "chomosome" (your chromosome identifier). cu Philipp