在ggalluvial中混合/合并流动

发布于 2025-02-08 15:32:26 字数 1393 浏览 3 评论 0原文

我需要使用ggalluvial创建特定类型的情节。来自包装的小插图:

require(ggalluvial)
data(vaccinations)
vaccinations <- transform(vaccinations,
                          response = factor(response, rev(levels(response))))
ggplot(vaccinations,
       aes(x = survey, stratum = response, alluvium = subject,
           y = freq,
           fill = response, label = response)) +
  scale_x_discrete(expand = c(.1, .1)) +
  geom_flow() +
  geom_stratum(alpha = .5) +
  geom_text(stat = "stratum", size = 3) +
  theme(legend.position = "none") +
  ggtitle("vaccination survey responses at three points in time")

给出此图:

”在此处输入图像描述

现在,我需要产生一个图,其中两个不同的节点“ Merge”(或收集)在同一部分中的两个不同的“流”第一个块中的另一个节点(例如,从“始终”和“有时”的流动在“始终”第二个块上的同一部分收敛)。显然,频率将与第一个块和第二个节点不同。

我试图操纵数据库更改频率,但是似乎无法在末端节点的同一部分中进行两个流“收敛”。

有人有猜测吗?

编辑:要回答评论,这是我想到的输出(从另一个答案中获取:创建sankey/冲积图,其中链接在节点上组合):

”

其中两个“ flow”(从红色和绿色盒子中)“汇聚”在粉红色盒子上(在粉红色盒子上占据同一位置)。

I need to create a particular type of plot using ggalluvial. From the vignette of the package:

require(ggalluvial)
data(vaccinations)
vaccinations <- transform(vaccinations,
                          response = factor(response, rev(levels(response))))
ggplot(vaccinations,
       aes(x = survey, stratum = response, alluvium = subject,
           y = freq,
           fill = response, label = response)) +
  scale_x_discrete(expand = c(.1, .1)) +
  geom_flow() +
  geom_stratum(alpha = .5) +
  geom_text(stat = "stratum", size = 3) +
  theme(legend.position = "none") +
  ggtitle("vaccination survey responses at three points in time")

Gives this plot:

enter image description here

Now, I need to produce a plot in which two different "flows" from the first block of nodes "merge" (or converge) on the same portion of another node in the first block (for example, the flows from "always" and "sometimes" converge on the same part on the "always" second block). Obviously, the frequencies would be different from the first block and the second block of nodes.

I've tried to manipulate the database changing frequencies, but it seems there is no way to make two flows "converge" on the same section of the end node.

Anyone have a guess?

EDIT: To answer to the comment, this is the output that I have in mind (taken from another answer, here: Create Sankey/ Alluvial diagram in which the links combine at the node):

enter image description here

In which two "flow" (from the red and the green boxes) "converge" on the pink box (occupying the same place on the pink box).

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文