mosaicplot

# Step 1: Load the necessary library
library(vcd)

# Step 2: Create a contingency table (replace 'data' with your actual dataset)
data <- as.table(matrix(c(10, 20, 30, 40), nrow = 2))
colnames(data) <- c("Group A", "Group B")
rownames(data) <- c("Category 1", "Category 2")

# Step 3: Create a mosaic plot
mosaicplot(data, main = "Mosaic Plot Example", color = c("lightblue", "lightgreen"))

# Optional Step 4: Customize the mosaic plot further (e.g., add labels or change colors)