[R] Add the Gauss curve on histogram
varin sacha
varinsacha at yahoo.fr
Tue Mar 17 12:11:54 CET 2015
Hi Jeff,
Here is I hope a reproducible code.
My R code gives something but not what I am expecting. Indeed, I am expecting a gauss curve and I get a straight line.
I have followed the advices of Rolf as well but I still don't get a gauss curve...
Thanks for your time
Dataset <- read.table("/Users/Caro/Desktop/Mesures d'association using R/test.txt", header=TRUE, sep="\t", na.strings="NA", dec=".", strip.white=TRUE)
newdata=na.omit(Dataset)
h <-hist(newdata$math.test, prob=TRUE, col="blue", border="white", xlab="Note test math", ylab="Densité", main="Test math")
x <- seq(from = min(newdata$math.test, na.rm=TRUE), to = max(newdata$math.test, na.rm=TRUE, length=100))
lines(x, dnorm(x, mean(newdata$math.test, na.rm = TRUE), sd(newdata$math.test, na.rm = TRUE)))
----- Mail original -----
De : Jeff Newmiller <jdnewmil at dcn.davis.CA.us>
À : varin sacha <varinsacha at yahoo.fr>; "r-help at r-project.org" <r-help at r-project.org>
Cc :
Envoyé le : Mardi 17 mars 2015 2h30
Objet : Re: [R] Add the Gauss curve on histogram
Not reproducible (sample data missing).
http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example
---------------------------------------------------------------------------
Jeff Newmiller The ..... ..... Go Live...
DCN:<jdnewmil at dcn.davis.ca.us> Basics: ##.#. ##.#. Live Go...
Live: OO#.. Dead: OO#.. Playing
Research Engineer (Solar/Batteries O.O#. #.O#. with
/Software/Embedded Controllers) .OO#. .OO#. rocks...1k
---------------------------------------------------------------------------
Sent from my phone. Please excuse my brevity.
>Dear R-Experts,
>
>I can easily plot an histogram and its density curve. But when I try to
>add the Gauss curve on the histogram with the following Rcode here
>below, I don't get it. What is wrong ? Or what is missing in my code ?
>
>##Plot an histogram
>h=hist(newdata$math.test, prob=TRUE, col="blue", border="white",
>xlab="Note test math", ylab="Densité", main="Test math")
>
>##Add the density curve on the histogram
>lines(density(newdata$math.test,na.rm=TRUE),lwd=2,col="orange")
>
>##Add the Gauss curve on the histogram
>x <- seq(from = min(newdata$math.test, na.rm=TRUE), to =
>max(newdata$math.test, na.rm=TRUE), lines(x, dnorm(x,
>mean(newdata$math.test, na.rm = TRUE), sd(newdata$math.test, na.rm =
>TRUE)))
>
>
>Best, thanks for your time.
>
>______________________________________________
>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