如何更改每个节/节点的高度
Sankey diagram
? 我想创建如下图1所示的内容,其中“性别”部分较小,然后“原因”部分较大,然后“年龄”部分较小:
代码:
library(ggplot2)
library(ggalluvial)
library(RColorBrewer)
dfs <- dftest[ , c("Hospital", "Paciente", "Terapia", "Unit")]
alpha <- 1
getPalette <- colorRampPalette(brewer.pal(12, "Set3"))
colourCount <- length(unique(dfs$Hospital))
ggplot(dfs,
aes(axis1 = Hospital, axis2 = Paciente, axis3=Terapia)) +
geom_alluvium(aes(fill = Hospital),
width = 1/12, alpha = alpha, knot.pos = 0.5) +
geom_stratum(width = 1/20) +
scale_x_continuous(breaks = 1:3, labels = c("Hospital", "Patient", "Therapy")) +
scale_fill_manual(values = getPalette(colourCount)) +
ggtitle("Teste") +
theme_minimal() +
theme( legend.position = "none", panel.grid.major = element_blank(),
panel.grid.minor = element_blank(), axis.text.y = element_blank(),
axis.text.x = element_text(size = 12, face = "bold"))
我有3个节段/节点,中心(24个独特),病人(750个独特)和治疗(10个独特)。所以,我想我可以创建一个类似于图1的sankey图。在下面你可以找到
dput(dfs)
对于一个虚构的数据集,因为我的数据集太大(750人)不能包含在这里。
dput(dfs)
structure(list(Hospital = structure(c(1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 3L, 3L, 3L, 3L, 3L, 4L, 4L, 4L,
4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L,
4L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L), .Label = c("1",
"2", "3", "4", "5"), class = "factor"), Paciente = structure(c(1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 3L, 3L,
3L, 3L, 3L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 5L, 5L, 5L,
5L, 5L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L,
6L, 6L, 6L, 6L, 6L, 6L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L
), .Label = c("21", "22", "23", "24", "25", "26", "27"), class = "factor"),
Terapia = structure(c(2L, 2L, 2L, 2L, 2L, 3L, 3L, 3L, 3L,
3L, 2L, 2L, 2L, 2L, 2L, 4L, 4L, 4L, 4L, 4L, 1L, 1L, 1L, 1L,
1L, 3L, 3L, 3L, 3L, 3L, 2L, 2L, 2L, 2L, 2L, 3L, 3L, 3L, 3L,
3L, 2L, 2L, 2L, 2L, 2L, 4L, 4L, 4L, 4L, 4L, 1L, 1L, 1L, 1L,
1L, 2L, 2L, 2L, 2L, 2L, 3L, 3L, 3L, 3L, 3L), .Label = c("Adalimumab",
"Etanercept", "Infliximab", "Rituximab"), class = "factor"),
Unit = c(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1)), class = "data.frame", row.names = c(NA,
-65L))
有人能给我建议吗?