【问题标题】:Pheatmap:Error in annotation_colors[[colnames(annotation)[i]]] : subscript out of boundsPheatmap:annotation_colors[[colnames(annotation)[i]]] 中的错误:下标越界
【发布时间】:2019-03-30 14:25:42
【问题描述】:
library(pheatmap)

another<-read.table("~/Desktop/tcga3dcategorized.csv",sep=',',header=FALSE)
test<-another[1:3]
labels<-another[4]
colnames(test)=c("Dim 1","Dim 2","Dim 3")

annotation_row=data.frame(CancerType=factor(labels))
ann_colors=list(CancerType=c(KIRC="red", UCEC="#B2509E",LUSC="#D49DC7",
    LGG="#C1A72F",PCPG="#E8C51D",HNSC="#F9ED32",CESC="#104A7F",ESCA="#9EDDF9",
    BRCA="#007EB5",THCA="#CACCDB",PRAD="#6E7BA2",MESO="#DAF1FC",PAAD="#00AEEF",
    LUAD="#F6B667",LAML="#D97D25",UVM="#FBE3C7",GBM="#F89420",READ="#97D1A9",
    SKCM="#009444",KIRP="#754C29",COAD="#CEAC8F",LIHC="#3953A4",SARC="#BBD642",
    OV="#00A99D",BLCA="#D3C3E0",STAD="#A084BD",TGCT="#542C88",ACC="#FAD2D9",
    THYM="#ED1C24",KICH="#F8AFB3",DLBC="#EA7075",UCS="#7E1918",CHOL="#BE1E2D"))

pheatmap(test,annotation_row=annotation_row,annotation_colors=ann_colors,main="title")
```

错误是:

Error in annotation_colors[[colnames(annotation)[i]]] : 
  subscript out of bounds

【问题讨论】:

  • 您需要发布您的数据,以及重现错误的代码,还包括您的库版本

标签: r bioinformatics pheatmap


【解决方案1】:

你应该强制你的数据框有行名。

# after read.table
rownames(another) <- paste0("row_", seq(nrow(another)))

看Something weird in pheatmap (a bug?)

【讨论】:

    【解决方案2】:

    检查您的数据结构 - 它们不正确。您的结构 another 由 read.table 和 test 生成,它是 dataframes 的子集。而您正试图将它们输入到使用matrix 的pheatmap 函数中——这与dataframe 的结构不同。 您可以像这样将对象转换为矩阵:

    test_matrix <- data.matrix(test, rownames.force=NA) # change the rownames.force -argument if you want rownames
    

    然后您可以将其提供给pheatmap。如果它不起作用,您可以检查送入pheatmap 的对象的尺寸。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-04-03
      • 1970-01-01
      • 2012-08-03
      • 1970-01-01
      • 1970-01-01
      • 2015-02-11
      • 2014-08-31
      • 1970-01-01
      相关资源
      最近更新 更多