07 – Plotting

Sebastian Raschka 6/17/2020

Source file: https://github.com/rasbt/R-notes/blob/master/07-plotting.Rmd

Plotting

Stem-and-Leaf plots

urban_barkdist <- c(29, 10, 15, 41, 18, 18, 12, 45, 34, 30, 22, 26, 18)
urban_concealdist <- c(8, 8, 10, 8, 9, 10, 9, 10, 9, 6, 6, 7, 5)
rural_barkdist <- c(40, 47, 38, 59, 45, 52, 57, 50, 50, 49, 50, 43)
rural_concealdist <- c(14, 12, 24, 30, 37, 46, 39, 22, 38, 38, 20, 33)

stem(urban_barkdist)

## 
##   The decimal point is 1 digit(s) to the right of the |
## 
##   1 | 025888
##   2 | 269
##   3 | 04
##   4 | 15

Histograms

hist(urban_barkdist)

R notes screenshot

hist(urban_barkdist, breaks=seq(0, 50, by = 5))

R notes screenshot

Barplot

barplot(c(mean(urban_barkdist), mean(rural_barkdist)),
        xlab="Bark distance (m)",
        names.arg=c("Urban", "Rural"),
        ylim=c(0, 65))

R notes screenshot

Scatterplots

plot(urban_barkdist, urban_concealdist,
     xlab="Bark distance (m)",
     ylab="Concealment discance (m)")

R notes screenshot

plot(urban_barkdist, urban_concealdist,
     xlim=range(1, 60), 
     ylim=range(1, 60),
     xlab='Bark distance (m)', 
     ylab='Concealment distance (m)');
points(rural_barkdist, rural_concealdist, pch=2)
legend(1, 50, pch=1:2, legend=c("Urban", "Rural"))

R notes screenshot

Boxplots