Created
August 18, 2018 10:11
-
-
Save lejon/1473c08a6e7fe7cedbb6444101c307f2 to your computer and use it in GitHub Desktop.
Plot distributions and overlayed distrobutions using ggplot
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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