Skip to content

Instantly share code, notes, and snippets.

@tomhopper
Created April 7, 2014 17:49
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 tomhopper/10025156 to your computer and use it in GitHub Desktop.
Save tomhopper/10025156 to your computer and use it in GitHub Desktop.
Plotting multiple probability density functions in ggplot2 using different colors
ggplot(NULL, aes(x=x, colour = distribution)) +
stat_function(fun=dnorm, data = data.frame(x = c(-6,6), distribution = factor(1)), size = 1) +
stat_function(fun=dt, args = list( df = 20), data = data.frame(x = c(-6,6), distribution = factor(2)), linetype = "dashed", size = 1) +
scale_colour_manual(values = c("blue","red"), labels = c("Normal","T-Distribution")) +
theme(text = element_text(size = 12),
legend.position = c(0.85, 0.75)) +
xlim(-4, 4) +
xlab(NULL) +
ylab(NULL)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment