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
相关产品推荐
相关产品推荐

