Question: Pheatmap error: 'gpar' element 'fill' must not be length 0 , what to do about that in an assymmetrical matrix
gravatar for
4.0 years ago by
Copenhagen, Denmark
emil.bb170 wrote:

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(
           nrow = 5, ncol = 11, byrow = TRUE)

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

annotation_c <-

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

# annotation_r <-

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

Thank you for your time,


blog pheatmap R • 29k views
ADD COMMENTlink modified 4.0 years ago • written 4.0 years ago by emil.bb170

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 REPLYlink written 4.0 years ago by Jean-Karim Heriche24k
gravatar for e.rempel
4.0 years ago by
Germany, Heidelberg
e.rempel1000 wrote:

I added rownames to the annotation_c data frame

rownames(annotation_c) <- colnames(DAT)

and your script worked.

ADD COMMENTlink modified 9 months ago by zx87549.9k • written 4.0 years ago by e.rempel1000
Please log in to add an answer.


Use of this site constitutes acceptance of our User Agreement and Privacy Policy.
Powered by Biostar version 2.3.0
Traffic: 1494 users visited in the last hour