Overlay normal distribution curve on histogram

160 views
Skip to first unread message

mick.h...@gmail.com

unread,
Jun 22, 2015, 10:26:16 PM6/22/15
to ded...@googlegroups.com
Hi,
I've got Deducer working (on one computer anyway) and getting my head around the plot builder. I'm trying to create histogram with a normal distribution curve superimposed, as per the attached pic.
Two questions:
a) How is it possible to achieve this via plot builder? (histogram is fine, but what elements/settings for the curve?)
b) Is it possible to filter the data used (e.g. I have a column of data, but I only what to plot the subset for one site)
Thanks
- Mick


Ian Fellows

unread,
Jun 23, 2015, 2:25:22 PM6/23/15
to ded...@googlegroups.com
So that is one of the more annoying things to do in ggplot. It is possible though using the stat_function element. The code created is:

ggplot() +
geom_histogram(aes(y = ..density..,x = mpg),data=mtcars) +
stat_function(aes(x = mpg),data=mtcars,fun = dnorm,args = list(mean=mean(mtcars$mpg),sd=sd(mtcars$mpg)))

for (b), the easiest thing to do is to subset before plotting using the Data -> subset dialog.

Best,
Ian


--

---
You received this message because you are subscribed to the Google Groups "Deducer" group.
To unsubscribe from this group and stop receiving emails from it, send an email to deducer+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

mick.h...@gmail.com

unread,
Jun 24, 2015, 8:02:43 AM6/24/15
to ded...@googlegroups.com
Thankyou Ian,
I was so close :)
I had tried that form of input without joy, but after testing your example successfully, I realise that my data was to blame. I assume this is because it contained some NA values.
I haven't tried subset before, but this format seemed to work Data.sub1<-subset(Data, !is.na(x)).
Is that the correct usage to just assign those rows in 'Data' where variable 'x' is not 'NA' ?
Thanks
- Mick
Message has been deleted

mick.h...@gmail.com

unread,
Jun 24, 2015, 8:30:54 AM6/24/15
to ded...@googlegroups.com, mick.h...@gmail.com
It's working now. Thanks again
- Mick


Reply all
Reply to author
Forward
0 new messages