[R] Need help on ploting Histograms

Richard.Cotton at hsl.gov.uk Richard.Cotton at hsl.gov.uk
Thu May 21 16:04:50 CEST 2009


> this is the command i made for a normal distribution, but when i try to 
plot
> the histograms, i dont know why the bars don't stick on the line...
> 
> nsamples<-1000
> sampsize<-15
> Samples<-matrix(rnorm(nsamples*sampsize,0,1),nrow=nsamples) 
> a<-apply(Samples,1,var)
> NC14<-a*14
> x<-0:40
> plot(x,dchisq(x,14),type='h') 
> hist(NC14,freq=F,add=T)

Set the histogram bins to match the plot.  Change the last line of your 
code to, e.g.

hist(NC14,freq=F,add=T, breaks=x, border="transparent", col="#dddddddd")

Note that the histogram contains sample values, while the plot shows a 
theoretical distribution, so they won't match exactly.

Regards,
Richie.

Mathematical Sciences Unit
HSL


------------------------------------------------------------------------
ATTENTION:

This message contains privileged and confidential inform...{{dropped:20}}




More information about the R-help mailing list