Ch12 Ensemble Graphics and Case Studies

12.1 Introduction
12.3 Combining different views—a case study example

 

Introduction| 244

data(coffee, package="pgmm")
coffee <- within(coffee, Type <- ifelse(Variety==1,
                              "Arabica", "Robusta"))
names(coffee) <- abbreviate(names(coffee), 8)
a <- ggplot(coffee, aes(x=Type)) + geom_bar(aes(fill=Type)) +
            scale_fill_manual(values = c("grey70", "red")) +
            guides(fill=FALSE) + ylab("")
b <- ggplot(coffee, aes(x=Fat, y=Caffine, colour=Type)) +
            geom_point(size=3) +
            scale_colour_manual(values = c("grey70", "red"))
c <- ggparcoord(coffee[order(coffee$Type),], columns=3:14,
                groupColumn="Type", scale="uniminmax",
                mapping = aes(size = 1)) +
                xlab("") +  ylab("") +
                theme(legend.position = "none") +
                scale_colour_manual(values = c("grey","red")) +
                theme(axis.ticks.y = element_blank(),
                axis.text.y = element_blank())
grid.arrange(arrangeGrob(a, b, ncol=2, widths=c(1,2)),
                         c, nrow=2)

 

Combining different views—a case study example | 249

data(Fertility, package="AER")
p0 <- ggplot(Fertility) + geom_bar(binwidth=1) + ylab("")
p1 <- p0 + aes(x=age)
p2 <- p0 + aes(x=work) + xlab("Weeks worked in 1979")
k <- ggplot(Fertility) + geom_bar() + ylab("") + ylim(0,250000)
p3 <- k + aes(x=morekids) + xlab("has more children")
p4 <- k + aes(x=gender1) + xlab("first child")
p5 <- k + aes(x=gender2) + xlab("second child")
p6 <- k + aes(x=afam) + xlab("African-American")
p7 <- k + aes(x=hispanic) + xlab("Hispanic")
p8 <- k + aes(x=other) + xlab("other race")
grid.arrange(arrangeGrob(p1, p2, ncol=2, widths=c(3,3)),
           arrangeGrob(p3, p4, p5, p6, p7, p8, ncol=6),
           nrow=2, heights=c(1.25,1))

 

250

doubledecker(morekids ~ age, data = Fertility,
             gp = gpar(fill = c("grey90", "green")),
             spacing=spacing_equal(0))

 

doubledecker(morekids ~ gender1 + gender2, data = Fertility,
             gp = gpar(fill = c("grey90", "green")))

 

251

doubledecker(morekids ~ age + gender1 + gender2,
             data = Fertility,
             gp = gpar(fill = c("grey90", "green")),
             spacing=spacing_dimequal(c(0.1,0,0,0)))