This is a test version of Biostars. For the public version, visit https://www.biostars.org.
Error in changing the annotation color of pheatmap

Hi recently i tried to use the R package pheatmap to make a heat map that shows the gene enrichment in TCGA-bulk RNA seq data. I tried to amend the color of the annotation with the following code:

ann_colors = list('group.risk' = c("firebrick2","green2"),
                  'BRCA_subtype' = c("#FFC0CB", "#00CED1", "#FFA07A", "#6A5ACD", "#90EE90", "#FF1493"),
                  'disease_stage' = c("#1F77B4", "#FF7F0E", "#2CA02C", "#D62728", "#9467BD", "#8C564B"),
                  'Fraction_Genome_Altered' = c("#E69F00", "#56B4E9", "#009E73", "#F0E442", "#0072B2", "#D55E00"),
                  'Cancer Type Detailed' = c("#FF0000", "#00FF00", "#0000FF", "#FFA500", "#800080", "#FFFF00", "#00FFFF"))

pheatmap(es.max %>% t() %>% as.matrix(), 
         annotation_col  = annotation_col,
         clustering_distance_cols = "euclidean",
         cluster_cols = TRUE,
         fontsize_row = 20,
         fontsize_col = 0.0001,
         annotation_names_col  = T,
        annotation_colors = ann_colors)

BUT it results in the following error:

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

what happen is that i have already double checked that group.risk has only two factors (i.e. high risk and low risk, just like what i show in the attached heatmap)

r package pheatmap

1 answer

You need to specify which colour is which, as the factors and the colour names need to match.

ann_colors = list('group.risk' = c(High = "firebrick2", Low = "green2"), ....)

Log in to answer this question.