*22*

The uniform distribution is a probability distribution in which every value between an interval from *a* to *b* is equally likely to occur.

If a random variable *X* follows a uniform distribution, then the probability that *X* takes on a value between *x _{1}* and

*x*

_{2}can be found by the following formula:

**P(x _{1} 2) = (x_{2 }â€“ x_{1}) / (b â€“ a)**

where:

**x**the lower value of interest_{1}:**x**the upper value of interest_{2}:**a:**the minimum possible value**b:**the maximum possible value

The following examples show how to plot a uniform distribution in R.

**Example 1: Plot Basic Uniform Distribution in R**

The following code shows how to plot a basic uniform distribution in R:

#define x-axis x #calculate uniform distribution probabilities y #plot uniform distribution plot(x, y, type = 'l')

The x-axis displays the potential values for a random variable that follows a uniform distribution while the y-axis shows the probability that the random variable takes on those values.

**Note**: The **dunif()** function in R is used to calculate the density of a uniform distribution, given a minimum and maximum value.

**Example 2: Plot Custom Uniform Distribution in R**

The following code shows how to plot a basic uniform distribution in R along with how to modify the title, axes labels, and colors:

#define x-axis x #calculate uniform distribution probabilities y #plot uniform distribution plot(x, y, type = 'l', lwd = 3, ylim = c(0, .2), col='blue', xlab='x', ylab='Probability', main='Uniform Distribution Plot')

**Additional Resources**

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

How to Plot a Normal Distribution in R

How to Plot a Chi-Square Distribution in R

How to Plot a Poisson Distribution in R

How to Plot a Binomial Distribution in R

How to Plot an Exponential Distribution in R