Hello,
I am using pheatmap to map RNA-seq data. I have run into the same problem as other users, in attempting to annotate my heatmaps. Unfortunately I'm in the early stages of learning R, so I am struggling to interpret the solutions offered in other posts.
I would like to annotate my heatmap by rows (genes falling into a particular category "Genetype", as well as columns "SubcloneCohort". I get the common error message:
Error in check.length("fill") : 'gpar' element 'fill' must not be length 0
If anyone can help me understand what is amiss I'll be very grateful! Here is a link to the .CSV data file
Thanks, Oliver
The code I am using is as follows:
Read in data
data <- read.csv("DNA repair genes.csv", comment.char="#")
assign labels in column 1 to "rnames"
rnames <- data[,1]
assign labels in column 67 to "gtype"
gtype <- data[,67]
transform column 2-66 into a matrix
matrix <- data.matrix(data[,2:66])
rownames(matrix) <- rnames
Generate annotations for columns
annotation_col = data.frame( SubcloneCohort = factor(rep(c("J", "O", "P", "K", "L", "N", "Q"), c(8, 10, 9, 10, 10, 7, 11))))
rownames(annotation_col) = paste("Cohort", 1:65, sep = "")
Generate annotations for rows
annotation_row = data.frame( GeneType = factor(rep(c("Strand break joining", "Base excision repair", "Poly polymerases", "Direct reversal of damage", "Repair of topoisomerase crosslinks", "Mismatch excision repair", "Homologour recombination", "Fanconi anaemia", "Non-homologous end joining"), c(6, 11, 3, 3, 2, 9, 19, 14, 7))))
rownames(annotation_row) = paste("Gene", 1:74, sep = "")
Display column annotations
pheatmap(matrix, annotation_col = annotation_col)
Draw heatmaps
pheatmap(matrix, cluster_rows=T, cluster_cols=F, scale = "row", clustering_distance_rows = "euclidean", gaps_col = c(8, 18, 27, 37, 47, 54), border_color = FALSE, color = colorRampPalette(c("red", "black", "green"))(499), #add this for special color pallette cellwidth = 8, cellheight = 10, main = "DNA repair", fontsize = 12, fontsize_row = 8, fontsize_col = 7)
glad you figured this out... I had the same problem... did not realize that the rownames of the column_annotations had to match with the colnames of the matrix.... I thought it was positional until I found this post.