在我的实验中,我正试图摆脱超过3个条件/样本的维恩地块.它只是变得越来越难以解释.

使用UpSetR::Supp()的翻转绘图效果很好,但我必须在后期制作中通过裁剪删除设置大小的绘图.我希望将其从颠倒的条形图中删除,以便生成的曲线图可以在报告中使用.

我的几个同事(我周围的生物学家,他们需要这些数字来做他们的报告)太习惯于查看Venns,他们真的希望看到每个交叉点的百分比以及完整的观测数量.一般来说,我希望展示不同条件下不同基因等表达的重叠.

下面是一个例子:

require(tidyverse)
require(stringr)
require(VennDiagram)
require(UpSetR)


temp_movies  <- ggplot2movies::movies



to_UpSet <- list( Action = filter( temp_movies, Action == 1)$title,
                  Comedy = filter( temp_movies, Comedy == 1)$title,
                  Drama = filter( temp_movies, Drama == 1)$title,
                  Romance = filter( temp_movies, Romance == 1)$title)


upset(fromList(to_UpSet), 
      order.by = "freq",
      set_size.show = TRUE)

它产生:

enter image description here

我怎样才能删除集大小图和添加%一样,在文氏图附件

enter image description here

Manually cropped example is here along with % labels for two bars - need % labels on all the bars: enter image description here

推荐答案

UpSetR:::print.upset函数(执行最终绘图)不允许进行此类修改.

然而,好消息是,整个绘图是以grid为基础的,因此您可以相当容易地从计算的部分绘制绘图,跳过设置大小的绘图并修改标签(归根结底是找到正确的Grobs):

library(grid)
library(gridExtra)

ups <- upset(fromList(to_UpSet), 
             order.by = "freq",
             set_size.show = TRUE)

skip_set_size_plot <- function(ups) {
  main <- ups$Main_bar
  ## find panel grob
  panel_idx <- grep("panel", main$layout$name, fixed = TRUE)
  ## find text grob
  text_idx <- which(
    vapply(main$grobs[[panel_idx]]$children, 
           \(x) inherits(x, "text"), 
           logical(1)))
  tG <- main$grobs[[panel_idx]]$children[[text_idx]]
  tG$label <- paste0(tG$label, " (",
                     scales::label_percent(0.1)(as.numeric(tG$label) / 
                                                  sum(as.numeric(tG$label))),
                     ")")
  main$grobs[[panel_idx]]$children[[text_idx]] <- tG
  grid.newpage()
  grid.draw(arrangeGrob(main, ups$Matrix, heights = ups$mb.ratio))
}

skip_set_size_plot(ups)

Visualization of set intersections using novel UpSet matrix design without the barchart representing the set sizes

与通常的手动grid调音一样,您依赖internal struct ,如果包作者出于任何原因决定更改它,您的代码可能会崩溃.

此外,这段代码使用最简单的交叉点图形式,但一旦开始要求额外的元素(例如legend),您就需要适应.

R相关问答推荐

导入到固定列宽的R中时出现问题

R中的枢轴/转置

如何使用geom_sf在边界显示两种 colored颜色 ?

使用ggcorrplot在相关性矩阵上标注supertitle和index标签

按R中的组查找相邻列的行累积和的最大值

在R中列表的结尾添加数字载体

如何求解arg必须为NULL或deSolve包的ode函数中的字符向量错误

R根据条件进行累积更改

在ggplot中为不同几何体使用不同的 colored颜色 比例

以字符格式导入的ExcelElectron 表格日期列标题

汇总数据的Sheffe检验的P值(平均值和标准差)

R如何将列名转换为更好的年和月格式

如何在R中使用混合GAM模型只对固定的影响因素进行适当的预测?

为什么将负值向量提升到分数次方会得到NaN

R-如何在ggplot2中显示具有不同x轴值(日期)的多行?

根据排名的顶点属性调整曲线图布局(&Q)

conditionPanel不考虑以下条件

使用列名和r中的前缀 Select 列的CREATE函数

创建两个变量组合的索引矩阵

使用循环改进功能( struct 简单)