library(vcdExtra)

This example illustrates some alternatives to barplots for contingency tables

what’s wrong with barplots?

HE <- margin.table(HairEyeColor, 2:1)  # as in Table 4.2
barplot(HE, xlab="Hair color", ylab="Frequency")

why spineplots are better

Show this both ways, with hair and eye color on the horizontal axis

spineplot(HE)

spineplot(t(HE))

tile plots are also useful

tile(HE)

tile(HE, tile_type="width")

tile(HE, tile_type="height")

many other variations in fluctile()

The extracat package is no longer on CRAN

# if (!require(extracat)) devtools::install_github("heike/extracat")
# library(extracat)
# fluctile(HE)
IycgLS0tDQojJyB0aXRsZTogIlR3by13YXkgdGFibGVzOiBiYXJwbG90cywgc3BpbmVwbG90cyBhbmQgdGlsZSBwbG90cyINCiMnIGF1dGhvcjogIk1pY2hhZWwgRnJpZW5kbHkiDQojJyBkYXRlOiAiYHIgZm9ybWF0KFN5cy5EYXRlKCkpYCINCiMnIG91dHB1dDoNCiMnICAgaHRtbF9kb2N1bWVudDoNCiMnICAgICB0aGVtZTogcmVhZGFibGUNCiMnICAgICBjb2RlX2Rvd25sb2FkOiB0cnVlDQojJyAtLS0NCg0KbGlicmFyeSh2Y2RFeHRyYSkNCg0KIysgZWNobz1GQUxTRQ0Ka25pdHI6Om9wdHNfY2h1bmskc2V0KA0KICB3YXJuaW5nID0gRkFMU0UsICAgIyBhdm9pZCB3YXJuaW5ncyBhbmQgbWVzc2FnZXMgaW4gdGhlIG91dHB1dA0KICBtZXNzYWdlID0gRkFMU0UNCikNCg0KIycgVGhpcyBleGFtcGxlIGlsbHVzdHJhdGVzIHNvbWUgYWx0ZXJuYXRpdmVzIHRvIGJhcnBsb3RzIGZvciBjb250aW5nZW5jeSB0YWJsZXMNCiMnIA0KIycgIyMgd2hhdCdzIHdyb25nIHdpdGggYmFycGxvdHM/DQpIRSA8LSBtYXJnaW4udGFibGUoSGFpckV5ZUNvbG9yLCAyOjEpICAjIGFzIGluIFRhYmxlIDQuMg0KYmFycGxvdChIRSwgeGxhYj0iSGFpciBjb2xvciIsIHlsYWI9IkZy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