UpSetR 按颜色集分组

2024-02-17

我盯着这个问题看了几个小时,似乎没有找到解决方案。我希望 upSet 图按集合着色。例如,

library('UpSetR')
movies <- read.csv( system.file("extdata", "movies.csv", package = "UpSetR"), 
                    header=T, sep=";" )
upset(movies, 
      sets = c("Action", "Comedy", "Drama"), 
      group.by="sets", matrix.color="blue", point.size=5,
      sets.bar.color=c("maroon","blue","orange"))

Looks like: UpSet1 However, I would like it to look like: UpSet2

换句话说,戏剧的所有交集为红色,喜剧的所有交集为蓝色,动作的交集为黄色。谢谢!


我添加了一个mat_col论证upset功能允许自定义交叉点的颜色。这是修改后的myupset功能。

myupset <- function (data, nsets = 5, nintersects = 40, sets = NULL, keep.order = F, 
    set.metadata = NULL, intersections = NULL, matrix.color = "gray23", mat_col=NULL,
    main.bar.color = "gray23", mainbar.y.label = "Intersection Size", 
    mainbar.y.max = NULL, sets.bar.color = "gray23", sets.x.label = "Set Size", 
    point.size = 2.2, line.size = 0.7, mb.ratio = c(0.7, 0.3), 
    expression = NULL, att.pos = NULL, att.color = main.bar.color, 
    order.by = c("freq", "degree"), decreasing = c(T, F), show.numbers = "yes", 
    number.angles = 0, group.by = "degree", cutoff = NULL, queries = NULL, 
    query.legend = "none", shade.color = "gray88", shade.alpha = 0.25, 
    matrix.dot.alpha = 0.5, empty.intersections = NULL, color.pal = 1, 
    boxplot.summary = NULL, attribute.plots = NULL, scale.intersections = "identity", 
    scale.sets = "identity", text.scale = 1, set_size.angles = 0, 
    set_size.show = FALSE, set_size.numbers_size = NULL, set_size.scale_max = NULL)  {

    startend <- UpSetR:::FindStartEnd(data)
    first.col <- startend[1]
    last.col <- startend[2]
    if (color.pal == 1) {
        palette <- c("#1F77B4", "#FF7F0E", "#2CA02C", "#D62728", 
            "#9467BD", "#8C564B", "#E377C2", "#7F7F7F", "#BCBD22", 
            "#17BECF")
    }
    else {
        palette <- c("#E69F00", "#56B4E9", "#009E73", "#F0E442", 
            "#0072B2", "#D55E00", "#CC79A7")
    }
    if (is.null(intersections) == F) {
        Set_names <- unique((unlist(intersections)))
        Sets_to_remove <- UpSetR:::Remove(data, first.col, last.col, Set_names)
        New_data <- UpSetR:::Wanted(data, Sets_to_remove)
        Num_of_set <-UpSetR:::Number_of_sets(Set_names)
        if (keep.order == F) {
            Set_names <- UpSetR:::order_sets(New_data, Set_names)
        }
        All_Freqs <- UpSetR:::specific_intersections(data, first.col, 
            last.col, intersections, order.by, group.by, decreasing, 
            cutoff, main.bar.color, Set_names)
    }
    else if (is.null(intersections) == T) {
        Set_names <- sets
        if (is.null(Set_names) == T || length(Set_names) == 0) {
            Set_names <- UpSetR:::FindMostFreq(data, first.col, last.col, 
                nsets)
        }
        Sets_to_remove <- UpSetR:::Remove(data, first.col, last.col, Set_names)
        New_data <- UpSetR:::Wanted(data, Sets_to_remove)
        Num_of_set <- UpSetR:::Number_of_sets(Set_names)
        if (keep.order == F) {
            Set_names <- UpSetR:::order_sets(New_data, Set_names)
        }
        All_Freqs <- UpSetR:::Counter(New_data, Num_of_set, first.col, 
            Set_names, nintersects, main.bar.color, order.by, 
            group.by, cutoff, empty.intersections, decreasing)
    }
    Matrix_setup <- UpSetR:::Create_matrix(All_Freqs)
    labels <- UpSetR:::Make_labels(Matrix_setup)
    att.x <- c()
    att.y <- c()
    if (is.null(attribute.plots) == F) {
        for (i in seq_along(attribute.plots$plots)) {
            if (length(attribute.plots$plots[[i]]$x) != 0) {
                att.x[i] <- attribute.plots$plots[[i]]$x
            }
            else if (length(attribute.plots$plots[[i]]$x) == 
                0) {
                att.x[i] <- NA
            }
            if (length(attribute.plots$plots[[i]]$y) != 0) {
                att.y[i] <- attribute.plots$plots[[i]]$y
            }
            else if (length(attribute.plots$plots[[i]]$y) == 
                0) {
                att.y[i] <- NA
            }
        }
    }
    BoxPlots <- NULL
    if (is.null(boxplot.summary) == F) {
        BoxData <- UpSetR:::IntersectionBoxPlot(All_Freqs, New_data, first.col, 
            Set_names)
        BoxPlots <- list()
        for (i in seq_along(boxplot.summary)) {
            BoxPlots[[i]] <- UpSetR:::BoxPlotsPlot(BoxData, boxplot.summary[i], 
                att.color)
        }
    }
    customAttDat <- NULL
    customQBar <- NULL
    Intersection <- NULL
    Element <- NULL
    legend <- NULL
    EBar_data <- NULL
    if (is.null(queries) == F) {
        custom.queries <- UpSetR:::SeperateQueries(queries, 2, palette)
        customDat <- UpSetR:::customQueries(New_data, custom.queries, 
            Set_names)
        legend <- UpSetR:::GuideGenerator(queries, palette)
        legend <- UpSetR:::Make_legend(legend)
        if (is.null(att.x) == F && is.null(customDat) == F) {
            customAttDat <- UpSetR:::CustomAttData(customDat, Set_names)
        }
        customQBar <- UpSetR:::customQueriesBar(customDat, Set_names, 
            All_Freqs, custom.queries)
    }
    if (is.null(queries) == F) {
        Intersection <- UpSetR:::SeperateQueries(queries, 1, palette)
        Matrix_col <- intersects(UpSetR:::QuerieInterData, Intersection, 
            New_data, first.col, Num_of_set, All_Freqs, expression, 
            Set_names, palette)
        Element <- UpSetR:::SeperateQueries(queries, 1, palette)
        EBar_data <- UpSetR:::ElemBarDat(Element, New_data, first.col, 
            expression, Set_names, palette, All_Freqs)
    }
    else {
        Matrix_col <- NULL
    }
    if (!is.null(mat_col)) {
      Matrix_col <- mat_col
    }
    Matrix_layout <- UpSetR:::Create_layout(Matrix_setup, matrix.color, 
        Matrix_col, matrix.dot.alpha)
    Set_sizes <- UpSetR:::FindSetFreqs(New_data, first.col, Num_of_set, 
        Set_names, keep.order)
    Bar_Q <- NULL
    if (is.null(queries) == F) {
        Bar_Q <- intersects(UpSetR:::QuerieInterBar, Intersection, New_data, 
            first.col, Num_of_set, All_Freqs, expression, Set_names, 
            palette)
    }
    QInter_att_data <- NULL
    QElem_att_data <- NULL
    if ((is.null(queries) == F) & (is.null(att.x) == F)) {
        QInter_att_data <- intersects(UpSetR:::QuerieInterAtt, Intersection, 
            New_data, first.col, Num_of_set, att.x, att.y, expression, 
            Set_names, palette)
        QElem_att_data <- elements(UpSetR:::QuerieElemAtt, Element, New_data, 
            first.col, expression, Set_names, att.x, att.y, palette)
    }
    AllQueryData <- UpSetR:::combineQueriesData(QInter_att_data, QElem_att_data, 
        customAttDat, att.x, att.y)
    ShadingData <- NULL
    if (is.null(set.metadata) == F) {
        ShadingData <- UpSetR:::get_shade_groups(set.metadata, Set_names, 
            Matrix_layout, shade.alpha)
        output <- UpSetR:::Make_set_metadata_plot(set.metadata, Set_names)
        set.metadata.plots <- output[[1]]
        set.metadata <- output[[2]]
        if (is.null(ShadingData) == FALSE) {
            shade.alpha <- unique(ShadingData$alpha)
        }
    }
    else {
        set.metadata.plots <- NULL
    }
    if (is.null(ShadingData) == TRUE) {
        ShadingData <- UpSetR:::MakeShading(Matrix_layout, shade.color)
    }
    Main_bar <- suppressMessages(UpSetR:::Make_main_bar(All_Freqs, Bar_Q, 
        show.numbers, mb.ratio, customQBar, number.angles, EBar_data, 
        mainbar.y.label, mainbar.y.max, scale.intersections, 
        text.scale, attribute.plots))
    Matrix <- UpSetR:::Make_matrix_plot(Matrix_layout, Set_sizes, All_Freqs, 
        point.size, line.size, text.scale, labels, ShadingData, 
        shade.alpha)
    Sizes <- UpSetR:::Make_size_plot(Set_sizes, sets.bar.color, mb.ratio, 
        sets.x.label, scale.sets, text.scale, set_size.angles, 
        set_size.show, set_size.scale_max, set_size.numbers_size)
    structure(class = "upset", .Data = list(Main_bar = Main_bar, 
        Matrix = Matrix, Sizes = Sizes, labels = labels, mb.ratio = mb.ratio, 
        att.x = att.x, att.y = att.y, New_data = New_data, expression = expression, 
        att.pos = att.pos, first.col = first.col, att.color = att.color, 
        AllQueryData = AllQueryData, attribute.plots = attribute.plots, 
        legend = legend, query.legend = query.legend, BoxPlots = BoxPlots, 
        Set_names = Set_names, set.metadata = set.metadata, set.metadata.plots = set.metadata.plots))
}

