I have performed a Seurat PCA via Dimplot.
How do I extend the x axis?
Bioinformatics Stack Exchange is a question and answer site for researchers, developers, students, teachers, and end users interested in bioinformatics. It only takes a minute to sign up.Sign up to join this community
Looking at the source code for Seurat's
DimPlot() it's based on ggplot2 graphics (https://github.com/satijalab/seurat/blob/HEAD/R/visualization.R#L794), so you can manipulate the dimplot object and save it using ggplot2 commands. Using
ggsave() you can specify the figure dimensions; if you increase the width of the final figure it should 'fix' your label overlap issue, i.e.
#BiocManager::install("Seurat") library(Seurat) #> Attaching SeuratObject library(ggplot2) # for plotting library(cowplot) # for the theme used by Seurat # example data data("pbmc_small") p <- DimPlot(object = pbmc_small, split.by = "ident") # example dimplot p
# increase font size to make the labels overlap p + theme_cowplot(font_size = 28) + theme(strip.background = element_blank())
# save the 'overlapping label' figure and specify a relatively large width to 'space out' the three facets ggsave("dimplot_test.png", width = 40, height = 10, units = "cm")
You could also decrease the font size and keep the original dimensions to fix the problem, or alter the breaks on the x axis, e.g.
# reduce the size of the x axis text labels p + theme_cowplot() + theme(strip.background = element_blank(), axis.text.x = element_text(size = 8))
# change the number of breaks p + theme_cowplot() + theme(strip.background = element_blank()) + scale_x_continuous(breaks = scales::pretty_breaks(n = 2))
# Specify the breaks you want to use p + theme_cowplot() + theme(strip.background = element_blank()) + scale_x_continuous(breaks = c(-20, 0, 20, 40))
Created on 2022-12-01 with reprex v2.0.2