问题 Suppose I have data with both an ordinal variable and a categorical variable: set.seed(35) df <- data.frame(Class = factor(rep(c(1,2),times = 80), labels = c("Math","Science")), StudyTime = factor(sort(sample(1:4, 16, prob = c(0.25,0.3,0.3,0.15), replace = TRUE)),labels = c("<5","5-10","10-20",">20")), Nerd = factor(sapply(rep(c(0.1,0.3,0.5,0.8),c(30,50,50,30)), function(x)sample(c("Nerd","NotNerd"),size = 1, prob = c(x,1-x))),levels = c("NotNerd","Nerd"))) One could use ggplot and geom_bar