How to Plot a Beta Distribution in R (With Examples)

Plotting a beta distribution in R is easy to do using the built-in function “plot” and the beta function. To plot a beta distribution, you must pass the function the alpha and beta parameters, as well as the range of values to plot and the number of points. You can then customize the plot by adding labels, titles, and other features using the graphical parameters. Once the plot is created, you can use it to view the probability density, cumulative density, or quantile functions of the beta distribution. Examples are provided to demonstrate how to plot a beta distribution in R.


You can use the following syntax to plot a Beta distribution in R:

#define range
p = seq(0, 1, length=100)

#create plot of Beta distribution with shape parameters 2 and 10
plot(p, dbeta(p, 2, 10), type='l')

The following examples show how to use this syntax in practice.

Example 1: Plot One Beta Distribution

The following code shows how to plot a single Beta distribution:

#define range
p = seq(0,1, length=100)

#create plot of Beta distribution with shape parameters 2 and 10
plot(p, dbeta(p, 2, 10), type='l')

You can also customize the colors and axes labels of the plot:

#define range
p = seq(0,1, length=100)

#create custom plot of Beta distribution
plot(p, dbeta(p, 2, 10), ylab='density',
     type ='l', col='purple', main='Beta Distribution')

Example 2: Plot Multiple Beta Distributions

The following code shows how to plot multiple Beta distributions with different shape parameters:

#define range
p = seq(0,1, length=100)

#plot several Beta distributions
plot(p, dbeta(p, 2, 10), ylab='density', type ='l', col='purple')
lines(p, dbeta(p, 2, 2), col='red') 
lines(p, dbeta(p, 5, 2), col='blue')

#add legend
legend(.7, 4, c('Beta(2, 10)','Beta(2, 2)','Beta(1,1)'),
       lty=c(1,1,1),col=c('purple', 'red', 'blue'))

The following tutorials explain how to plot other common distributions in R:

x