简体   繁体   English

R中关于冲积plot的简单一个

[英]Simple one about Alluvial plot in R

I would like to make a simple flow graph.我想制作一个简单的流程图。 Here is my code:这是我的代码:

## Data
    x = tibble(qms = c("FLOW", "FLOW"),
               move1 = c("Birth", "Birth"),
               move2 = c("Direct", NA),
               freq = c(100, 50))
## Graph
    x %>% 
      mutate(id = qms) %>% 
      to_lodes_form(axis = 2:3, id = id) %>% 
      na.omit() %>% 
      ggplot(aes(x = x, stratum = stratum, alluvium = id,
                 y = freq, label = stratum)) +
      scale_x_discrete(expand = c(.1, .1)) +
      geom_flow(aes(fill = qms),stat = "alluvium") +
      geom_stratum(aes(fill = stratum), show.legend=FALSE) +
      geom_text(stat = "stratum", size = 3) 

This is the outcome:这是结果:

在此处输入图像描述

My desired outcome is that:我想要的结果是:

在此处输入图像描述

How can I express the decreasing pattern with the missing value?如何用缺失值表示递减模式?

By slightly reshaping your data you can get what you want.通过稍微重塑您的数据,您可以获得您想要的。 I think the key is to map the alluvium to something fixed like 1 so that it will be a single flow, and mapping stratum to the same variable as x .我认为关键是 map 将alluvium固定为1之类的东西,这样它将成为一个单一的流,并将stratum映射到与x相同的变量。

library(tidyverse)
library(ggalluvial)

x <- tibble(x = c("Birth", "Direct"),
            y = c(100, 50))

x %>% 
  ggplot(aes(x, y, alluvium = 1, stratum = x)) +
  geom_alluvium() +
  geom_stratum()

Created on 2022-11-15 with reprex v2.0.2创建于 2022-11-15,使用reprex v2.0.2

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM