This is a test version of Biostars. For the public version, visit https://www.biostars.org.
Change Heatmap Labels from ENSDAR to Gene_Names in correct order

Hello All

I want to change the labels of my heatmap from ENSDAR_IDs to Gene Names. The Heatmap I initially produce with ENSDAR_IDs can be seen in (Fig.1). I have a list of gene names List_Gene_Names, Which I want to use as labels instead of the ENSDAR_IDs so that my Heatmap will look as in (Fig. 2). However, when I use my List_Gene_Names in the following code Code_To_Change_Labels my new Gene_Name labels become randomly located on the heatmap as can be seen in (Fig. 3)

Question: How can I add my List_Gene_Names in the correct order to my Heatmap?

Note: Fig. 2 is made with the following code: Code_For_(Fig. 2). However, this code is not. Feasible for heatmaps with 200+ labels, as I manually typed it in.

> List_Gene_Names

[1]  "FO704772.2" "FO704772.1" "atp5pd"     "ndufa4l"    "CR383676.2" "nme2b.2"    "cox7c"      "RPL37A"     "hspa5"     
[10]  "zgc:162730" "sorbs1"     "hspb7" 

# Code_To_Change_Labels

p4 <- DoHeatmap(zf_AR, features = top2$gene)

p4 + theme(legend.position="right", text = element_text(size = 10))

p4 + scale_y_discrete(labels = **List_Gene_Names**)


# Code_For_(Fig. 2)

p4 + scale_y_discrete(labels = c("ENSDARG00000116076" = "FO704772.2", "ENSDARG00000114910" = "FO704772.1", "ENSDARG00000098355" = "atp5pd",
                                 "ENSDARG00000099499" = "ndufa4l", "ENSDARG00000099970" = "CR383676.2", "ENSDARG00000099420" = "nme2b.2",
                                 "ENSDARG00000104537" = "cox7c", "ENSDARG00000115271" = "RPL37A", "ENSDARG00000103846" = "hspa5",
                                 "ENSDARG00000103720" = "zgc:162730", "ENSDARG00000103435" = "sorbs1", "ENSDARG00000104441" = "hspb7") )

Fig. 1 Fig 1

Fig. 2 Fig 2

Fig. 3 Fig 3

Best Regards

Kristian Andersen

rna-seq r

Without knowing what DoHeatmap actually does, it's difficult to give a precise answer, but I would recommend to change the names in the zf_AR object already. Can you post the result of head(zf_AR) and str(zf_AR) here?

Hello Friederike

Here are the head(zf_AR) and some of str(zf_AR) result. Let me know if you need more information, I'm quite new at working with R and scRNAseq analysis.

Best Regards Kristian Andersen

> head(zf_AR)

Warning: The following arguments are not used: drop

An object of class Seurat 

6 features across 1959 samples within 1 assay

Active assay: RNA (6 features, 0 variable features)

1 dimensional reduction calculated: tsne
>str(zf_AR)

Formal class 'Seurat' [package "Seurat"] with 13 slots

  ..@ assays      :List of 1

  .. ..$ RNA:Formal class 'Assay' [package "Seurat"] with 8 slots

  .. .. .. ..@ counts       :Formal class 'dgCMatrix' [package "Matrix"] with 6 slots

  .. .. .. .. .. ..@ i       : int [1:2183138] 4 12 13 14 17 22 25 30 34 38 ...

  .. .. .. .. .. ..@ p       : int [1:1960] 0 2244 2863 3145 4457 5079 5806 6058 6958 8285 ...

  .. .. .. .. .. ..@ Dim     : int [1:2] 16957 1959

  .. .. .. .. .. ..@ Dimnames:List of 2

  .. .. .. .. .. .. ..$ : chr [1:16957] "ENSDARG00000102141" "ENSDARG00000114503" "ENSDARG00000098311" "ENSDARG00000102474" ...

  .. .. .. .. .. .. ..$ : chr [1:1959] "AAACCCAGTGCATTAC-1" "AAACCCATCTTGATTC-1" "AAACGAAAGAGGGCGA-1" "AAACGAATCGTGCTCT-1" ...

  .. .. .. .. .. ..@ x       : num [1:2183138] 2 1 1 2 25 1 2 1 4 1 ...

  .. .. .. .. .. ..@ factors : list()

  .. .. .. ..@ data         :Formal class 'dgCMatrix' [package "Matrix"] with 6 slots

  .. .. .. .. .. ..@ i       : int [1:2183138] 4 12 13 14 17 22 25 30 34 38 ...

  .. .. .. .. .. ..@ p       : int [1:1960] 0 2244 2863 3145 4457 5079 5806 6058 6958 8285 ...

  .. .. .. .. .. ..@ Dim     : int [1:2] 16957 1959

  .. .. .. .. .. ..@ Dimnames:List of 2

  .. .. .. .. .. .. ..$ : chr [1:16957] "ENSDARG00000102141" "ENSDARG00000114503" "ENSDARG00000098311" 
"ENSDARG00000102474" ...

  .. .. .. .. .. .. ..$ : chr [1:1959] "AAACCCAGTGCATTAC-1" "AAACCCATCTTGATTC-1" "AAACGAAAGAGGGCGA-1" "AAACGAATCGTGCTCT-1" ...

  .. .. .. .. .. ..@ x       : num [1:2183138] 0.0676 0.0344 0.0344 0.0676 0.6285 ...

  .. .. .. .. .. ..@ factors : list()

  .. .. .. ..@ scale.data   : num [1:16957, 1:1959] -0.0354 -0.0792 -0.0253 -0.0777 1.0524 ...

  .. .. .. .. ..- attr(*, "dimnames")=List of 2

  .. .. .. .. .. ..$ : chr [1:16957] "ENSDARG00000102141" "ENSDARG00000114503" "ENSDARG00000098311" "ENSDARG00000102474" ...

  .. .. .. .. .. ..$ : chr [1:1959] "AAACCCAGTGCATTAC-1" "AAACCCATCTTGATTC-1" "AAACGAAAGAGGGCGA-1" "AAACGAATCGTGCTCT-1" ...

  .. .. .. ..@ key          : chr "rna_"

  .. .. .. ..@ assay.orig   : NULL

  .. .. .. ..@ var.features : chr [1:2000] "ENSDARG00000089087" "ENSDARG00000020711" "ENSDARG00000038424" "ENSDARG00000070780" ...

  .. .. .. ..@ meta.features:'data.frame':  16957 obs. of  5 variables:

  .. .. .. .. ..$ vst.mean                 : num [1:16957] 0.00459 0.0148 0.00306 0.04135 0.17509 ...

  .. .. .. .. ..$ vst.variance             : num [1:16957] 0.00458 0.01561 0.00305 0.06009 0.41417 ...

  .. .. .. .. ..$ vst.variance.expected    : num [1:16957] 0.00545 0.02094 0.00337 0.06931 0.51105 ...

  .. .. .. .. ..$ vst.variance.standardized: num [1:16957] 0.839 0.746 0.906 0.867 0.81 ...

  .. .. .. .. ..$ vst.variable             : logi [1:16957] FALSE FALSE FALSE FALSE FALSE FALSE ...

It doesn't look like the order is random, but reversed from what you wanted. Try List_Gene_Names <- rev(List_Gene_Names).

0 answers

No answers yet.

Log in to answer this question.