Pheatmap error: 'gpar' element 'fill' must not be length 0 , what to do about that in an assymmetrical matrix
2
10
Entering edit mode
7.8 years ago
emil.bb ▴ 180

Hi there,

I'm trying to create a pheatmap with annotationcolors based on groups. I'm an sociologist, so this might not be the common way to use pheatmap, but I found it to be great at displaying social groups as well. But,, when I try to plot an assymmetrical matrix, where the rows and columns do not match, I get an error:

Error in check.length("fill") : 
  'gpar' element 'fill' must not be length 0

The issue is also tackled here, but as I understand it, the solution is to make sure rownames and colnames are identical. Which isn't possible for my purpose.

here is an reproducible example:

DAT <- matrix(c(
771,1176,1018,1042,275,949,823,1250,348,622,1244,
465,984,766,790,573,784,592,1250,1222,421,1103,
171,288,194,80,547,528,249,959,72,81,224,
132,122,90,50,44,206,127,108,52,59,144,
0,9,5,9,0,10,17,0,0,0,0),
           nrow = 5, ncol = 11, byrow = TRUE)

group <-  c("grp1","grp2","grp3","grp4","grp5","grp6","grp7","grp8","grp9","grp9","grp9")

annotation_c <- as.data.frame(group)

colnames(DAT) <- paste(group," ", "no.",seq_len(11),sep="")
rownames(DAT) <- paste(rep(c("grp"),5),91:95,sep="_")

# annotation_r <- as.data.frame(rownames(DAT))

pheatmap::pheatmap(DAT, color = colorRampPalette(rev(brewer.pal(n = 7, name = "RdYlBu")))(length(seq_len(10))), cluster_cols=FALSE,cluster_rows=FALSE ,  
    annotation_col=annotation_c)

Thank you for your time,
Emil

pheatmap R • 55k views
ADD COMMENT
0
Entering edit mode

From this other post you refer to, it seems you also need the grid package installed. Did you do that ? If really symmetry is a problem with pheatmap, there are plenty of R functions/packages for heatmaps. For example, both heatmap() and heatmap.2() have a symm parameter to indicate whether the matrix is symmetric.

ADD REPLY
16
Entering edit mode
7.8 years ago
e.rempel ★ 1.1k

I added rownames to the annotation_c data frame

rownames(annotation_c) <- colnames(DAT)

and your script worked.

ADD COMMENT

Login before adding your answer.

Traffic: 1602 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