Reputation: 2589
I have two histograms superimposed in an R file. All the parameters are set equal (bin size, x-scale and y-scale). I would like make a chart where the x-axis rapresents the same variable of the histograms, but in the y-axis, the proportion of the y-axis of the two histograms.
Example:
In a generic bin that represents the range [X_0, X_1] I have twenty events for the first histogram and ten events for the second histogram. So the chart must have in that point the value (X_0+X_1)/2 for the x-axis and 10/20 in the y axis.
How can I do this with R or gnuplot?
Upvotes: 0
Views: 196
Reputation: 3127
The problem could be a 0 in the denominator
> many <- rnorm(1000)
> few <- rnorm(100)
> mh <- hist(many, plot=FALSE)
> fh <- hist(few, breaks=mh$breaks, plot=FALSE)
> ph <- fh
> ph$density <- fh$counts/(mh$counts+0.001) #you have to deal with a 0 denominator
> plot(ph,freq=FALSE)
This is for R. I don't know "gnu" R.
Upvotes: 1