在一张图表上绘制直方图和密度函数曲线 [英] Plot histogram and density function curve on one chart
问题描述
我有一个密度函数f,我为此进行了MCMC采样.为了评估抽样的优劣,我需要在同一张图表中绘制hist
和curve
.问题
hist(samples);
curve(dfun,add=TRUE);
它们的尺度不同:某个容器的频率通常为数百,而密度函数的最大值约为1左右.我想做的是在同一高度配置两个图,一个y轴在左侧,另一个在y轴上.有人可以帮忙吗?谢谢.
对hist
使用prob=TRUE
参数:
hist(samples, prob=TRUE)
curve(dfun,add=TRUE)
另请参见此SO问题 >
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.
Use the prob=TRUE
argument to hist
:
hist(samples, prob=TRUE)
curve(dfun,add=TRUE)
Also see this SO question
这篇关于在一张图表上绘制直方图和密度函数曲线的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!