tags:

views:

96

answers:

1

I have a bunch of histograms to plot on data that is still coming. As the sample sizes vary, in order to compare them I need to plot the histograms with percentages not counts.

qplot (field, data=mydata, geom="histogram", binwidth=10)

the above qplot displays the counts. The density option is not applicable as it divides the counts within a bin to the bin's width, whereas I need to divide on the total number of samples.

I can precalculate a column containing the percentage, but it's cumbersome (I have many data sets).

Is there a better way to tell qplot to directly plot the histogram with percentages (ideally, also displayed as percentages (as 69%) and not as 0.69)?

Thanks!

+4  A: 

hi

try this:

ggplot(movies,aes(x=rating))+stat_bin(aes(n=nrow(movies), y=..count../n))+
scale_y_continuous(formatter = "percent")
kohske
excellent, it works as I hoped. thanks!
wishihadabettername
And the implicit advice of "don't use qplot unless you're a ggplot expert" is also excellent!
Harlan