r - 如何在桑基图中垂直改变节点的位置
问题描述
如何垂直更改 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")
我的代码:
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())
我很感激这方面的任何帮助。提前致谢。
解决方案
你试过了吗
var options = {
width: 900,
sankey: { node: { nodePadding: 80 } },
};
推荐阅读
- vb.net - 如何从表单调用类函数?
- docker - .net core 3.1 docker容器响应极慢
- reactjs - 当 React 中存在带有钩子的功能组件时,还应该使用类组件吗?
- microsoft-graph-api - OpenExtensions:查找和检索具有给定扩展名的事件
- javascript - 裁剪图像宽高比 1:1
- vb.net - 如何在更改 UICulture 后重新加载我的主窗体而不会丢失我的控件状态
- javascript - 拼接第一个对象返回TypeError: Cannot read property of undefined
- java - Thymeleaf 模板不发布正文
- c# - 我无法解决 - 无法从具有索引像素格式错误的图像创建图形对象
- google-cloud-platform - 使用 nodejs 10 运行时遵循谷歌云工作流教程时出错