Ch01 Setting the Scene

Ch1 Setting the scene

1.1 Graphics in action
1.3 What is Graphical Data Analysis (GDA)?
1.4 Using this book, the R code in it, and the books website

 

Graphics in action | 1

library(ggplot2)
data(SpeedSki, package = "GDAdata")
ggplot(SpeedSki, aes(x=Speed, fill=Sex)) + xlim(160, 220) +
       geom_histogram(binwidth=2.5) + xlab("Speed (km/hr)") +
       facet_wrap(~Sex, ncol=1) + ylab("") +
       theme(legend.position="none")

 

3

ggplot(SpeedSki, aes(Speed, fill=Sex)) +
       geom_histogram(binwidth=2.5) + xlab("Speed (km/hr)") +
       ylab("") + facet_grid(Sex~Event) +
       theme(legend.position="none")

 

What is Graphical Data Analysis (GDA)? | 6

ggplot(iris, aes(Petal.Length)) + geom_histogram()

 

7

library(ggthemes)
ggplot(iris, aes(Petal.Length, Petal.Width, color=Species)) +
       geom_point() + theme(legend.position="bottom") +
       scale_colour_colorblind()

 

8

library(gridExtra)
ucba <- as.data.frame(UCBAdmissions)
a <- ggplot(ucba, aes(Dept)) + geom_bar(aes(weight=Freq))
b <- ggplot(ucba, aes(Gender)) + geom_bar(aes(weight=Freq))
c <- ggplot(ucba, aes(Admit)) + geom_bar(aes(weight=Freq))
grid.arrange(a, b, c, nrow=1, widths=c(7,3,3))

 

9

library(vcd)
ucb <- data.frame(UCBAdmissions)
ucb <- within(ucb, Accept <- 
              factor(Admit, levels=c("Rejected", "Admitted")))
doubledecker(xtabs(Freq~ Dept + Gender + Accept, data = ucb),
             gp = gpar(fill = c("grey90", "steelblue")))

 

10

data(Pima.tr2, package="MASS")
h1 <- ggplot(Pima.tr2, aes(glu)) + geom_histogram()
h2 <- ggplot(Pima.tr2, aes(bp)) + geom_histogram()
h3 <- ggplot(Pima.tr2, aes(skin)) + geom_histogram()
h4 <- ggplot(Pima.tr2, aes(bmi)) + geom_histogram()
h5 <- ggplot(Pima.tr2, aes(ped)) + geom_histogram()
h6 <- ggplot(Pima.tr2, aes(age)) + geom_histogram()
grid.arrange(h1, h2, h3, h4, h5, h6, nrow=2)

 

11

library(dplyr)
PimaV <- select(Pima.tr2, glu:age)
par(mar=c(3.1, 4.1, 1.1, 2.1))
boxplot(scale(PimaV), pch=16, outcol="red")

 

12

library(GGally)
ggpairs(PimaV, diag=list(continuous=’density’),
axisLabels=’show’)