尝试以下方法。
library(dplyr)
data <- tibble(group = factor(c(rep("A", 10), rep("B", 10), rep("C", 10), rep("D", 10)), levels = c("A", "B", "C", "D")),
state = c(rep(c("Not Started", "Just Beginning",
"25% Complete", "40% Complete", "Halfway Done",
"75% Complete", "Mostly Done", "Completed",
"Follow Up", "Final Follow Up"), 4)),
count = c(100, 5, 4, 445, 67, 44, 25, 877, 240, 353,
48, 51, 48, 40, 141, 34, 50, 45, 34, 35,
140, 5, 8, 0, 17, 42, 0, 5, 3, 75,
477, 20, 59, 13, 1065, 1, 50, 353, 73, 104))
data$state_factor <- factor(data$state, levels = c("Not Started", "Just Beginning",
"25% Complete", "40% Complete", "Halfway Done",
"75% Complete", "Mostly Done", "Completed",
"Follow Up", "Final Follow Up"))
head(data, 20)