In: Computer Science
1. In R Studio create a plot with two subplots (2 rows, 1 column):
Code snippet:
mean = c(0,0,0,1,1,1)
sd = c(1,2,3,1,2,3)
x = seq(-4,4,length=200) #input data
hx = dnorm(x, mean = 0, sd = 1)
colors <- c("black", "red", "green", "blue",
"lightblue","purple")
labels <- c("(0,1)", "(0,2)", "(0,3)", "(1,1)", "(1,2)","(1,3)")
par(mfrow=c(2,1)) #for subplotting
plot(x, hx, type="l", main="pdf curves")
for(i in 2:length(mean)){
lines(x, dnorm(x, mean = mean[i], sd = sd[i]), lwd=2,
col=colors[i])
}
legend("topright", title="pdf distributions",
labels, ncol = 2,fill = 1:6, col=color ,cex = 0.45)
hx1 = pnorm(x, mean = 0, sd = 1)
plot(x, hx1, type="l", xlab="x value",
ylab="Density", main="cdf curves", lty = 1)
for(i in 2:length(mean)){
lines(x, pnorm(x, mean = mean[i], sd = sd[i]), lwd=2,
col=colors[i])
}
legend("topleft", title="cdf distributions",
labels,fill = 1:6, ncol = 2, col=colors,cex = 0.45)