这是一个展示如何使用它的示例。

# The matrix of colors for the 3 x 12 intersection grid
mtxcol <- data.frame(x=rep(1:12,each=3), 
                     color=rep(c("maroon","blue","orange"),each=12))

movies <- read.csv(system.file("extdata", "movies.csv", package = "UpSetR"), 
                   header=T, sep=";")
myupset(movies, 
      sets = c("Action", "Comedy", "Drama"),
      group.by="sets", point.size=5, mat_col=mtxcol,
      sets.bar.color=c("maroon","blue","orange"))
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

UpSetR 按颜色集分组 的相关文章

  • R中的一元加/减是什么?

    来自 R 的详细信息部分Syntax http stat ethz ch R manual R patched library base html Syntax html帮助页面 定义了以下一元和二元运算符 他们被列出 在优先级组中 从最高
  • 我无法下载 R 中的 reshape2 包 [关闭]

    Closed 这个问题是无法重现或由拼写错误引起 help closed questions 目前不接受答案 我在尝试安装 R 包时收到此响应 gt installed packages reshape2 Package LibPath V
  • 正则表达式字符串中第一个和最后一个非点的位置

    我希望找到字符串的第一个和最后一个非点元素的位置 理想情况下我想这样做regex在基地R 我已经写过R解决问题的代码 不过 我对一个感兴趣regex解决方案 感谢您的任何建议 这是一个示例数据集和R代码以获得所需的结果 此代码拆分字符串并使
  • 使用 purrr 迭代替换数据帧列中的字符串

    我想用purrr使用以下命令在数据框列上迭代运行多个字符串替换gsub 功能 这是示例数据框 df lt data frame Year 2019 Text c rep a aa 5 rep a bb 3 rep a cc 2 gt df
  • 如何计算R中移动窗口内的平均斜率

    我的数据集包含2个变量y 和 t 05s y 每 05 秒测量一次 我正在尝试计算移动中的平均坡度20秒窗口 即计算第一个 20 秒斜率值后 窗口向前移动一个时间单位 05 秒 并计算下一个 20 秒窗口 在以下位置生成连续 20 秒斜率值
  • R 中的快速 QR 分解

    我有大量矩阵 需要对其执行 QR 分解并存储生成的 Q 矩阵 进行归一化 以便 R 矩阵在其对角线上具有正数 除了使用之外还有其他方法吗qr 功能 这是工作示例 system time Parameters for the matrix t
  • 将每列的值乘以 R 中另一个 data.frame 中的权重

    我有两个data frames df and weights 代码如下 df看起来像这样 id a b d EE f 1 this 0 23421153 0 02324956 0 5457353 0 73068586 0 5642554 2
  • 在 R 中使用 lapply 绘制多个数据帧

    我正在尝试使用 lapply 函数绘制多个数据帧 每个数据帧一个图 但是尽管有关此主题的所有帖子我都找不到答案 因为我不断收到错误 图的输出列表为空 我的数据结构如下 df1 lt mtcars gt group by cyl gt tal
  • 朴素贝叶斯分类器仅基于先验概率做出决策

    我试图根据推文的情绪将推文分为三类 买入 持有 卖出 我正在使用 R 和包 e1071 我有两个数据框 一个训练集和一组需要预测情绪的新推文 训练集数据框 text sentiment this stock is a good buy Bu
  • 只读取选定的列

    谁能告诉我如何仅读取下面每年数据的前 6 个月 7 列 例如使用read table Year Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec 2009 41 27 25 31 31 39 2
  • ddply 和aggregate 之间的区别

    有人可以通过以下示例帮助我了解聚合和 ddply 之间的区别 数据框 mydat lt data frame first rpois 10 10 second rpois 10 10 third rpois 10 10 group c re
  • 文本挖掘 pdf 文件/词频问题

    我正在尝试挖掘一篇具有丰富 pdf 编码和图表的文章的 pdf 我注意到 当我挖掘一些 pdf 文档时 我得到的高频词是 phi taeoe toe sigma gamma 等 它与某些 pdf 文档配合良好 但与其他文档配合使用时却得到这
  • 旋转 Markdown 的表格 pdf 输出

    我想将 pdf 上的表格输出旋转 90 度 我正在使用 Markdown 生成报告并kable循环显示表格 如果可以的话我想继续使用kable因为还有很多其他依赖于它的东西我没有包含在这个 MWE 中 这是一个简单的例子 使用iris数据集
  • 如何从 R keras 中的类似生成器的数据中评估()和预测()

    我有以下代码 数据集可以下载here https www dropbox com s qjt5o31oyqj10m8 data tar gz dl 0 or here https www kaggle com c dogs vs cats
  • 为什么 R 更新后 sim_slopes() 中会出现此错误?

    我正在尝试使用 交互 包来创建简单斜率的约翰逊 尼曼图 但是 当尝试运行 sim slopes 函数时 出现以下错误 直到我将R更新到4 2 2 我才没有遇到这个问题 我使用的是 macOS Ventura 13 1 Error class
  • read_html(url) 和 read_html(content(GET(url), "text")) 之间的区别

    我正在看这个很棒的答案 https stackoverflow com a 58211397 3502164 https stackoverflow com a 58211397 3502164 解决方案的开头包括 library httr
  • R“错误:“}”中出现意外的“}”[重复]

    这个问题在这里已经有答案了 我有一个字符串变量 对于缺少数据的情况 它具有 空值 我想将 空值 重新编码为缺失 而不是说 空值 我正在尝试编写一个循环来删除这些 空值 条目 但我不断收到错误 错误 中出现意外的 for row in dat
  • 实三次多项式的最快数值解?

    R 问题 寻找最快的方法来数值求解一堆已知具有实系数和三个实根的任意三次方程 据报道 R 中的 polyroot 函数对复杂多项式使用 Jenkins Traub 算法 419 但对于实多项式 作者参考了他们早期的工作 对于实三次或更一般的
  • 在 Shiny 中的用户会话之间共享反应数据集

    我有一个相当大的反应数据集 该数据集是通过轮询文件然后按预定义的时间间隔读取该文件而派生的 数据更新频繁 需要不断重新加载 诚然 重新加载可以增量完成并附加到 R 中的现有对象 但事实并非如此 然而目前 尽管会话中的数据相同 但此操作是针对
  • 如何使用 dplyr 独立过滤每列的行

    我有以下内容 library tidyverse df lt tibble tribble gene colB colC a 1 2 b 2 3 c 3 4 d 1 1 df gt A tibble 4 x 3 gt gene colB c

