You need to enable JavaScript to run this app. R语言结合UpSet图绘制type分布直方图的报错解决咨询
优惠活动
大模型
产品
解决方案
定价
更多

R语言结合UpSet图绘制type分布直方图的报错解决咨询

报错原因
  • 你调用的histogram绘图函数底层是ggplot2的geom_histogram(),该函数仅支持对连续数值型变量做分箱统计
  • 你的type列是存储SNP/DEL的离散分类变量,不符合geom_histogram()的输入要求,因此触发报错
修复代码

首先确保已加载依赖包:

library(UpSetR)
library(ggplot2)

有两种常用实现方案:

方案1:自定义ggplot条形图(支持灵活调整样式)

upset(df, 
      attribute.plots = list(
        gridrows = 50,
        plots = list(
          list(
            plot = function(data) {
              ggplot(data, aes(x = type)) + 
                geom_bar(fill = "#457b9d") +
                labs(x = "变异类型", y = "样本数") +
                theme_minimal()
            },
            x = "type", 
            y = "count"
          )
        )
      ))

方案2:使用UpSetR内置柱状图(写法更简洁)

upset(df, 
      attribute.plots = list(
        gridrows = 50,
        plots = list(
          list(plot = "hist", x = "type")
        )
      ))

内容的提问来源于stack exchange,提问作者LDT

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.10.09 14:48:01