3.2 Graphical Measures

3.2.1 Shape

It’s a good habit to label your graph, so others can easily follow.

data = rnorm(100)

# Histogram
hist(data,labels = T,col="grey",breaks = 12) 

# Interactive histogram  
pacman::p_load("highcharter")

hchart(data) 
# Box-and-Whisker plot
boxplot(count ~ spray, data = InsectSprays,col = "lightgray",main="boxplot")

# Notched Boxplot
boxplot(len~supp*dose, data=ToothGrowth, notch=TRUE,
  col=(c("gold","darkgreen")),
  main="Tooth Growth", xlab="Suppliment and Dose")
## Warning in bxp(list(stats = structure(c(8.2, 9.7, 12.25, 16.5, 21.5, 4.2, : some
## notches went outside hinges ('box'): maybe set notch=FALSE

# If notches differ -> medians differ

# Stem-and-Leaf Plots
stem(data)
## 
##   The decimal point is at the |
## 
##   -3 | 0
##   -2 | 821
##   -1 | 7665444430
##   -0 | 9999888777776655444433222111111000
##    0 | 0112223333344444455555566667777789
##    1 | 00000112222445666
##    2 | 9
# Bagplot - A 2D Boxplot Extension
pacman::p_load(aplpack)
attach(mtcars)
bagplot(wt,mpg, xlab="Car Weight", ylab="Miles Per Gallon",
  main="Bagplot Example")

Others more advanced plots

# boxplot.matrix()  #library("sfsmisc")
# boxplot.n()       #library("gplots")
# vioplot()         #library("vioplot")