overlaying exponential distribution onto histogram

天涯浪子 提交于 2019-12-02 04:17:25

问题


How can i overlay an exponential distribution on a histogram of time intervals? The histogram looks like an exponential distribution. When I try to create the histogram in a similar way to superimposing a normal curve I get the following:

Error in xy.coords(x, y) : 'x' and 'y' lengths differ

I can create the histogram on its own which has an x axis from 0 to 70. And I can create an exponential distribution curve on its own but its x axis goes from 0 to 1.

I am using hist(t) where t is a list of times in seconds for the histogram and curve(dexp(x,rate=0.09)) for the exponential distribution.


回答1:


Make sure to use prob = TRUE in hist, and add = TRUE in curve

z <- rexp(300,rate = 0.09)
hist(z, prob = TRUE)
curve(dexp(x, rate = 0.09), col = 2, lty = 2, lwd = 2, add = TRUE)



来源:https://stackoverflow.com/questions/22704047/overlaying-exponential-distribution-onto-histogram

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!