This function plots a cell-by-cell chart (chiplot) on a given matrix of standardized residuals (Z) from a chi square test.
chiplot(
zmat,
method = "square",
type = "full",
ggtheme = ggplot2::theme_classic(),
title = "",
show.legend = TRUE,
legend.title = "Z",
colors = c("dodgerblue3", "white", "firebrick2"),
outline.color = "white",
lab = FALSE,
lab_col = "black",
lab_size = 4,
p.mat = NULL,
z.crit = NULL,
sig.level = 0.05,
insig = pch,
pch = 4,
pch.col = "black",
pch.cex = 5,
tl.cex = 12,
tl.col = "black",
tl.srt = 45,
digits = 2,
as.is = FALSE
)This function returns the chi square plot of standardized residuals for categories of var1 by var2 in data frame df, all of which are extracted from the chi square test.
a matrix of standardized residuals, extracted from the chi square test, to visualize.
the type of visualization used in plot (default set to "square").
the section of the plot that will be displayed (default set to "full").
ggplot2 function to set the theme of the plot (default set to ggplot2::theme_classic()).
title of the plot, extracted from the chi square test.
logical (default set to TRUE), to display legend on plot.
title of the legend (default set to "Z").
a vector of 3 colors for negative, zero, and positive residuals.
the outline color of the square (default set to "white").
logical (default set to FALSE, but set to TRUE if extracted from chi square test), to display standardized residual (Z) value (and significance stars) on for each cell comparison on the plot.
color of text displayed in each cell comparison for standardized residual (Z) value when lab = TRUE (default set to "black").
size of text displayed in each cell comparison for standardized residual (Z) value when lab = TRUE (default set to 4).
a matrix of p-values for each standardized residual (Z) value comparison, extracted from chi square test.
the critical Z value for the comparison of standardized residuals (Z), extracted from the chi square test.
the alpha value used to assess significance (default set to 0.05).
glyphs to add on non-significant standardized residual (Z) values (default set to "pch").
glyphs added to non-significant standardized residual (Z) values (default set to 4).
color of pch glyphs (default set to "black").
size of pch glyphs (default set to 5).
size of text label for each category name for both variables (default set to 12).
color of text label for each category name for both variables (default set to "black").
string rotation of text label for each category name for the variable on the x-axis (default set to 45).
the number of decimal digits to be displayed in the plot (default set to 2, but set to 3 if extracted from chi square test).
determines how to handle dimnames, either left as strings (if set to TRUE), or converted (default set to FALSE).
data <- mtcars
x2 <- chi.sq(data,vs,am,post=TRUE)
chiplot(zmat = x2$z_mat,p.mat = x2$p_z_mat,z.crit = round(x2$z_crit, 4),
outline.color = "white",lab = TRUE,digits = 3)
Run the code above in your browser using DataLab