ggalluvial 中的其他颜色透明度类别

Additional colour transparency categories in ggalluvial

我正在尝试重现流动性流程图,但我真的不知道如何根据 axis2 类别向填充参数添加额外的颜色透明度。或者这是否是解决这个问题的方法!

如有任何建议,将不胜感激,谢谢!

我想要达到的目标: Mobility flow diagram

我有: My mobility flow diagram example

我的移动流程图示例代码:

library(ggplot2)
library(ggalluvial)

oclass <- c("1st", "1st", "1st", "2nd", "2nd", "2nd", "3rd", "3rd", "3rd")
dclass <- c("1st", "2nd", "3rd", "1st", "2nd", "3rd", "1st", "2nd", "3rd")
Freq  <- c(700, 200, 100, 200, 600, 200, 50, 250, 700)

odclass <- data.frame(oclass, dclass, Freq)

ggplot(odclass, aes(y = Freq, axis1 = oclass, axis2 = dclass)) + 
       geom_alluvium(aes(fill = oclass), width = 1/6, reverse = TRUE) +
       geom_stratum(width = 1/6, alpha = 0, reverse = TRUE, color = "black") +
       geom_text(aes(label = after_stat(stratum)), stat = "stratum", reverse = TRUE, size=5) +
       scale_fill_manual(values = c("darkcyan", "darkgoldenrod2", "mediumorchid")) +
       theme_minimal() +
       theme(axis.title.y = element_blank(), axis.text.y= element_blank(), legend.position = "none", 
             plot.title = element_text(hjust=0.5, size=18), axis.text.x = element_blank())

添加您想要的内容非常容易。您只需要将 alpha 映射到 dclass,然后使用 scale_alpha_manual().

设置您想要的值
library(tidyverse)
library(ggalluvial)
#> Warning: package 'ggalluvial' was built under R version 4.0.4

oclass <- c("1st", "1st", "1st", "2nd", "2nd", "2nd", "3rd", "3rd", "3rd")
dclass <- c("1st", "2nd", "3rd", "1st", "2nd", "3rd", "1st", "2nd", "3rd")
Freq  <- c(700, 200, 100, 200, 600, 200, 50, 250, 700)

odclass <- data.frame(oclass, dclass, Freq)

ggplot(odclass, aes(y = Freq, axis1 = oclass, axis2 = dclass)) + 
  geom_alluvium(aes(fill = oclass, alpha = dclass), width = 1/6, reverse = TRUE) +
  geom_stratum(width = 1/6, alpha = 0, reverse = TRUE, color = "black") +
  geom_text(aes(label = after_stat(stratum)), stat = "stratum", reverse = TRUE, size=5) +
  scale_fill_manual(values = c("darkcyan", "darkgoldenrod2", "mediumorchid")) +
  scale_alpha_manual(values = c(0.9, 0.7, 0.5)) +
  theme_minimal() +
  theme(axis.title.y = element_blank(), axis.text.y= element_blank(), legend.position = "none", 
        plot.title = element_text(hjust=0.5, size=18), axis.text.x = element_blank())
#> Warning in to_lodes_form(data = data, axes = axis_ind, discern =
#> params$discern): Some strata appear at multiple axes.
#> Warning in to_lodes_form(data = data, axes = axis_ind, discern =
#> params$discern): Some strata appear at multiple axes.

#> Warning in to_lodes_form(data = data, axes = axis_ind, discern =
#> params$discern): Some strata appear at multiple axes.

reprex package (v1.0.0)

于 2021 年 3 月 29 日创建