Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.
Use stat_function(). It’s
also necessary to give ggplot() a dummy
data frame so that it will get the proper x range.
In this example we’ll use dnorm(), which
gives the density of the normal distribution (Figure 13-4, left):
# The data frame is only used for setting the rangep<-ggplot(data.frame(x=c(-3,3)),aes(x=x))p+stat_function(fun=dnorm)
Some functions take additional arguments. For example, dt(), the
function for the density of the t-distribution,
takes a parameter for degrees of freedom (Figure 13-4, right). These additional arguments
can be passed to the function by putting them in a list and giving the
list to args: