I have question probably similar to Fitting a density curve to a histogram in R. Using qplot I have created 7 histograms with this command:
(qplot(V1, data=data, binwidth=10, facets=V2~.)
For each slice, I would like to add a fitting gaussian curve. When I try to use lines() method, I get error:
Error in plot.xy(xy.coords(x, y), type = type, ...) :
plot.new has not been called yet
What is the command to do it correctly?
Have you tried
stat_function?You’ll probably want to plot the histograms using
aes(y = ..density..)in order to plot the density values rather than the counts.A lot of useful information can be found in this question, including some advice on plotting different normal curves on different facets.
Here are some examples:
Overlay a single normal density on each facet:
From the question I linked to, create a separate data frame with the different normal curves:
And plot them separately using
geom_line: