I have the following code:
set.seed(123)
CIS_data_5 <- data.frame(
CIS$P20,
CIS$P3
)
CIS$P3 <- factor(CIS$P3, labels = c("Mejor", "(NO LEER) Igual", "Peor", "N.S.", "N.C."))
n <- as.numeric(c(CIS$P20))
P20 <- sample(n, 2787, replace = TRUE, prob = NULL)
P20labs <- c("16-29", "30-44", "45-64", ">65", "N.C.")
cut_points <- c(16, 30, 45, 65, Inf)
i <- findInterval(P20, cut_points)
P20_fac <- P20labs[i]
P20_fac[is.na(P20)] <- P20labs[length(P20labs)]
P20_fac <- factor(P20_fac, levels = P20labs)
where P3 has 5 categories, indicating the socioeconomic perception of a sample of Spanish population, and P20_fac has 5 other categories that indicate the age of the respondents.
My desired outcome would be to have 5 joint graphs, in which the socioeconomic situation (P3) is reflected according to the age of the respondents (P20_fac).
I have been stuck on thinking how I can possibly represent this graphically, and after many an hour spent, I have completely run out of ideas (though I think that it can somehow be done by means of facet_wrap() or facet_grid()).
Any help would be much appreciated!
Many thanks in advance!