x <- seq(-4, 4, length=100)
y <- dnorm(x, mean=0, sd=1)
plot(x, y, type="l",
main="Kurva Distribusi Normal",
xlab="Nilai",
ylab="Kepadatan")

x <- seq(4, 16, length=100)
y <- dnorm(x, mean=10, sd=2)
plot(x, y, type="l",
main="Kurva Distribusi Normal (μ = 10, σ = 2)",
xlab="Nilai",
ylab="Kepadatan")

# Nilai x
x <- seq(0, 20, length=1000)
# Kurva normal
y1 <- dnorm(x, mean=10, sd=1)
y2 <- dnorm(x, mean=10, sd=2)
y3 <- dnorm(x, mean=10, sd=3)
y4 <- dnorm(x, mean=10, sd=4)
# Grafik pertama
plot(x, y1, type="l",
main="Kurva Distribusi Normal",
xlab="Nilai",
ylab="Kepadatan",
ylim=c(0, 0.22))
# Menambahkan kurva lainnya
lines(x, y2)
lines(x, y3)
lines(x, y4)
# Garis rata-rata μ = 10
abline(v=10, lty=2)
# Keterangan
legend("topright",
legend=c("σ = 1", "σ = 2", "σ = 3", "σ = 4"),
lty=1)

x <- 0:20
y1 <- dnorm(x, mean=10, sd=1)
y2 <- dnorm(x, mean=10, sd=2)
y3 <- dnorm(x, mean=10, sd=3)
y4 <- dnorm(x, mean=10, sd=4)
plot(x, y1, type="o",
main="Kurva Distribusi Normal",
xlab="Count",
ylab="Kepadatan",
ylim=c(0, 0.22),
pch=16)
lines(x, y2, type="o", pch=16)
lines(x, y3, type="o", pch=16)
lines(x, y4, type="o", pch=16)
abline(v=10, lty=2)
legend("topright",
legend=c("σ=1", "σ=2", "σ=3", "σ=4"),
lty=1,
pch=16)

# Parameter distribusi
mu <- c(0, 2, 5, 10, 15)
sigma <- c(1, 1, 5, 3, 0.1)
# Warna masing-masing kurva
warna <- c("blue", "red", "green", "purple", "orange")
# Membuat nilai X (Count)
x <- seq(-5, 20, length=1000)
# Membuat kurva normal
y1 <- dnorm(x, mean=mu[1], sd=sigma[1])
y2 <- dnorm(x, mean=mu[2], sd=sigma[2])
y3 <- dnorm(x, mean=mu[3], sd=sigma[3])
y4 <- dnorm(x, mean=mu[4], sd=sigma[4])
y5 <- dnorm(x, mean=mu[5], sd=sigma[5])
# Grafik kurva pertama
plot(x, y1,
type="l",
col=warna[1],
lwd=2,
ylim=c(0, 0.45),
main="Simulasi Distribusi Normal (5 Variabel)",
xlab="Count (X)",
ylab="Kepadatan")
# Menambahkan 4 kurva lainnya
lines(x, y2, col=warna[2], lwd=2)
lines(x, y3, col=warna[3], lwd=2)
lines(x, y4, col=warna[4], lwd=2)
lines(x, y5, col=warna[5], lwd=2)
# Garis rata-rata μ = 10
abline(v=10, lty=2)
# Legenda
legend("topright",
legend=c(
"Kurva 1: μ=0, σ=1",
"Kurva 2: μ=2, σ=1",
"Kurva 3: μ=5, σ=5",
"Kurva 4: μ=10, σ=3",
"Kurva 5: μ=15, σ=0.1"
),
col=warna,
lwd=2)

# Membagi tampilan menjadi 3 x 3 grafik
par(mfrow=c(3,3))
# 1. DISTRIBUSI NORMAL
x <- seq(0,20,length=1000)
y <- dnorm(x, mean=10, sd=2)
plot(x,y,type="l",col="blue",lwd=2,
main="Distribusi Normal",
xlab="X",ylab="Kepadatan")
# 2. DISTRIBUSI t
x <- seq(-5,5,length=1000)
y <- dt(x,df=5)
plot(x,y,type="l",col="red",lwd=2,
main="Distribusi t",
xlab="X",ylab="Kepadatan")
# 3. DISTRIBUSI F
x <- seq(0,6,length=1000)
y <- df(x,df1=5,df2=10)
plot(x,y,type="l",col="green",lwd=2,
main="Distribusi F",
xlab="X",ylab="Kepadatan")
# 4. DISTRIBUSI CHI-SQUARE
x <- seq(0,20,length=1000)
y <- dchisq(x,df=5)
plot(x,y,type="l",col="purple",lwd=2,
main="Distribusi Chi-Square",
xlab="X",ylab="Kepadatan")
# 5. DISTRIBUSI GAMMA
x <- seq(0,10,length=1000)
y <- dgamma(x,shape=2,rate=1)
plot(x,y,type="l",col="orange",lwd=2,
main="Distribusi Gamma",
xlab="X",ylab="Kepadatan")
# 6. DISTRIBUSI WEIBULL
x <- seq(0,8,length=1000)
y <- dweibull(x,shape=2,scale=2)
plot(x,y,type="l",col="brown",lwd=2,
main="Distribusi Weibull",
xlab="X",ylab="Kepadatan")
# 7. DISTRIBUSI EKSPONENSIAL
x <- seq(0,8,length=1000)
y <- dexp(x,rate=1)
plot(x,y,type="l",col="pink",lwd=2,
main="Distribusi Eksponensial",
xlab="X",ylab="Kepadatan")
# 8. DISTRIBUSI PARETO
# R tidak memiliki fungsi dpareto bawaan,
# sehingga rumus kepadatannya dibuat manual
x <- seq(1,10,length=1000)
shape <- 3
scale <- 1
y <- shape*scale^shape/x^(shape+1)
plot(x,y,type="l",col="darkgreen",lwd=2,
main="Distribusi Pareto",
xlab="X",ylab="Kepadatan")
# 9. DISTRIBUSI UNIFORM
x <- seq(0,10,length=1000)
y <- dunif(x,min=0,max=10)
plot(x,y,type="l",col="darkblue",lwd=2,
main="Distribusi Uniform",
xlab="X",ylab="Kepadatan")

# Mengembalikan tampilan menjadi 1 grafik
par(mfrow=c(1,1))