Just what I wanted. It works perfectly. Thanks a lot!
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("")
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
1 answer
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
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)
Log in to answer this question.