Hi:

Another approach to multiple plotting in base graphics is to use matplot,
which
is particularly convenient for something such as densities because the plots
are of
a similar character with the same domain. Here's an example:

x <- seq(0, 1, by = 0.01)
d1 <- dbeta(x, 2, 2)
d2 <- dbeta(x, 3, 3)
d3 <- dbeta(x, 4, 4)
d4 <- dbeta(x, 5, 5)
d5 <- dbeta(x, 6, 6)

betapdfs <- rbind(d1, d2, d3, d4, d5)  # combine into matrix
matplot(x, t(betapdfs), type = 'l', col = 1:5, ylab = 'Density')
legendpars <- c('(2, 2)', '(3, 3)', '(4, 4)', '(5, 5)', '(6, 6)')  # labels
for legend
legend('topright', legendpars, lty = 1:5, col = 1:5)

You need to transpose the betapdfs matrix so that the number of rows of the
'y'
matrix matches the length of x. You may want to tweak some of the features;
e.g., to make all lines solid, insert lty = 1 in the matplot call (and in
the legend).
For anything else, see ?matplot

HTH,
Dennis

On Mon, Jan 4, 2010 at 12:13 PM, John Westbury <jrwestbury@gmail.com> wrote:

> Hello,
>
> I am new to R and have two easy questions.
>
> How can you plot multiple density functions in one graph?  I have five beta
> densities that I would like to plot in one graph.  I understand how to plot
> one beta density as a line:
>
> plot (x,(dbeta(x,shape1=,shape2=,), type ="l")
>
> Does the Pareto distribution need to be added to R with an additional
> package?
>
> thanks,
> John
>
>        [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

	[[alternative HTML version deleted]]

