I am learning ggplot2 commands specifically qplot for the time being and I have figured out how to create histograms and normal density curves but I am not sure how to add a normal bell curve or other dist. as well on top of a histogram.
Here are the two graphs that I created.
w<-qplot(t, main="Normal Random Sample", fill=I("blue"), colour=I("black"), geom="histogram")
r<-qplot(t, main="Normal Random Sample", colour=I("black"), geom="density", adjust=4)
Don't use t as var names, because t is also a function (transpose).
This code should work...
T <- rnorm(500)
qplot(T, geom = "blank") +
geom_histogram(aes(y = ..density..), colour = "black", fill = "blue") +
stat_density(geom = "line", colour = "red")
> -----Original Message-----
> From: [hidden email] > [mailto:[hidden email]] On Behalf Of dicko ahmadou
> Sent: Tuesday, June 07, 2011 11:41 AM
> To: [hidden email] > Subject: Re: [R] ggplot 2: Histogram with bell curve?
> Don't use t as var names, because t is also a function (transpose).
> This code should work...
> T <- rnorm(500)
I think that it is more dangerous to use 'T' than 't' since
'T' is a built-in data name (with value TRUE) and I've
seen it used more than 't' (probably because S and S+
regard it as a reserved word). I don't think that reusing
built-in names as local names is as dangerous as some would make
out but reusing built-in data names is probably more dangerous
than using built-in function names for local data names
(because function name lookup is done differently than general
name lookup - the former will only look for functions).
Spotfire, TIBCO Software