微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

ggalluvial geom_text 重复

如何解决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.JdbcOdbcDriver发生异常。为什么?
这是用Java进行XML解析的最佳库。
Java的PriorityQueue的内置迭代器不会以任何特定顺序遍历数据结构。为什么?
如何在Java中聆听按键时移动图像。
Java“Program to an interface”。这是什么意思?