Skip to content

Instantly share code, notes, and snippets.

@christophergandrud
Created June 13, 2017 17:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save christophergandrud/0494d30ae2afaa580c3be42d5af9c044 to your computer and use it in GitHub Desktop.
Save christophergandrud/0494d30ae2afaa580c3be42d5af9c044 to your computer and use it in GitHub Desktop.
Simple function for simulating/plotting beta distributions for Dataverse 2017 Package Development Workshop
#' @import ggplot2
#' @export
beta_plot <- function(n = 10000, a = 1, b = 3) {
# draw distributions
sims <- rbeta(n = n, shape1 = a, shape2 = b)
# convert to data frame for ggplot2 compatability
sims <- data.frame(x = sims)
# plot probability density function
ggplot(sims, aes(x)) +
geom_density() +
xlab("") + ylab("Probability Density Function") +
theme_bw()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment