使用UpSetR绘图时出现start_col:end_col参数长度为0错误的解决咨询
UpSetR绘图报错:
Error in start_col:end_col : argument of length 0 解决方法 问题场景
使用如下数据集:
df <- structure(list(id = c(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40), a = c(0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 1, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 0, 1, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 0, 0, 1, 1, 0), b = c(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 1), c = c(0, 0, 1, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 0, 0, 1, 1, 0, 0, 0, 1, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 0, 0, 1, 1, 0), d = c(1, 1, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 1, 0, 0, 0, 0, 1, 1, 1, 0, 1, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0), e = c(0, 0, 0, 0, 1, 1, 1, 0, 1, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1)), class = c("tbl_df", "tbl", "data.frame"), row.names = c(NA, -40L))
执行以下UpSetR绘图代码时触发报错:
library(UpSetR) graph <- upset(df, sets = c("a", "b", "c", "d", "e"), order.by = "freq", empty.intersections = "on")
报错及警告信息:
Error in start_col:end_col : argument of length 0 In addition: There were 12 warnings (use warnings() to see them) Warning messages: 1: In xtfrm.data.frame(x) : cannot xtfrm data frames 2: In xtfrm.data.frame(x) : cannot xtfrm data frames 3: In xtfrm.data.frame(x) : cannot xtfrm data frames 4: In xtfrm.data.frame(x) : cannot xtfrm data frames 5: In xtfrm.data.frame(x) : cannot xtfrm data frames 6: In xtfrm.data.frame(x) : cannot xtfrm data frames 7: In xtfrm.data.frame(x) : cannot xtfrm data frames 8: In xtfrm.data.frame(x) : cannot xtfrm data frames 9: In xtfrm.data.frame(x) : cannot xtfrm data frames 10: In xtfrm.data.frame(x) : cannot xtfrm data frames 11: In xtfrm.data.frame(x) : cannot xtfrm data frames 12: In xtfrm.data.frame(x) : cannot xtfrm data frames
问题根源
你的数据集是tibble(tbl_df类型),UpSetR包对tibble的兼容性较差,而官方示例使用的是普通data.frame,这是触发报错的核心原因。
解决方法
将tibble转换为普通data.frame后再调用upset()函数,修改后的代码如下:
library(UpSetR) # 转换为普通data.frame df <- as.data.frame(df) # 重新绘制UpSet交集图 graph <- upset(df, sets = c("a", "b", "c", "d", "e"), order.by = "freq", empty.intersections = "on")
执行上述代码后即可正常生成交集可视化图,不会再触发原报错和警告。
内容的提问来源于stack exchange,提问作者user19745561
相关产品推荐
相关产品推荐

