Open In App

Normal Distribution in R

Last Updated : 12 Jul, 2025
Comments
Improve
Suggest changes
Like Article
Like
Report

In this article, we will discuss in detail the normal distribution and different types of built-in functions to generate normal distribution using R Programming Language.

What is Normal Distribution in R?

Normal Distribution in R is a probability function used in statistics that tells about how the data values are distributed. It is the most important probability distribution function used in statistics because of its advantages in real-case scenarios. For example, the height of the population, shoe size, IQ level, rolling a dice, and many more. It is generally observed that data distribution is normal when there is a random collection of data from independent sources. In R, there are 4 built-in functions to generate normal distribution:

  1. dnorm()
  2. pnorm()
  3. qnorm()
  4. rnorm()

Now we will discuss all 4 built-in functions to generate normal distribution in detail using R Programming Language.

1: Genrate Normal Distribution using dnorm()

The dnorm() function computes the density (height of the probability density function) at a given point for a normal distribution.

norm(x, mean = 0, sd = 1, log = FALSE)

Where,

  • x: A vector of quantiles.
  • mean: The mean of the distribution.
  • sd: The standard deviation of the distribution.
  • log: If TRUE, probabilities p are returned as log(p).

Lets perform one example to Genrate Normal Distribution using dnorm() in R.

R
# creating a sequence of values 
# between -15 to 15 with a difference of 0.1
x = seq(-15, 15, by=0.1)
 
y = dnorm(x, mean(x), sd(x))
 
# output to be present as PNG file
png(file="dnormExample.png")
 
# Plot the graph.
plot(x, y)
 
# saving the file
dev.off()  

Output:

Normal Distribution in R

2: Genrate Normal Distribution using pnorm()

The pnorm() function calculates the cumulative probability up to a given quantile.

pnorm(q, mean = 0, sd = 1, lower.tail = TRUE, log.p = FALSE)

Where,

  • q: A vector of quantiles.
  • mean: The mean of the distribution.
  • sd: The standard deviation of the distribution.
  • lower.tail: If TRUE, probabilities are P[X ≤ x]; otherwise, P[X > x].
  • log.p: If TRUE, probabilities p are returned as log(p).

Lets perform one example to Genrate Normal Distribution using pnorm() in R.

R
# creating a sequence of values
# between -10 to 10 with a difference of 0.1
x <- seq(-10, 10, by=0.1)

y <- pnorm(x, mean = 2.5, sd = 2)

# output to be present as PNG file
png(file="pnormExample.png")

# Plot the graph.
plot(x, y)

# saving the file
dev.off() 

Output:

Normal Distribution in R

3: Genrate Normal Distribution using qnorm()

The qnorm() function computes the quantile (inverse of pnorm()) for a given cumulative probability.

qnorm(p, mean = 0, sd = 1, lower.tail = TRUE, log.p = FALSE)

  • p: A vector of probabilities.
  • mean: The mean of the distribution.
  • sd: The standard deviation of the distribution.
  • lower.tail: If TRUE, probabilities are P[X ≤ x]; otherwise, P[X > x].
  • log.p: If TRUE, probabilities p are considered as log(p).

Lets perform one example to Genrate Normal Distribution using qnorm() in R.

R
# Create a sequence of probability values 
# incrementing by 0.02.
x <- seq(0, 1, by = 0.02)

y <- qnorm(x, mean(x), sd(x))

# output to be present as PNG file
png(file = "qnormExample.png")

# Plot the graph.
plot(x, y)

# Save the file.
dev.off()

Output:

Normal Distribution in R

4: Genrate Normal Distribution using rnorm()

The rnorm() function generates random numbers following a normal distribution.

rnorm(n, mean = 0, sd = 1)

  • n: Number of observations to generate.
  • mean: The mean of the distribution.
  • sd: The standard deviation of the distribution.

Lets perform one example to Genrate Normal Distribution using qnorm() in R.

R
# Create a vector of 1000 random numbers
# with mean=90 and sd=5
x <- rnorm(10000, mean=90, sd=5)

# output to be present as PNG file
png(file = "rnormExample.png")

# Create the histogram with 50 bars
hist(x, breaks=50)

# Save the file.
dev.off()

Output:

Normal Distribution in R

Conclusion

The normal distribution is a crucial concept in statistics, with applications ranging from data analysis to inferential statistics. R provides a variety of functions (dnorm(), pnorm(), qnorm(), rnorm()) to work with normal distributions, making it easy to perform statistical analyses and generate visualizations. Understanding how to use these tools is essential for effective data analysis in R.


Normal Distribution in R
Article Tags :