我正在尝试创建一个具有5条的条形图,每个条形图代表一个不同的变量。每个变量都是具有相同数量的分类级别的因子(4)。我希望将它们堆叠起来,以便“填充”为水平(即1、2、3或4)。每个条形图的总和应为100%,并且条形图中每个堆叠级别的比例应为100%。
这是我第一次尝试reprex,希望它能起作用。
df <- structure(list(icap_1 = structure(c(1L, 2L, 2L, 2L, 1L, 2L, 2L,
2L, 3L, 4L), .Label = c("1", "2", "3", "4"), class = "factor"),
icap_2 = structure(c(2L, 1L, 1L, 2L, 1L, 2L, 2L, 1L, 2L,
2L), .Label = c("1", "2", "3", "4"), class = "factor"), icap_3 = structure(c(3L,
2L, 2L, 2L, 2L, 3L, 2L, 2L, 3L, 2L), .Label = c("1", "2",
"3", "4"), class = "factor"), icap_4 = structure(c(2L, 2L,
2L, 2L, 2L, 3L, 2L, 2L, 3L, 2L), .Label = c("1", "2", "3",
"4"), class = "factor"), icap_5 = structure(c(2L, 1L, 2L,
2L, 1L, 2L, 1L, 1L, 3L, 2L), .Label = c("1", "2", "3", "4"
), class = "factor")), row.names = c(NA, 10L), class = "data.frame")
实质上,这只是为了可视化每个变量的分布。我看过其他程序的示例,但似乎无法在线找到示例。任何提示都将不胜感激!