Graphics Reference
In-Depth Information
Creating a Mosaic Plot
Problem
You want to make a mosaic plot to visualize a contingency table.
Solution
Use the
mosaic()
function from the vcd package. For this example we'll use the
USBAdmis-
sions
data set, which is a contingency table with three dimensions. We'll first take a look at the
data in a few different ways:
UCBAdmissions
, , Dept
=
A
Gender
Admit Male Female
Admitted
512
89
Rejected
313
19
...
[four other Depts]
, , Dept
=
F
Gender
Admit Male Female
Admitted
22
24
Rejected
351
317
# Print a "flat" contingency table
ftable(UCBAdmissions)
Dept A B C D E
F
Admit Gender
Admitted Male
512 353 120 138 53 22
Female
89 17 202 131 94 24
Rejected Male
313 207 205 279 138 351
Female
19
8 391 244 299 317
dimnames(UCBAdmissions)
$Admit
[
1
]
"Admitted" "Rejected"