3

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.

Gavin Simpson
  • 170,508
  • 25
  • 396
  • 453
Ziyuan
  • 4,215
  • 6
  • 48
  • 77

1 Answers1

7

Use the prob=TRUE argument to hist:

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

Also see this SO question

Community
  • 1
  • 1
Dirk Eddelbuettel
  • 360,940
  • 56
  • 644
  • 725
  • Thank you, @Dirk Eddelbuettel, it is perfect. One more question. What if my density function is not normalized? The option `prob` does not help. (Besides manually normalization) – Ziyuan Jan 15 '12 at 19:40