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'))
Additional Resources
The following tutorials explain how to plot other common distributions in R:
How to Plot a Normal Distribution in R
How to Plot a Chi-Square Distribution in R
How to Plot a Binomial Distribution in R
How to Plot a Poisson Distribution in R