Skip to content

Instantly share code, notes, and snippets.

@lejon
Created August 18, 2018 10:11
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 lejon/1473c08a6e7fe7cedbb6444101c307f2 to your computer and use it in GitHub Desktop.
Save lejon/1473c08a6e7fe7cedbb6444101c307f2 to your computer and use it in GitHub Desktop.
Plot distributions and overlayed distrobutions using ggplot
plot_dist <- function(dist_fun, dist_args, range) {
pl <- ggplot(data = data.frame(x = range), aes(x)) +
stat_function(fun = dist_fun, n = 101, args = dist_args) + ylab("") +
scale_y_continuous(breaks = NULL)
}
plot_overlay_dist <- function(dist_funs, dist_args, range) {
pl <- ggplot(data = data.frame(x = range), aes(x)) + scale_y_continuous(breaks = NULL)
fcnt <- 1;
for(dfun in dist_funs) {
pl <- pl + stat_function(fun = dfun, n = 101, args = dist_args[[fcnt]]) + ylab("")
fcnt <- fcnt + 1
}
pl
}
print(plot_overlay_dist(c(dnorm,dcauchy), list(list(mean = 100, sd = 1),list(location = 100, scale = 2.5)), c(75,125)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment