[R] Overlying a Normal Dist in a Barplot

Bret Collier bret at tamu.edu
Fri Jul 8 21:22:14 CEST 2005

Hopefully someone can shed some light on these questions as I had
little luck searching the archives (although I probably missed something
in my search due to the search phrase).  I estimated multinomial
probabilities for some count data (number successful offspring) ranging
from 0 to 8 (9 possible response categories).  I constructed a barplot
(using barplot2) and I want to "overlay" a normal distribution on the
figure (using rnorm (1000, mean, sd)).  My intent is to show that using
a mean(and associated sd) estimated from discrete count data may not be
a valid representation of the distribution of successful offspring.  

Obviously the x and y axes (as structured in barplot2) will not be
equivalent for these 2 sets of information and this shows up in my
example below. 

1)  Is it possible to somehow reconcile the underlying x-axis to the
same scale as would be needed to overly the normal distribution (e.g.
where 2.5 would fall on the normal density, I could relate it to 2.5 on
the barplot)?  Then, using axis (side=4) I assume I could insert a
y-axis for the normal distribution.

2)  Is lines(density(x)) the appropriate way to insert a normal
distribution into this type of figure?  Should I use 'curve'?

If someone could point me in the right direction, I would appreciate

TIA, Bret


0    0.196454948
1    0.063515510
2    0.149187592
3    0.237813885
4    0.282127031
5    0.066469719
6    0.001477105
7    0.001477105
8    0.001477105

x<-rnorm(1000, 2.84, 1.57)
barplot2(testdata, xlab="Fledgling Number", 
             ylab="Probability", ylim=c(0, 1), col="black", 
             border="black", axis.lty=1)

platform i386-pc-mingw32
arch     i386           
os       mingw32        
system   i386, mingw32  
major    2              
minor    0.1            
year     2004           
month    11             
day      15             
language R

More information about the R-help mailing list