Plot histogram and density function curve on one chart

有些话、适合烂在心里 提交于 2019-12-22 10:34:04

问题


I have a density function f, and I do MCMC sampling for it. To evaluate the goodness of the sampling, I need to plot the hist and curve within the same chart. The problem of

hist(samples);
curve(dfun,add=TRUE);

is that they are on the different scale: the frequency of a certain bin is usually hundreds, while the maximum of a density function is about 1 or so. What I want to do is to configure two plots at the same height, with one y-axis on the left and the other on the right. Can anyone help? Thank you.


回答1:


Use the prob=TRUE argument to hist:

hist(samples, prob=TRUE)
curve(dfun,add=TRUE)

Also see this SO question



来源:https://stackoverflow.com/questions/8872525/plot-histogram-and-density-function-curve-on-one-chart

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