[R] Histogram for each ID value

Sarah Goslee sarah.goslee at gmail.com
Mon Oct 17 14:14:25 CEST 2011


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.5

Using 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



More information about the R-help mailing list