Plot categorical data in R, mosaic, and association plots can graphically illustrate the association between two or more categorical variables (such as those data handled by contingency tables and log-linear modeling).

We will use a data set from Young and Winn, in which encountered eels were cross-classified according to species and location, to provide graphical summaries for categorical data.

How to Use Gather Function in R?-tidyr Part2 (datasciencetut.com)

## Plot categorical data in R

Location<-c("A","B","C","D") Species<-c("q1","q1","q2","q2") Count<-c(12,13,14,12) data<-data.frame(Location,Species,Count) data

Location Species Count 1 A q1 12 2 B q1 13 3 C q2 14 4 D q2 12

xtabs(Count~Location+Species,data)

Species Location q1 q2 A 12 0 B 13 0 C 0 14 D 0 12

## Mosiac Plot in R

Each cross-classification is represented by a mosaic of rectangles in the mosaic plot, whose sizes are proportional to the observed frequencies.

In addition, the rectangles can be shaded to reflect the magnitudes and significance of the residuals, thereby providing an indication of which cross-classifications contribute to a lack of independence.

Top Data Science Applications You Should Know 2023 (datasciencetut.com)

library(vcd) strucplot(data1,gp=shading_max)

## Association Plot in R

Cross-classifications are shown in association plots as rectangles with areas that correspond to the raw residuals and heights that represent the relative sizes and polarities of person residuals.

Similar to mosaic plots, residual magnitude, and significance can be reflected by shading.

Top 10 Data Visualisation Tools (datasciencetut.com)

assoc(data1,gp=shading_max)