Compute cross-tabulation statistics
Computes statistics of a 2-dimensional matrix using augment.htest
from broom.
stat_cross( mapping = NULL, data = NULL, geom = "point", position = "identity", ..., na.rm = TRUE, show.legend = NA, inherit.aes = TRUE, keep.zero.cells = FALSE )
mapping |
Set of aesthetic mappings created by |
data |
The data to be displayed in this layer. There are three options: If A A |
geom |
Override the default connection between |
position |
Position adjustment, either as a string, or the result of a call to a position adjustment function. |
... |
Other arguments passed on to |
na.rm |
If |
show.legend |
logical. Should this layer be included in the legends?
|
inherit.aes |
If |
keep.zero.cells |
If |
stat_prop
requires the x and the y aesthetics.
number of observations in x,y
proportion of total
row proportion
column proportion
expected count under the null hypothesis
Pearson's residual
standardized residual
# Small function to display plots only if it's interactive p_ <- GGally::print_if_interactive d <- as.data.frame(Titanic) # plot number of observations p_(ggplot(d) + aes(x = Class, y = Survived, weight = Freq, size = after_stat(observed)) + stat_cross() + scale_size_area(max_size = 20)) # custom shape and fill colour based on chi-squared residuals p_(ggplot(d) + aes( x = Class, y = Survived, weight = Freq, size = after_stat(observed), fill = after_stat(std.resid) ) + stat_cross(shape = 22) + scale_fill_steps2(breaks = c(-3, -2, 2, 3), show.limits = TRUE) + scale_size_area(max_size = 20)) # plotting the number of observations as a table p_(ggplot(d) + aes( x = Class, y = Survived, weight = Freq, label = after_stat(observed) ) + geom_text(stat = "cross")) # Row proportions with standardized residuals p_(ggplot(d) + aes( x = Class, y = Survived, weight = Freq, label = scales::percent(after_stat(row.prop)), size = NULL, fill = after_stat(std.resid) ) + stat_cross(shape = 22, size = 30) + geom_text(stat = "cross") + scale_fill_steps2(breaks = c(-3, -2, 2, 3), show.limits = TRUE) + facet_grid(Sex ~ .) + labs(fill = "Standardized residuals") + theme_minimal()) # can work with continuous or character variables data(tips, package = "reshape") p_(ggplot(tips) + aes(x = tip, y = as.character(day), size = after_stat(observed)) + stat_cross(alpha = .1, color = "blue") + scale_size_area(max_size = 12))
Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.