library(dplyr)
## 
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
## 
##     filter, lag
## The following objects are masked from 'package:base':
## 
##     intersect, setdiff, setequal, union
PY110 <- read.csv("~/social_survey/PY110.csv")
n <- 3367
data <- data.frame(
  ZQ30A = sample(1:5, n, replace = TRUE),
  ZQ30D = sample(1:5, n, replace = TRUE)
)

data <- PY110 %>%
  mutate(Job_Satisfaction_Category = case_when(
    ZQ30A %in% 1:2 ~ "High",
    ZQ30A %in% 3 ~ "Middle",
    ZQ30A %in% 4:5 ~ "Low",
    TRUE ~ NA_character_
  ),
  Life_Satisfaction_Category = case_when(
    ZQ30D %in% 1:2 ~ "High",
    ZQ30D %in% 3 ~ "Middle",
    ZQ30D %in% 4:5 ~ "Low",
    TRUE ~ NA_character_
  ))

cross_tab <- table(data$Job_Satisfaction_Category, data$Life_Satisfaction_Category)

mosaicplot(cross_tab, color = TRUE, main = "Mosaic Plot")