eyecolor <- c(rep("blue", 3), rep("brown", 3), "hazel",
              "blue", "brown", "blue", "green", "brown")
height <- c(66, 62, 64, 70, 68, 62, 72, 62, 61, 59, 64, 65)
DF <- data.frame(eyecolor, height)
rm("eyecolor", "height")
DT::datatable(DF)
(mh <- mean(DF$height))
## [1] 64.58333

The average height (\(\bar{X}\)) for this class is 64.58 inches.

hist(DF$height, col = "blue")

boxplot(DF$height, col = "purple", horizontal = TRUE)

ggplot2

library(ggplot2)
ggplot(data = DF, aes(x = height)) +
  geom_histogram() + 
  theme_bw()
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

#
ggplot(data = DF, aes(x = height)) +
  geom_histogram(binwidth = 2, fill = "green", color = "black") + 
  theme_bw() 

#
ggplot(data = DF, aes(x = height, y = ..density..)) +
  geom_histogram(binwidth = 2, fill = "red", color = "black") + 
  theme_bw() +
  geom_density()

ggplot(data = DF, aes(x = "", y = height)) + 
  geom_boxplot(fill = "pink") + 
  coord_flip() + 
  labs(x = "") + 
  theme_bw()

Base Graphs

Barplots

table(DF$eyecolor)
## 
##  blue brown green hazel 
##     5     5     1     1
barplot(table(DF$eyecolor), col = c("blue", "brown", "green", "darkgreen"))

ggplot2 bargraphs

ggplot(data = DF, aes(x = eyecolor)) +
  geom_bar(fill = c("blue", "brown", "green", "darkgreen")) +
  theme_bw()

Writing Mathematics

The standard deviation (\(s\)) is defined as

\[s = \sqrt{\sum_{i=1}^n \frac{(x_i - \bar{x})^2}{n-1}}\]