0

I know similar questions have been asked before but nothing that is specific to my problem:

gamma_j <- function(x) {
  y <- .120605*dgamma(x, shape =  2.2181, scale = 4.310067) + 
    .879395*dgamma(x, shape = 5.2007, scale = 8.7208)
  return(y)
}

j_plot <- plot(gamma_j(0:120), type =  "l")

Above is a gamma mixture I created. How do I stack this on top of my original histogram, which I made using ggplot?

pop_dist <- ggplot(HHMembers, aes(Age)) +
  geom_histogram(binwidth = 1)
pop_dist

I'm sorry I don't know how to input the Age data itself. There's tens of thousands of data points so things like dput are too big for the console for me to copy and paste.

But as you can see one was using ggplot and the other was using the built-in plot function so I'm not sure how to stack them together. Plus one is a density and the other is a frequency. Would dividing the frequency by the total fix part of the problem?

Thanks (:

  • So many relevant links: [here](https://www.r-bloggers.com/exploratory-data-analysis-combining-histograms-and-density-plots-to-examine-the-distribution-of-the-ozone-pollution-data-from-new-york-in-r/), [here](https://www.packtpub.com/mapt/book/big_data_and_business_intelligence/9781849513067/6/ch06lvl1sec07/overlaying-density-line-over-a-histogram), [here](https://stackoverflow.com/questions/37404002/geom-density-to-match-geom-histogram-binwitdh), [here](https://stackoverflow.com/questions/15117843/overlay-density-and-histogram-plot-with-ggplot2-using-custom-bins), ... – Maurits Evers Feb 28 '18 at 02:08
  • Are you saying that none of the solutions in any of these links have worked for you? In that case, could you please be more specific in *what* you've tried and *how* it didn't work. – Maurits Evers Feb 28 '18 at 02:11

1 Answers1

0

Just plot your histogram and then run

curve(gamma_j, add=TRUE)
G5W
  • 36,531
  • 10
  • 47
  • 80