# Basic usage with 2-way table - shade by residuals from independence
data(HairEyeColor)
HEC <- margin.table(HairEyeColor, 1:2) # 2-way: Hair x Eye
color_table(HEC)
# Shade by frequencies instead (no message printed)
color_table(HEC, shade = "freq")
# 3-way table - using a formula to specify layout (col_vars ~ row_vars):
# Eye is the single column variable, Hair and Sex are row variables shown
# as separate stub columns
color_table(HairEyeColor, formula = Eye ~ Hair + Sex)
# Display residual values in cells instead of frequencies
color_table(HEC, values = "residuals")
# Multiple column variables - shown using nested spanner headings instead
# of concatenated column labels
data(Titanic)
color_table(Titanic, formula = Class + Sex ~ Survived)
# Multiple row AND column variables together: column spanners (Class, Sex)
# combined with row-variable stub columns (Age, Survived)
color_table(Titanic, formula = Class + Sex ~ Age + Survived, legend = TRUE)
if (FALSE) {
# From a data.frame in frequency form (2-way)
hec_df <- as.data.frame(HEC)
color_table(hec_df)
# Save table as an image file
color_table(HEC, filename = "hair_eye_table.png")
}
Run the code above in your browser using DataLab