【问题标题】:Simple one about Alluvial plot in R关于R中冲积地块的简单一个
【发布时间】:2022-11-16 10:23:59
【问题描述】:

我想制作一个简单的流程图。 这是我的代码:

## 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) 

这是结果:

我想要的结果是:

如何用缺失值表示递减模式?

【问题讨论】:

    标签: r ggplot2


    【解决方案1】:

    通过稍微重塑您的数据,您可以获得您想要的。我认为关键是将alluvium 映射到与y 相同的变量,这样它会减少并将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()
    

    创建于 2022-11-15 reprex v2.0.2

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-07-10
      • 2020-01-23
      • 1970-01-01
      • 2023-01-29
      • 1970-01-01
      • 2022-01-13
      • 2021-12-28
      • 2020-06-10
      相关资源
      最近更新 更多