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!
I'm not going to use your data because it's not an easily paste-able but how
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...