Changing colour labels of samples with pheatmap
1
0
Entering edit mode
2.6 years ago
mar77 ▴ 40

Bit of an R newbie here. I'm trying to generate a figure to see how RNA-seq samples are grouping via hierarchical clustering.

Using this code

rld<-vst(dds, blind=TRUE)
rld_mat<- assay(rld)
rld_cor<-cor(rld_mat)
head(rld_cor)
pheatmap(rld_cor,annotation = meta)
heat.colors<-brewer.pal(9, "Blues")
annotdf<-data.frame(row.names = rownames(rld_cor))
pheatmap(rld_cor, 
         annotation=meta, 
         color=heat.colors,
         annotation_colors = ColorCode,
         border_color = NA, 
         fontsize = 10, 
         fontsize_row = 10, 
         height=20)

enter image description here

But when I try to add this code in:

ColorCode<-c("#CDCDCD","#A5A5A5","#808080","#9AB3FF","#537EFF","#265DFF", "#FFD733","#DDB310", "#CC9900","#FB8ACA","#FB49B0","#E40081","#00FF89","#00B25D","#008042")

and then add this into the pheatmap function

         annotation_colors = ColorCode,

to try and change the colour labels for the samples to match other figures I keep getting this error

Error in annotation_colors[[names(annotation)[i]]] <- factor_colors[ind] : 

more elements supplied than there are to replace

I don't really understand why as I have set up 15 colours and by samples are sorted into 15 categories. Does anyone know how to fix this? Thanks for any help

pheatmap • 3.9k views
ADD COMMENT
1
Entering edit mode
2.6 years ago
Papyrus ★ 2.9k

I think the input to annotation_colors should be a list. For example:

ColorCode  = list(sampletype = c("#CDCDCD","#A5A5A5","#808080","#9AB3FF","#537EFF","#265DFF", "#FFD733","#DDB310", "#CC9900","#FB8ACA","#FB49B0","#E40081","#00FF89","#00B25D","#008042"))

And also, I would work with the: annotation_col and annotation_row arguments, not with annotation

Try this example:

library(pheatmap)

foo <- matrix(1:6,2,3)
colnames(foo) <- c("a","b","c")

anno.colors <- list(anno = c(a = "black",b = "green",c = "blue"))

pheatmap(foo,
         annotation_colors  = anno.colors,
         annotation_col = data.frame(anno = c("a","b","c"),
                                     row.names = c("a","b","c")))
ADD COMMENT

Login before adding your answer.

Traffic: 2648 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6