library(dplyr) library(ggplot2) dist_maker <- function(d, m, s){ d <- eval(parse(text=d[1])) function(x){ d(x, m, s) } } lnorm_sd_from_mean_mode <- function(mu, mo){ sqrt((mu^3 * (mo/mu)^(1/3))/mo - mu^2) } dlnorm_mean_sd <- function(x, m, s){ l_m <- log(m / sqrt(1 + s^2/m^2)) l_s <- sqrt(log(1 + s^2/m^2)) dlnorm(x, l_m, l_s) } data.frame(distribution = c('A', 'B', 'C', 'D'), mu = c(50, 60, 60, 60), sigma = c(10, 10, 15, lnorm_sd_from_mean_mode(60, 50)), dfunc = c("dnorm", "dnorm", "dnorm", "dlnorm_mean_sd") ) %>% do(cbind(.[rep(seq(1, nrow(.)), each = 200),], x = seq(20, 120, length.out = 200)) ) %>% group_by(distribution) %>% mutate(density = dist_maker(dfunc, mu, sigma)(x)) %>% ggplot(aes(x = x, y = density, color = distribution)) + geom_line() + scale_color_brewer(type = 'qual', palette = 3) + facet_grid(distribution ~ .) + theme_bw()