积聚控制节点的位置

时间:2018-12-14 03:16:33

标签: r ggplot2

在冲积图中,我想控制节点的垂直位置。具体来说,我想对齐相同值的节点(例如,秋季为“ Meet”,春季为“ Meet”),以避免像下面的蓝色示例(倾斜表示错误增长)中的蓝色倾斜坡地一样。如果我可以将相同值的节点在相同的y轴值上居中,我想我可以将这种错误信号降到最低。

enter image description here

library(ggalluvial)
library(tidyverse)

set.seed(57)

levels_score <- c("Below", "Meet")

ds_sankey <- 
  tibble(
    fall = c("Below", "Below", "Meet", "Meet"),
    spring = c("Below", "Meet", "Below", "Meet"),
    n = runif(n = 4, min = 100, max = 500)
  ) %>% 
  mutate(
    fall = factor(fall, levels = levels_score),
    spring = factor(spring, levels = levels_score),
    n = round(n)
  ) 

ds_sankey %>% 
  ggplot(aes(y = n, axis1 = fct_rev(fall), axis2 = fct_rev(spring))) +
  geom_alluvium(width = 1/12) +
  geom_stratum(width = 1/4, color = "grey") +
  geom_label(stat = "stratum", label.strata = TRUE) +
  scale_x_discrete(limits = c("fall", "spring"), expand = c(.05, .05))

0 个答案:

没有答案