R语言ggplot中alluvial plot透明度调整无效的解决方法
解决ggalluvial桑基图颜色透明问题
你的代码里透明度调整无效的核心原因是把alpha放在了aes()映射内部,这会让ggplot将其视为数据变量而非图层参数,导致设置不生效。只需要把alpha从aes()中移出,作为geom_alluvium的独立参数设置即可。
修改后的完整代码:
library(dplyr) library(ggplot2) library("ggalluvial") library("viridis") plot = ggplot(df, aes(y = Total_Publications, axis1 = Method_Group, axis2 = Topic)) + # 关键改动:将alpha从aes()中移出,作为geom_alluvium的参数 geom_alluvium(aes(fill = Topic), width = 1/5, alpha = 1) + scale_fill_viridis(discrete=TRUE, alpha = 1) + geom_stratum(width = 1/5, alpha = 0, reverse = TRUE, color = "black") + geom_text(stat = "stratum", aes(label = after_stat(stratum)), size= 4.5) + scale_x_discrete(limits = c("Ecological Topic", "Ecological Theme"), expand = c(.05, .05)) + 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())
补充说明:如果需要调整透明度程度,直接修改geom_alluvium里的alpha数值即可(比如alpha=0.8为半透明,alpha=1为完全不透明)。
内容的提问来源于stack exchange,提问作者Kristen Cyr
相关产品推荐
相关产品推荐

