Search code examples
rheatmappheatmap

pheatmap: change text color


How can I change the text color in pheatmap? I've tried the following but it doesn't change the axes text and labels but it doesn't work

par( col.lab="#FFFFFF", fg="#FFFFFF", col.main="#FFFFFF", col.axis="#FFFFFF", cex.main=2, cex=2)
pheatmap(heat_data, cluster_rows = FALSE, gaps_row = c(3), cellwidth=35, cellheight=35, fontsize = 25)

Solution

  • Here's the answer. The code modifies the color and font size of the x and y labels as well as the color and linewidth of the dendrogram. The colors are set to white, but you can change it to other colors.

    p = pheatmap(heat_data, cluster_rows=F,  gaps_row = 3, 
                cellwidth=45, cellheight=45, fontsize = 20, angle_col = "90", legend=TRUE,legend_breaks=c(40, 20, 0, -20, -40, -60),
                 legend_labels=c(40, 20, " 0", -20, -40, -60), annotation_row = NULL,
                annotation_legend = FALSE, labels_row = NULL, labels_col=NULL, 
                annotation_names_row = F, annotation_names_col = F, annotation_colors  = ann_colors, dist="euclidean", 
                col=COLS, scale="none", show_rownames = T, show_colnames = T)
    my_gtable = p$gtable
    
    my_gtable$grobs[[3]]$gp=gpar(col="#ffffff", fontsize=20)# assuming that the xlabels are in the third grob
    my_gtable$grobs[[4]]$gp=gpar(col="#ffffff", fontsize=20)# assuming that the ylabels are in the fourth grob
    my_gtable$grobs[[1]]$gp=gpar(col="#ffffff", lwd=2) # change the color of the dendrogram and set the linewidth to 2
    my_gtable$grobs[[5]]$gp=gpar(col="#ffffff", fontsize="20", just="center") # legend