Annotation in pheatmap
1
0
Entering edit mode
Rob • 0
@9a3af295
Last seen 16 months ago
United Kingdom

I want to add the annotation row labelling to a pheatmap.

It appears from the tutorial here: https://towardsdatascience.com/pheatmap-draws-pretty-heatmaps-483dab9a3cc

That I can call a data frame in order to do this.

Here is my data frame:


               Sample Condition
1    Sample_Run1HR62_S1_Run1    groupa
2    Sample_Run2HR62_S1_Run2    groupa
3    Sample_Run1HR70_S2_Run1    groupa
4    Sample_Run2HR70_S2_Run2    groupa
5    Sample_Run1HR78_S3_Run1    groupa
6    Sample_Run2HR78_S3_Run2    groupa
7    Sample_Run1HR81_S4_Run1    groupa
8    Sample_Run2HR81_S4_Run2    groupa
9    Sample_Run1HR87_S5_Run1    groupa
10   Sample_Run2HR87_S5_Run2    groupa
11   Sample_Run1HR99_S6_Run1    groupa
12   Sample_Run2HR99_S6_Run2    groupa
13  Sample_Run1HR107_S7_Run1    groupa
14  Sample_Run2HR107_S7_Run2    groupa
15  Sample_Run1HR114_S8_Run1    groupa
16  Sample_Run2HR114_S8_Run2    groupa
17 Sample_Run1HR142_S17_Run1    groupa
18 Sample_Run2HR142_S17_Run2    groupa
19 Sample_Run1HR146_S18_Run1    groupa
20 Sample_Run2HR146_S18_Run2    groupa
21   Sample_Run1HR61_S9_Run1    groupb
22   Sample_Run2HR61_S9_Run2    groupb
23  Sample_Run1HR71_S11_Run1    groupb
24  Sample_Run2HR71_S11_Run2    groupb
25  Sample_Run1HR74_S41_Run1    groupb
26  Sample_Run2HR74_S41_Run2    groupb
27  Sample_Run1HR80_S12_Run1    groupb
28  Sample_Run2HR80_S12_Run2    groupb
29  Sample_Run1HR86_S13_Run1    groupb
30  Sample_Run2HR86_S13_Run2    groupb
31 Sample_Run1HR115_S14_Run1    groupb
32 Sample_Run2HR115_S14_Run2    groupb
33 Sample_Run1HR121_S15_Run1    groupb
34 Sample_Run2HR121_S15_Run2    groupb
35 Sample_Run1HR127_S16_Run1    groupb
36 Sample_Run2HR127_S16_Run2    groupb
37  Sample_Run2HR66_S10_Run2    groupb
38  Sample_Run1HR66_S10_Run1    groupb

Here is the r script I am using to generate the Pheatmap:

# Create sample-sample heatmap
sampleDists <- dist(t(assay(rld))) #calculates Euclidean distance. Rld to ensure we have a roughly equal contribution from all genes
sampleDistMatrix <- as.matrix( sampleDists )
rownames(sampleDistMatrix) <- paste( targets$Sample, sep = " - " )
colnames(sampleDistMatrix) <- NULL
colors <- colorRampPalette( rev(brewer.pal(9, "Blues")) )(255)
pheatmap(sampleDistMatrix, clustering_distance_rows = sampleDists, clustering_distance_cols = sampleDists,col = colors, main = "Heatmap of Sample to Sample Distances in Pig Samples" )

Here is the same code when I add the 'annotation_row' command:

# Create sample-sample heatmap
sampleDists <- dist(t(assay(rld))) #calculates Euclidean distance. Rld to ensure we have a roughly equal contribution from all genes
sampleDistMatrix <- as.matrix( sampleDists )
rownames(sampleDistMatrix) <- paste( targets$Sample, sep = " - " )
colnames(sampleDistMatrix) <- NULL
colors <- colorRampPalette( rev(brewer.pal(9, "Blues")) )(255)
pheatmap(sampleDistMatrix, clustering_distance_rows = sampleDists, clustering_distance_cols = sampleDists,col = colors,annotation_row = targets, main = "Heatmap of Sample to Sample Distances in Pig Samples" )

Here is the error generated from this:

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

Any help would be greatly appreciated

pheatmap • 2.2k views
ADD COMMENT
0
Entering edit mode
Guido Hooiveld ★ 3.9k
@guido-hooiveld-2020
Last seen 26 minutes ago
Wageningen University, Wageningen, the …

Please note that pheatmap is not a Bioconductor package. Having said this, why do you explicitly set colnames(sampleDistMatrix) <- NULL ? I would not be surprised if this is the cause of the error. You rather could add this argument when calling pheatmap: show_colnames = FALSE. See the help pages for pheatmap (type ?pheatmap) for all arguments that can be set (you will see there are many...).

ADD COMMENT

Login before adding your answer.

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