ggplot2 has a stat_function() function to overlay the function on the graph in the same way as curve() . I tried a little to get this to work without generating data, until I figured out how to use the variables created by the statistics --- here ..y.. The following is similar to what you would get with curve(dbeta(x, shape1 = 2, shape2 = 2), col = "red") :
require(ggplot2) x <- seq(0, 1, len = 100) p <- qplot(x, geom = "blank") stat <- stat_function(aes(x = x, y = ..y..), fun = dbeta, colour="red", n = 100, args = list(shape1 = 2, shape2 = 2)) p + stat
source share