How to plot a Gamma distribution in ggplot2

Viewed 5851

I have a plot in R that I am trying to replicate in ggplot2. I have the following code:

theta = seq(0,1,length=500)
post <- dgamma(theta,0.5, 1)
plot(theta, post, type = "l", xlab = expression(theta), ylab="density", lty=1, lwd=3)

enter image description here

I have tried to replicate this plot in ggplot2 and this is the closest I was able to get.

df=data_frame(post,theta)
ggplot(data=df,aes(x=theta))+
  stat_function(fun=dgamma, args=list(shape=1, scale=.5))

enter image description here

1 Answers
Related