代码之家  ›  专栏  ›  技术社区  ›  jhyeon

R冲积地块简论

  •  0
  • jhyeon  · 技术社区  · 2 年前

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

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

    结果是:

    enter image description here

    我想要的结果是:

    enter image description here

    如何表达缺失值的递减模式?

    1 回复  |  直到 2 年前
        1
  •  1
  •   Dan Adams    2 年前

    通过对数据进行轻微的整形,您可以得到您想要的东西。我认为关键是绘制 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()
    

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