I would like to plot the gamma density function derived from a set of observations over the histogram of the observed data. I am able to generate the histogram and parameter estimates for the gamma fit. This is being done for multiple subsets of data from a master data set. How can I plot the gamma density function on each of the histograms created in this loop?
I currently have:
library(MASS)
species <- c('acesac', 'acesac', 'acesac', 'acesac', 'acesac', 'acesac',
'polbif', 'polbif', 'polbif', 'polbif', 'polbif', 'polbif')
tmean <- c(2,3,5,6,6,7,5,6,6,6,8,9)
Data <- data.frame(species, tmean)
for (i in unique(Data$species)){
subdata <- subset(Data, species ==i)
hist(subdata$tmean, main = i)
dist <- fitdistr(subdata$tmean, "gamma")
}
I'm thinking that I should use lines()
, however, not sure how to specify this?