在R中向Pheatmap添加注释颜色时出错:“提供的元素多于要替换的元素”

时间:2018-11-23 14:31:25

标签: r pheatmap

我是相对的R新手,尝试更改pheatmap中用于批注的调色板时遇到一些问题。

我已经使用以下命令从文件Total_depth_avg_mag.txt中创建了带注释的热图:

library(vegan)
library(gplots)
library(dplyr)
library('pheatmap')
library(RColorBrewer)

#Reads data into table, adds row names and deletes the first column
dat<-read.table("Total_depth_avg_mag.txt", header = T)
row.names(dat) <- dat$mag
dat <- dat[, -1]

# Produces annotation data_frame from input file
data_annot_2 <- read.table("Mag_annot_taxonomy.txt", header = T) 
rownames(data_annot_2) = data_annot_2$mag
data_annot <- data_annot_2["Taxonomy"]

#Produces annotated heatmap
pheatmap(dat, cluster_cols = F, cluster_rows = F, fontsize_col = 10, 
fontsize_row = 5, filename = "Mags_all_unclustered_tax.png", width =20, 
height =30, border_color= NA, annotation_row = data_annot) 

产生以下内容: Heatmap_with_generic_colours

由于我的注释中有很多(34)变量,其中一些最终使用相同的颜色,因此我想使用自己的调色板。我使用以下代码尝试执行此操作:

#Making a version of the "Greys" set from Rcolorbrewer containing 17 colours
coul = brewer.pal(9, "Greys")
coul = colorRampPalette(coul)(17)

#Producing a palette to feed into pheatmap. Contains 34 colours. 
my_palette <- c(brewer.pal(9, "Reds")[c(6)], brewer.pal(9, "Greens") 
[c(4,7)], brewer.pal(9, "Oranges")[c(4)], brewer.pal(9, "Blues")[c(3,5,7)], 
brewer.pal(8, "Accent")[c(4)], brewer.pal(8, "Accent")[c(6)], brewer.pal(8, 
"Accent")[c(7)], coul, brewer.pal(9, "Purples")[c(3,4,5,7)], brewer.pal(9, 
"BuGn")[c(3,4)], brewer.pal(8, "Pastel2")[c(7)])

#Producing annotated heatmap with my_palette
pheatmap(dat, cluster_cols = F, cluster_rows = F, fontsize_col = 10, 
fontsize_row = 5, filename = "Mags_all_unclustered_tax_col.png", width =20, 
height =30, border_color= NA, annotation_row = data_annot, 
annotation_colors = my_palette) 

然后我收到错误消息“ notification_colors [[names(annotation] [i]]]] <-factor_colors [ind]:提供的元素多于要替换的元素”

我不确定为什么会这样,因为my_palette中肯定有34种颜色,并且我的注释应包含34个变量。

有人可以提出任何建议来解决此问题吗?

0 个答案:

没有答案