0

I want to plot the PMF of binomial(40, 0.5), but the following barplot seems giving me a wrong x-axis position?

probability = dbinom(0:40, 40, 0.5)
plot(probability, pch = 21, bg="red")
barplot(probability, add = TRUE)

enter image description here

My barplot() is using the same data probability as its height, why it shifts a little bit toward right? I am wondering where I have missed and how can I fix it?

Jay Wang
  • 2,650
  • 4
  • 25
  • 51
  • http://stackoverflow.com/a/15332146/6455166 should be helpful. – Weihuang Wong Feb 02 '17 at 02:51
  • 1
    you can see the midpoints of the bars using `b = barplot(probability, plot=FALSE, width=1, space=0)` (note I added the extra `width` and `space` arguments). Your scatter plot uses x-axis values from one to `length(probability)` by default as you didnt add in an x-variable. So you need to adjust this term. – user20650 Feb 02 '17 at 02:54

0 Answers0