ggalluvial geom_text 重复

问题描述

我想在我创建的 ggalluvial 图中使用 geom_text。下面提供的代码按预期工作,除非性能级别之间有 50/50 的平均分配。 geom_text() 中是否有一个参数可以防止文本在 geom_stratum(aes(fill = profEOY)) 上重复?简而言之,2018 年的结果看起来符合预期,2019 年的结果以 50/50 的比例划分是有问题的。

我在 Shiny 中为 160 多个报告站点显示此图,因此我认为 annotate() 不会起作用。

Example Plot

library(tidyverse)
library(ggalluvial)
df <-
  structure(
    list(
      profBOY = c(
        "At or Above","At or Above","Below or Well Below","Below or Well Below"
      ),profEOY = c(
        "At or Above",EndYear = c(
        2018L,2018L,2019L,2019L
      ),sum = c(37,6,21,27,3,5,22),totaln = c(74L,74L,80L,80L),totalNBoy = c(68,68,64,64),totalInBoyPB = c(
        "38","38","30","32","32"
      ),percentInBoyPB = c(55.9,55.9,44.1,50,50),totalNEoy = c(69,69,73,73),totalInEoyPB = c(
        "44","25","44","34","39","39"
      ),percentInEoyPB = c(63.8,36.2,63.8,46.6,53.4,53.4),percent = c(
        "50%","0%","8%","28%","34%","4%","6%","28%"
      )
    ),row.names = c(NA,-8L),class = c("tbl_df","tbl","data.frame")
  )

ggplot(df,aes(y = sum,axis1 = str_wrap(profBOY,10),axis2 = str_wrap(profEOY,fill = profBOY
       )) +
  geom_flow(color = '#e57a3c',curve_type = 'quintic') +
  scale_x_discrete(limits = c("Beginning \nof Year","End \nof Year")) +
  scale_fill_manual(values = c("#315683","#6c7070")) +
  geom_stratum(aes(fill = profEOY),color = 'grey',width = 1/2) +
  geom_stratum(aes(fill = profBOY),width = 1/2) +
  geom_text(stat = 'stratum',aes(label = paste0(percentInBoyPB,'%')),vjust = 1,size = 4,color = 'white')+
  labs(fill = 'Performance Level')+
  facet_wrap(vars(factor(EndYear)),nrow = 1,scales = 'free_y')+
  theme_minimal()+
  theme(axis.text.y = element_blank(),axis.title.y = element_blank(),axis.ticks = element_blank(),panel.grid = element_blank(),legend.position = 'top',legend.text = element_text(size = 12),legend.title = element_text(size = 14),axis.text.x = element_text(size = 16),strip.text = element_text(size = 18),strip.background = element_rect(fill = 'lightgrey',color = 'lightgrey')
  )

感谢您的建议!

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...