Graphing Normal Distributions with Varied Variances

Graphing Normal Distributions with Varied Variances





I want to create a normal distribution graph with a specific variance. First, it’s necessary to create the data. I’ll generate data with a mean of 100 and a variance of 100 (which means the standard deviation is 10). However, it’s important to establish a range. To do this, I’ll set up a range of 6σ, and the dataset will contain 1,000 rows.

mean=100
variance=100

distribution= data.frame(y=seq(mean-6*sqrt(variance), mean+6*sqrt(variance), length.out=1000))

head(distribution,10)
          y
1  40.00000
2  40.12012
3  40.24024
4  40.36036
5  40.48048
6  40.60060
7  40.72072
8  40.84084
9  40.96096
10 41.08108
.
.
.

and I’ll create a normal distribution graph.

if(!require(ggplot2)) install.packages("ggplot2")
library(ggplot2)

ggplot(distribution, aes(x=y)) +
  stat_function(fun=dnorm, args=list(mean=mean(distribution$y), 
                                     sd=sd(distribution$y)), color="black") +
  scale_x_continuous(breaks=seq(0,200,50), limits=c(0,200)) +
  scale_y_continuous(breaks=seq(0,0.02,0.005), limits=c(0,0.02)) +
  labs(x="Value", y="Frequency") +
  theme_classic() +
windows(width=5.5, height=5)

These are graphs with different variances, ranging from 1σ to 6σ.






Comments are closed.