#
# CHAPTER 20: High-level graphics
#
# univariate data: histogram
#
x = state.x77[ , 2] # 50 average state incomes in 1977
x # display x
hist(x) # histogram
hist(x, breaks = 4) # histogram using 4 cells
hist(x, probability = TRUE) # histogram so it sums to 1
y = quakes$depth # 1000 earthquake depths
hist(y) # histogram of 1000 earthquake depths
hist(y, breaks = 7) # histogram using 7 cells
hist(y, seq(0, 700, by = 70)) # histogram using 10 cells
#
# univariate data: empirical cumulative distribution function
#
ecdf(x) # empirical cumulative distn function
plot.ecdf(x) # associated plot (income data)
plot.ecdf(x, verticals = T, pch = "") # add vertical lines and no dots
plot.ecdf(y, verticals = T, pch = "") # ecdf plot of 1000 earthquake depths
#
# qqplot
#
qqnorm(x) # qq plot for the state income data
qqline(x, col = 2) # col = 2 for the red reference line
qqnorm(y) # qq plot for the earthquake depths
qqline(y, col = "red") # red reference line
#
# box plots
#
boxplot(x) # box plot of the state income data
boxplot(count ~ spray, data = InsectSprays) # classify count data by spray
#
# multivariate data
#
# two-dimensional data: scatterplot --- plot(x, y)
#
plot(quakes$long, quakes$lat) # longitude vs. latitude of epicenters
symbols(quakes$long, quakes$lat, circles = 10 ^ quakes$mag) # adjust for mag.
#
# three-dimensional data: pairs(x)
#
pairs(trees) # pairwise Girth, Height, & Volume
stars(trees) # star plot for tree data
stars(trees, draw.segments = TRUE) # segment plot for tree data
#
# three dimensional plots
#
contour(crimtab) # contour plot of criminal data
image(crimtab) # image plot of criminal data
persp(crimtab) # perspective plot of criminal data
#
# categorical data: pie charts
#
# pie.sales is not in all versions of R
#
pie.sales = c(0.12, 0.30, 0.26, 0.16, 0.04, 0.12)
names(pie.sales) = c("Blueberry", "Cherry", "Apple", "Boston Creme",
"Other", "Vanilla Creme")
pie.sales # proportion of pie sales
pie(pie.sales, col = c("blue", "red", "green", "wheat", "orange", "white"))
dotchart(pie.sales, xlim = c(0, 0.3)) # force axis to include zero
barplot(pie.sales, col = c("blue", "red", "green", "wheat", "orange", "white"))
barplot(VADeaths, beside = T, legend = T,
main = "Virginia Death Rates per 1000 in 1940")
#
# time series plots
#
ts.plot(AirPassengers) # international airline passengers
ts.plot(presidents) # presidential approval ratings