[R] Shift the normal curve to the top or near to the top of the histogram

Rui Barradas ruipbarradas at sapo.pt
Mon Sep 25 12:00:45 CEST 2017


Hello,

Try using hist argument 'prob = TRUE' or, which is equivalent, 'freq = 
FALSE'.

hist(..., prob = TRUE)   # or hist(..., freq = FALSE)

This is because like this you will have a density, comparable to a 
parametric density. Note that the peak of the normal will be outside the 
plot area so you will have to adjust the plot area dimensions. In this 
case I've set 'ylim = c(0, 0.35)'.


hist(Lizard.tail.lengths, main = "Normal Probability Plot of Lizard Tail
Lengths", ylim = c(0, 0.35), prob = TRUE)

curve(dnorm(x ,mean=mean(Lizard.tail.lengths),sd=sd(Lizard.tail.lengths)),
add=TRUE, col=2, lwd = 2)


Hope this helps,

Rui Barradas

Em 25-09-2017 00:35, AbouEl-Makarim Aboueissa escreveu:
> Dear All:
>
> One more thing.
>
> I want to add the normal curve to the histogram. Is there away to stretch
> the peak of the curve to the top of the histogram or at least near to the
> top of the histogram.
>
> Please see the code below.
>
>
> Lizard.tail.lengths <- c(6.2, 6.6, 7.1, 7.4, 7.6, 7.9, 8, 8.3, 8.4, 8.5,
> 8.6,8.8, 8.8, 9.1, 9.2, 9.4, 9.4, 9.7, 9.9, 10.2, 10.4, 10.8,11.3, 11.9)
>
> x<-seq(5,12, 0.001)
>
> hist(Lizard.tail.lengths, main = "Normal Probability Plot of Lizard Tail
> Lengths")
>
> curve(dnorm(x ,mean=mean(Lizard.tail.lengths),sd=sd(Lizard.tail.lengths)),
> add=TRUE, col=2, lwd = 2)
>
>
>
> with many thanks
> abou
> ______________________
> AbouEl-Makarim Aboueissa, PhD
> Professor of Statistics
> Department of Mathematics and Statistics
> University of Southern Maine
>
> 	[[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



More information about the R-help mailing list