I have a dataset from which I am trying to visualize a contingency table of ETH (ethnicity coded as 0 or 1) and SEX (sex coded as 0 or 1).
This is what my dataset looks like:
This is my coding in R:
library(readxl)
library(corrplot)
#Dataset
Datavisit1<- read_excel("~/Downloads/Datavisit1.xlsx")
View(Datavisit1)
#Contingency Table
ethsextable<- table(Datavisit1$ETH, Datavisit1$SEX, dnn = c("ETH", "SEX"))
ethsextable
ethsextablechi<- chisq.test(ethsextable)
ethsextablechi
corrplot(ethsextablechi$residuals, is.corr = FALSE)
This is the plot I see:
How do I add the labels of ETH and SEX to this corrplot of the residuals? Right now I am confused which one is ETH and which one is SEX.
How do I put the legend that has the Pearson residuals numbers slightly to the right? At the moment the numbers are above the colour bar and hard to see.
Is the visualization of the chi-squared residuals of 2x2 or 2x3 contingency tables better through corrplots or through mosaic plots? Which is the more standard way of visual representation?
Thank you!
I have a function in a package that I wrote for a class that's on CRAN called
uwo4419
that has a function in it to plot standardized residuals from a chi-squared test.This would seem to answer all of your questions. I feel like a heatmap plot is a good way to visualize standardized residuals.