plot a normal distribution with a mean of 10 and sd of 2 in r

To plot a normal distribution with a mean of 10 and standard deviation of 2 in R, we can use the dnorm() and curve() functions.

dnorm() is used to calculate the height of the probability density function at a given point, while curve() is used to plot the probability density function over a range of values.

Here's an example code:

main.r
# Set mean and standard deviation
mean <- 10
sd <- 2

# Create a sequence of values from mean - 3 * sd to mean + 3 * sd
x <- seq(mean - 3*sd, mean + 3*sd, length=100)

# Use dnorm() to calculate the height of the probability density function at each value of the sequence
y <- dnorm(x, mean, sd)

# Plot the density curve using curve()
curve(dnorm(x, mean, sd), from = mean - 3*sd, to = mean + 3*sd, ylab="Density", xlab="X", main="Normal Probability Density Function")
470 chars
13 lines

This will produce a plot that shows the normal probability density function with a mean of 10 and standard deviation of 2.

gistlibby LogSnag