开发者

Produce a chart from histograms

开发者 https://www.devze.com 2023-04-06 07:46 出处:网络
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 histog

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/2开发者_如何学Python0 in the y axis.

How can I do this with R or gnuplot?


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号