R | pheatmap: Error in convert_annotations(annotation_col, annotation_colors) : Factor levels on

运行pheatmap包构建分组时报错,报错内容:

Error in convert_annotations(annotation_col, annotation_colors) : 
  Factor levels on variable Time do not match with annotation_colors

原因及解决方法
如图1所示,annotation_col一栏构建数据框分组列时,Time中写的是“gJuly”,而ann_colors颜色列表中写的是“July”,二者不匹配导致报错,修改之后运行成功。
R | pheatmap: Error in convert_annotations(annotation_col, annotation_colors) : Factor levels on_第1张图片
图1 报错代码

修改后代码

annotation_col = data.frame(Sample=factor(rep(c("group1","group2","group3"),3)),Time=factor(rep(c("March","July","December"),3)))
row.names(annotation_col) = colnames(data1) #这一行必须有,否则会报错:Error in check.length("fill") :  'gpar' element 'fill' must not be length 0

ann_colors <- list(
             Sample = c(group1 = "blue", group2 = "red", group3 = "green"),
             Time = c(March = "orange", July = "purple", December = "yellow")
             )

你可能感兴趣的:(R,pheatmap)