在一张图表上绘制直方图和密度函数曲线 [英] Plot histogram and density function curve on one chart

查看:279
本文介绍了在一张图表上绘制直方图和密度函数曲线的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个密度函数f,我为此进行了MCMC采样.为了评估抽样的优劣,我需要在同一张图表中绘制histcurve.问题

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