1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
|
# Histogram ####################################################################
par(mfrow=c(1, 2))
head(mtcars, n=15)
mtcars$mpg
a=rnorm(100000, mean=0, sd=3)
hist(a)
hist(a, breaks=100)
# Basic Histogram
par(mfrow=c(2, 2))
hist(mtcars$mpg)
hist(mtcars$mpg, breaks=10, col="gray")
hist(mtcars$mpg, breaks=10, xlim=c(0, 40), col="gray")
hist(mtcars$mpg, breaks=10, xlim=c(0, 40), col=c("gray", "red"))
# Histogram and Fit
par(mfrow=c(1,2))
numMpg = mtcars$mpg
objHist = hist(numMpg, breaks=10, col="gray", xlim=c(10, 40),
xlab="Efficiency (MPG)",
main="Histogram of Fuel Efficiency")
objHist
numX = seq(min(numMpg), max(numMpg), length=100)
numX
numY = dnorm(numX, mean = mean(numMpg), sd = sd(numMpg))
numY
numAdjY = numY * length(numMpg) * diff(objHist$mids[1:2])
numAdjY
sum(numAdjY)
lines(numX, numAdjY, col="blue", lwd=2)
abline(v = mean(numMpg), lty = 21, col="red")
abline(h = 3, lty = 21, col="blue")
plot(numX, numY, pch = 20, col="red", cex=1.5)
lines(numX, numY, col="blue", lwd=2)
abline(v = mean(numMpg), lty = 21, col="red")
|