r - 更改 Sankey 中节点的位置
问题描述
如何垂直更改 Sankey 图中节点的位置(y 轴),使其看起来像下面带有红色节点的示例:
我的数据集:
> dput(final_df_2)
structure(list(individual_id = c(21L, 21L, 22L, 23L, 24L, 24L,
24L, 25L, 26L, 26L, 26L, 26L, 26L, 26L, 26L, 27L, 27L, 27L, 27L
), number = c(1L, 2L, 1L, 1L, 1L, 2L, 3L, 1L, 1L, 2L, 3L, 4L,
5L, 6L, 7L, 1L, 2L, 3L, 4L), treatment = structure(c(5L, 3L,
2L, 4L, 1L, 5L, 3L, 2L, 3L, 5L, 2L, 5L, 4L, 5L, 1L, 2L, 5L, 5L,
3L), .Label = c("Adalimumab", "Etanercept", "Infliximab", "Rituximab",
"(Missing)"), class = "factor")), row.names = c(1L, 2L, 8L, 14L,
20L, 26L, 27L, 33L, 39L, 45L, 46L, 52L, 53L, 59L, 60L, 66L, 72L,
73L, 74L), class = "data.frame")
我的代码:
install.packages("alluvial")
library(alluvial)
ggplot(final_df_2 , aes(x = number, stratum = treatment, alluvium = individual_id, fill = treatment, label = treatment)) +
scale_fill_brewer(type = "qual", palette = "Set3") +
geom_flow(width = 1/10) +
geom_stratum(width = 1/10, colour = NA) +
scale_x_continuous(breaks = 1:7, labels = c("1st Therapy", "2nd Therapy", "3rd Therapy", "4th Therapy", "5th Therapy", "6th Therapy", "7th Therapy"))+
ggtitle("Treatment across observation period")+
theme_minimal()+
theme( panel.grid.major = element_blank(),
panel.grid.minor = element_blank(), axis.text.y = element_blank())
解决方案
推荐阅读
- javascript - 如果数据库中已存在用户,如何使用 Math.random() 将其排除在随机之外
- python - 'RawReactionActionEvent' 对象没有属性 'guild'
- python - discord.py 1.3.2:如何在用户按下表情符号反应时检测和执行代码
- python - 我想知道这个python程序的工作过程
- php - 为什么我不能在 WordPress functions.php 中将多个 Google 字体排入队列?
- python-3.x - 用python解决耦合PDE
- angular - Angular $localize 使用动态翻译 ID
- r - 如何在向量中使用 onehot 编码和 dummyVars?
- vuejs2 - 为什么使用 vuetable-2 组件时出现未知的自定义元素错误?
- vue.js - vue会在客户端下载所有页面吗?