For a cross-tabulation, plots the number of observations by using rectangles with proportional areas, and the phi measures of association between the categories with a diverging gradient of colour, using ggplot2.

ggassoc_crosstab(data, mapping, max.phi=.8, sort="none", 
axes.labs=TRUE, ticks.labs=TRUE, text.size=3)



dataset to use for plot


aesthetic being used. It must specify x and y.


numeric value, specifying the lower and upper limit of the scale for the color gradient filling the rectangles, i.e. for the phi measures of association. It corresponds to the maximum absolute value of phi one wants to represent in the plot.


character. If "both", rows and columns are sorted according to the first factor of a correspondence analysis of the contingency table. If "x", only rows are sorted. If "y", only columns are sorted. If "none" (default), no sorting is done.


Whether to display the labels of the axes, i.e. the names of x and y. Default is TRUE.


Whether to display the labels of the categories of x and y. Default is TRUE.


Size of the association measure. If NULL, the text is not added to the plot.


The phi measure of association measures how much each combination of categories of x and y is over/under-represented.

Cramer's V measure of global association between x and y is displayed in upper-left corner of the plot.

This function can be used as a high-level plot with ggduo and ggpairs functions of the GGally package.


a ggplot object


Nicolas Robette

See also


data(Taste) ggassoc_crosstab(data=Taste, mapping=ggplot2::aes(x=Age, y=Classical))
#> Warning: Removed 1 rows containing missing values (geom_tile).