HI everyone, I'm plotting a histogram in R and within that histogram i need to demonstrate the percentage of another variable (Percentage of MutStatus) within the bins plotted inthe histogram....I don't know how to do that! Data:Validation_Status Mutation_Status TvarRatio Wildtype None 0.08 Wildtype None 0.08 Wildtype None 0.08 Wildtype None 0.08 Wildtype None 0.080139373 Wildtype None 0.080152672 Wildtype None 0.080213904 Wildtype None 0.080357143 Wildtype None 0.080357143 Wildtype None 0.080357143 Wildtype None 0.08045977 Wildtype None 0.1 Wildtype LOH 0.1 Wildtype None 0.1 Wildtype None 0.1 Wildtype None 0.1 Wildtype None 0.1 Wildtype None 0.1 Wildtype Somtatic 0.1 Wildtype None 0.100558659 Wildtype None 0.100591716 Wildtype None 0.101010101 Wildtype None 0.101123596 Wildtype Gline 0.101333333 Wildtype None 0.101369863 Wildtype None 0.101449275 Wildtype None 0.101522843 Wildtype None 0.101604278 Wildtype None 0.102040816 Wildtype Gline 0.102040816 Wildtype None 0.102362205 Wildtype None 0.102459016 Wildtype None 0.102564103 Wildtype None 0.102702703 Wildtype None 0.102739726 Wildtype None 0.102803738 Valid Somatic 0.102941176 Wildtype None 0.102941176 -- View this message in context: http://r.789695.n4.nabble.com/Histograms-in-R-tp3733644p3733644.html Sent from the R help mailing list archive at Nabble.com.
Perhaps you could shade the bars as appropriate? I'm not going to use your data because it's not an easily paste-able but how about this: x = rnorm(100) y = sample(c("A","B"),100,replace=T,prob=c(0.7,0.3)) d = data.frame(level = x, status = y) n = 10 # Number of bins breaks = quantile(d$level, (0:n)/n) #breaks = with(d,hist(level,breaks=n,plot=F)$breaks) breaksAssign = findInterval(d$level,breaks) percentB = unique(ave(d$status=="B",breaksAssign)[order(breaksAssign)]) percentB = gray(percentB/max(percentB)) # Many other color functions available as well. with(d, hist(level, breaks = breaks, col = percentB)) If you want to use hist()'s smart choice of bins (which I'd recommend), you can call this hist command once with plot=F and get the breaks from there. I.e., breaks = with(d,hist(level,breaks=n,plot=F)$breaks) There's probably a smarter way to do all this, but this does seem to work... Hope this helps, Michael Weylandt On Wed, Aug 10, 2011 at 1:16 PM, lt2 <lt2@bcm.edu> wrote:> HI everyone, > I'm plotting a histogram in R and within that histogram i need to > demonstrate the percentage of another variable (Percentage of MutStatus) > within the bins plotted inthe histogram....I don't know how to do that! > > Data:Validation_Status Mutation_Status TvarRatio > Wildtype None 0.08 > Wildtype None 0.08 > Wildtype None 0.08 > Wildtype None 0.08 > Wildtype None 0.080139373 > Wildtype None 0.080152672 > Wildtype None 0.080213904 > Wildtype None 0.080357143 > Wildtype None 0.080357143 > Wildtype None 0.080357143 > Wildtype None 0.08045977 > Wildtype None 0.1 > Wildtype LOH 0.1 > Wildtype None 0.1 > Wildtype None 0.1 > Wildtype None 0.1 > Wildtype None 0.1 > Wildtype None 0.1 > Wildtype Somtatic 0.1 > Wildtype None 0.100558659 > Wildtype None 0.100591716 > Wildtype None 0.101010101 > Wildtype None 0.101123596 > Wildtype Gline 0.101333333 > Wildtype None 0.101369863 > Wildtype None 0.101449275 > Wildtype None 0.101522843 > Wildtype None 0.101604278 > Wildtype None 0.102040816 > Wildtype Gline 0.102040816 > Wildtype None 0.102362205 > Wildtype None 0.102459016 > Wildtype None 0.102564103 > Wildtype None 0.102702703 > Wildtype None 0.102739726 > Wildtype None 0.102803738 > Valid Somatic 0.102941176 > Wildtype None 0.102941176 > > -- > View this message in context: > http://r.789695.n4.nabble.com/Histograms-in-R-tp3733644p3733644.html > Sent from the R help mailing list archive at Nabble.com. > > ______________________________________________ > 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. >[[alternative HTML version deleted]]
Assuming your data is in a data.frame called df, try this: attach(df) TR.groups <- cut(TvarRatio, seq(0.07, 0.11, 0.01)) m <- table(Mutation_Status, TR.groups) mut.no <- dim(m)[1] barplot(m, col=seq(mut.no), xlab="TvarRatio", ylab="Frequency") legend("topleft", dimnames(m)[[1]], fill=seq(mut.no), title="Mutation_Status") Jean `·.,, ><(((º> `·.,, ><(((º> `·.,, ><(((º> Jean V. Adams Statistician U.S. Geological Survey Great Lakes Science Center 223 East Steinfest Road Antigo, WI 54409 USA r-help-bounces@r-project.org wrote on 08/10/2011 12:16:51 PM:> [image removed] > > [R] Histograms in R > > lt2 > > to: > > r-help > > 08/10/2011 12:18 PM > > Sent by: > > r-help-bounces@r-project.org > > HI everyone, > I'm plotting a histogram in R and within that histogram i need to > demonstrate the percentage of another variable (Percentage of MutStatus) > within the bins plotted inthe histogram....I don't know how to do that! > > Data:Validation_Status Mutation_Status TvarRatio > Wildtype None 0.08 > Wildtype None 0.08 > Wildtype None 0.08 > Wildtype None 0.08 > Wildtype None 0.080139373 > Wildtype None 0.080152672 > Wildtype None 0.080213904 > Wildtype None 0.080357143 > Wildtype None 0.080357143 > Wildtype None 0.080357143 > Wildtype None 0.08045977 > Wildtype None 0.1 > Wildtype LOH 0.1 > Wildtype None 0.1 > Wildtype None 0.1 > Wildtype None 0.1 > Wildtype None 0.1 > Wildtype None 0.1 > Wildtype Somtatic 0.1 > Wildtype None 0.100558659 > Wildtype None 0.100591716 > Wildtype None 0.101010101 > Wildtype None 0.101123596 > Wildtype Gline 0.101333333 > Wildtype None 0.101369863 > Wildtype None 0.101449275 > Wildtype None 0.101522843 > Wildtype None 0.101604278 > Wildtype None 0.102040816 > Wildtype Gline 0.102040816 > Wildtype None 0.102362205 > Wildtype None 0.102459016 > Wildtype None 0.102564103 > Wildtype None 0.102702703 > Wildtype None 0.102739726 > Wildtype None 0.102803738 > Valid Somatic 0.102941176 > Wildtype None 0.102941176 > > -- > View this message in context: http://r.789695.n4.nabble.com/ > Histograms-in-R-tp3733644p3733644.html > Sent from the R help mailing list archive at Nabble.com. > > ______________________________________________ > R-help@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guidehttp://www.R-project.org/posting-guide.html> and provide commented, minimal, self-contained, reproducible code.[[alternative HTML version deleted]]