Question: Pheatmap error: 'gpar' element 'fill' must not be length 0 , what to do about that in an assymmetrical matrix
9
gravatar for emil.bb
3.5 years ago by
emil.bb170
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(
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

blog pheatmap R • 25k views
ADD COMMENTlink modified 3.5 years ago • written 3.5 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 3.5 years ago by Jean-Karim Heriche23k
12
gravatar for e.rempel
3.5 years ago by
e.rempel890
Germany, Heidelberg, COS
e.rempel890 wrote:

I added rownames to the annotation_c data frame

rownames(annotation_c) <- colnames(DAT)

and your script worked.

ADD COMMENTlink modified 3 months ago by zx87549.6k • written 3.5 years ago by e.rempel890
Please log in to add an answer.

Help
Access

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