问题
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