The Wayback Machine - https://web.archive.org/web/20261103222206/https://www.geeksforgeeks.org/r-language/normal-distribution-in-r/

Normal Distribution in R

Last Updated : 28 Oct, 2026

The normal distribution is a continuous probability distribution that describes how data values are distributed around the mean. It is commonly used in statistics to represent data such as human heights and IQ scores. In the R Language, four built-in functions are used to work with the normal distribution: dnorm() pnorm() qnorm() rnorm()

1. Calculate Probability Density using dnorm()

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

Syntax:

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

  • x: A numeric value or vector at which to calculate the probability density.
  • mean: The mean of the normal distribution. The default is 0.
  • sd: The standard deviation of the normal distribution. The default is 1.
  • log: If TRUE, returns the logarithm of the density; otherwise, returns the density itself.
R
x = seq(-15, 15, by=0.1)
 
y = dnorm(x, mean(x), sd(x))
png(file="dnormExample.png")
plot(x, y)

dev.off()

Output:

Normal Distribution in R

Explanation:

  • The graph shows the probability density of a normal distribution.
  • The curve is bell-shaped and reaches its highest point near (x = 0).
  • The density decreases as the values move away from the center in either direction.
  • The graph is approximately symmetric around the mean.

2. Calculate Cumulative Probability using pnorm()

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

Syntax:

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

  • 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).
R
x <- seq(-10, 10, by=0.1)

y <- pnorm(x, mean = 2.5, sd = 2)
png(file="pnormExample.png")
plot(x, y)
dev.off() 

Output:

Normal Distribution in R

Explanation:

  • The graph shows the cumulative probability of a normal distribution.
  • The x-axis represents the input values, while the y-axis represents cumulative probabilities.
  • The cumulative probability increases from approximately 0 to 1 as the input value increases.
  • The S-shaped curve rises most rapidly around the mean, which is 2.5 in this example.

3. Calculate Quantiles Using qnorm()

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

Syntax:

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).
R
x <- seq(0, 1, by = 0.02)

y <- qnorm(x, mean(x), sd(x))
png(file = "qnormExample.png")
plot(x, y)
dev.off()

Output:

Normal Distribution in R

Explanation:

  • The graph shows the quantiles corresponding to different cumulative probabilities.
  • The x-axis represents probabilities, while the y-axis represents the corresponding quantile values.
  • The quantile increases as the probability increases.
  • The curve becomes steeper near probabilities of 0 and 1 because the quantile values extend toward negative and positive infinity, respectively.

4. Generate Random Values using rnorm()

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

Syntax:

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.
R
x <- rnorm(10000, mean = 90, sd = 5)

png(file = "rnormExample.png")
hist(x, breaks = 50)
dev.off()

Output:

Normal Distribution in R

Explanation:

  • The histogram shows the frequency distribution of 10,000 randomly generated values.
  • The values are generated using a normal distribution with a mean of 90 and a standard deviation of 5.
  • Most values are concentrated around 90, while fewer values occur farther from the mean.
  • The histogram forms an approximately bell-shaped distribution.
Comment

Explore