随机推荐

  • Azure Function 给出错误:此平台不支持 System.Drawing

    如果这个问题措辞不好 有人可以帮我解决吗 我有一个 Azure Function 2 0 它依赖于一些 System Drawing 代码 我添加了对 System Drawing Common 4 5 0 的 NuGet 引用 然而 发布
  • 如何在Contact Form 7 WordPress中实施Google Adwords转换代码

    我想将 Google 转化 Adwords 代码集成到联系表7插件无需重定向到 谢谢 页面 如何在中实现 Google Adwords 转换代码联系表7插件 有人可以帮助我吗 我不喜欢重定向到另一个页面 我在联系表单 7 中找到了实施 Go
  • 如何遍历/迭代 STL 映射?

    我想遍历一张STL地图 我不想使用它的密钥 我不关心顺序 我只是寻找一种访问它包含的所有元素的方法 我怎样才能做到这一点 是的 您可以遍历标准库map 这是用于遍历的基本方法map 并作为遍历任何标准库集合的指导 C 03 C 11 inc
  • JavaScript 在某个索引后找到第一个正则表达式匹配

    我想找到第一个RegExp一定之后匹配index in a String在 JavaScript 中 JavaScriptString prototype indexOf在搜索开始处提供第二个参数限制 但indexOf只支持String n
  • CryptographicException:错误的 PKCS7 填充

    我看到一小部分生产用户随机报告与使用 Xamarin Android 加密 解密字符串相关的异常 但不幸的是我无法重现它 什么可能导致此问题和 或如何重现该异常 以便找到修复 解决方法 CryptographicException Bad
  • Swift 像闭包一样使用选择器参数

    我只是想知道是否可以将函数传递给按钮操作 通常是选择器 例如 通常我会说 UIBarButtonItem title Press style Done target self action functionToCall func funct
  • 当前拓扑不支持会话

    Hi 我收到错误 当前拓扑不支持会话 请参考附图 并编码为 async function insertBooking parking aFunction const session await BookingSchema startSess
  • 为什么我不能将此接口转换为具体类?

    我有一个界面IApiDataWithProperties 一个类叫做Event实现了这个接口 通常我可以投射一个对象IApiDataWithProperties to Event 假设它是一个 并且编译器让我这样做没有问题 在这种情况下 该
  • 在Oracle中的SQL查询中获取固定数量的行[重复]

    这个问题在这里已经有答案了 请帮我在Oracle数据库中编写一个SQL查询 有一个名为 tbl 的表 它有 12 行 我想先选择前 4 行 然后选择下 4 行和最后 4 行 谁能告诉我如何在 Informix 中做到这一点 编辑 现在应该通
  • PySpark 2.x:以编程方式将 Maven JAR 坐标添加到 Spark

    以下是我的 PySpark 启动片段 非常可靠 我已经使用它很长时间了 今天我添加了两个 Maven 坐标 如图所示spark jars packages选项 有效地 插入 Kafka 支持 现在通常会触发依赖项下载 由 Spark 自动执
  • 如何从 PHP 调用网站服务?

    我的问题如下 我的服务器上有一个 EmailReports php 我用它来发送邮件 例如 电子邮件受保护 cdn cgi l email protection 什么 123456 pdf 我无法修改 EmailReports php 因为
  • 快速查找字符串是否在数组中的方法

    在 Ruby 中 查找字符串是否在数组中 include x 非常慢 如果将该数组更改为集合 则BAM 闪电般的快速查找 在 JavaScript 中 没有集合 数组查找 indexOf x gt 0 也是very很慢 但是我需要在脚本中执
  • jquery DomWindow 用于网页上的所有链接

    是否可以实现本页的示例3 http swip codylindley com DOMWindowDemo html http swip codylindley com DOMWindowDemo html适用于网页上的所有链接 不仅仅是带有
  • 如何使用回调机制?

    我必须实施一项信用卡申请 其中我必须只处理一个信用卡帐户 类似的操作credit debit pinChange 但对我来说问题是我必须使用 JAVA CALLBACK 机制在两种情况下通知用户 引脚更改时 当余额低于 5000 时 如何使
  • SaveFileDialog 阻止可移动驱动器

    我使用 SaveFileDialog 让用户在可移动驱动器上选择目录和文件名 然后我创建该文件 写入该文件 然后再次关闭它 到那时 文件本身尚未锁定 可编辑 可删除 但我无法弹出驱动器 因为 Windows 声称它仍在使用中 我必须先退出应
  • java中System.gc()和finalize()方法有什么区别?

    我对 java 的 system gc 和 Finalize 方法感到困惑 我们不能强制将垃圾对象收集到 JVM 我们可以在java代码中编写这两种方法 那么如果它们都用于垃圾收集 那么java提供两种垃圾收集方法有什么意义呢 请告诉我这两
  • Sublime Text - 修改 tmTheme 文件

    In the tmTheme file
  • 为什么不使用 django-admin startapp mysite 生成 urls.py?

    但必须由用户创建 project settings py mysite views py apps py models py user created urls py file 应用程序不需要有 url 视图或任何东西 它也可以只是模板的集
  • 何时删除 Git 中的分支?

    假设我们有一个稳定的应用程序 明天 有人报告了一个大错误 我们决定立即修复 因此 我们为 master 的修补程序创建了一个分支 将其命名为 2011 Hotfix 并将其向上推送 以便所有开发人员都可以协作修复它 我们修复了该错误 并将
  • UpSetR 按颜色集分组

    我盯着这个问题看了几个小时 似乎没有找到解决方案 我希望 upSet 图按集合着色 例如 library UpSetR movies lt read csv system file extdata movies csv package Up