我有以下示例:
library(tidyverse)
library(ggalluvial)
data <- tibble(id = paste0("S", 1:20),
class_1 = c(rep("A", 10), rep("B", 10)),
class_2 = c(rep("A", 8), rep("B", 8), rep("A", 4)))
data_pvt <- data %>%
pivot_longer(starts_with("class"), names_to = "class_type", values_to = "class_label") %>%
mutate(class_type = factor(class_type),
class_label = factor(class_label))
ggplot(data_pvt, aes(x = fct_rev(class_type), stratum = class_label, alluvium = id,
label = class_label)) +
geom_flow(aes(fill = class_label), stat = "alluvium",
lode.guidance = "frontback") +
geom_stratum(aes(fill = class_label)) +
scale_x_discrete(expand = c(0.1, 0)) +
labs(x = "Class system", y = "n") +
coord_flip() +
theme_minimal()
由reprex 包于 2022-02-18 创建(v2.0.1)
我想从顶层 ( ) 而不是底层 ( )geom_flow
中获取fill
颜色。我可以不在一开始就做到这一点,然后在底部,而我希望它在顶部。class_1
class_2
fct_rev(class_type)
class_1
有任何想法吗?我可以使用ggalluvium
或的其他功能ggforce
,但我想保留将层着色为 的选项class_label
。