Is it possible to modify the gene names from the x-axis in Seurat::Dotplot?
1
0
Entering edit mode
5 months ago
ev97 ▴ 40

I have generated some dotplots for some genes in my scRNAseq data.

As the Seurat object was already annotated with Ensembl IDs (and not gene names), I am struggling a bit trying to replace those IDs to gene names in my plots.

In this context, I am trying to generate a DotPlot for two genes at the same time and although I have tried to specify the gene name, I only managed to put it as a title and not replace it at the bottom (in the x-axis).

Seurat::DotPlot(seuObject,
                    features = list("Gene1" = "ENSXXXXXXXXXX",  "Gene2" = "ENSXXXXXXXXXXX"),  group.by  = "Conditions") + 
        labs(title = "Gene1 & Gene2") + xlab("")

enter image description here

Does anybody know how I could remove the Ensembl IDs (ENSGXXXXX) from the bottom and instead writing the gene names (that I have at the top) in this type of plot?

Thanks very much in advance

seurat scRNA-seq single-cell dotplot • 988 views
ADD COMMENT
2
Entering edit mode
5 months ago
bk11 ★ 3.0k

Here is how you can change the genes names in DotPlot-

rm(list=ls())
# Load necessary libraries
library(Seurat)
library(SeuratData)
library(ggplot2)
library(patchwork)

data=UpdateSeuratObject(pbmc3k.final)

# Assume 'seurat_object' is your Seurat object and 'genes' is the list of genes you are plotting
genes <- c("MS4A1", "TAL1", "IPP")

# Create a DotPlot
p1 <- DotPlot(data, features = genes) + theme(axis.text.x = element_text(angle = 45, hjust = 1))
dot_plot <- DotPlot(data, features = genes)

# Custom gene labels - ensure this vector is in the same order as 'genes'
custom_labels <- c("Custom_Label1", "Custom_Label2", "Custom_Label3")

# Replace the gene names in the plot
dot_plot$data$features.plot <- factor(dot_plot$data$features.plot, 
                                      levels = genes, 
                                      labels = custom_labels)

# Display the modified DotPlot
p2 <- dot_plot + theme(axis.text.x = element_text(angle = 45, hjust = 1))

p1|p2

enter image description here

ADD COMMENT
0
Entering edit mode

Just what I wanted. It works perfectly. Thanks a lot!

ADD REPLY
0
Entering edit mode

Just in case someone gets to this post with the same question but using SCpubr::do_DotPlot, you can use the same accepted answer adding an extra line of code:

dot_plot$data$features.plot <- factor(dot_plot$data$features.plot, 
                                      levels = genes, 
                                      labels = custom_labels)

 #addition
p <- p + scale_x_discrete(labels = genes)
ADD REPLY

Login before adding your answer.

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