Seurat: How to make the same xlim and ylim in FeaturePlot with multiple genes?

Created on 1 May 2020  路  2Comments  路  Source: satijalab/seurat

Hi,

How can I make the same x and y scale for all six figures when I use the command below? Now, only the last figure (i.e., Dio2 gene) shows the x and y scale I need, i.e., xlim(-1,10), ylim(-7,10). Many thanks.

FeaturePlot(dermis, features = c("Sox2","Lef1","Alx4","Corin","Hey2","Dio2"), pt.size = 0.5, label = TRUE, label.size = 5, min.cutoff= c(0,0.5,0.5,0,0,0.5), ncol = 3, order = TRUE) + xlim(c(-1,10)) +ylim(c(-7,10))

20200501_Seurat_FeaturePlot_XlimYlim

Best,

Gary

Most helpful comment

Hi,

I would add two things. First is that by default Seurat now uses patchwork to combine plots when supplying multiple features. Therefore to supply additional modifications to all plots and not just the final one you can use the & to supply those additional calls:
FeaturePlot(dermis, features = c("Sox2","Lef1","Alx4","Corin","Hey2","Dio2"), pt.size = 0.5, label = TRUE, label.size = 5, min.cutoff= c(0,0.5,0.5,0,0,0.5), ncol = 3, order = TRUE) & xlim(c(-1,10)) & ylim(c(-7,10))

The other solution posted above also works but the second thing I would add is that as Seurat has moved to patchwork system CombinePlots is being deprecated and new way of implementing that same code using patchwork is:
wrap_plots(plist, ncol = 3)

Best,
Sam

All 2 comments

You may try the way below (there should be better way no need to crack the object), the point is setting combine=F to let FeaturePlot return a list of ggplot2 objects, then you can manipulate each of them.

library(Seurat)
library(SeuratData)
data("pbmc3k")

pbmc3k <- NormalizeData(pbmc3k)
pbmc3k <- ScaleData(pbmc3k, features = rownames(pbmc3k))
pbmc3k <- FindVariableFeatures(pbmc3k, selection.method = "vst", nfeatures = 2000)
pbmc3k <- RunPCA(pbmc3k, features = VariableFeatures(object = pbmc3k))
pbmc3k <- RunUMAP(pbmc3k, dims = 1:10)

# default xlim, ylim
FeaturePlot(pbmc3k, features=c("IL7R","CCR7","S100A4","CD14","LYZ","MS4A1"), pt.size = 0.5, label = TRUE, label.size = 5, min.cutoff= c(0,0.5,0.5,0,0,0.5), ncol = 3, order = TRUE)

tmp1

# modify list of ggplot2 objects of FeaturePlot()

library(ggplot2)
plist <- FeaturePlot(pbmc3k, features=c("IL7R","CCR7","S100A4","CD14","LYZ","MS4A1"), pt.size = 0.5, label = TRUE, label.size = 5, min.cutoff= c(0,0.5,0.5,0,0,0.5), ncol = 3, order = TRUE, combine=FALSE)
plist <- lapply(plist, function(g) {
    g + xlim(c(-1,10)) +ylim(c(-7,10))
})
CombinePlots(plist, ncol=3)

tmp2

Hi,

I would add two things. First is that by default Seurat now uses patchwork to combine plots when supplying multiple features. Therefore to supply additional modifications to all plots and not just the final one you can use the & to supply those additional calls:
FeaturePlot(dermis, features = c("Sox2","Lef1","Alx4","Corin","Hey2","Dio2"), pt.size = 0.5, label = TRUE, label.size = 5, min.cutoff= c(0,0.5,0.5,0,0,0.5), ncol = 3, order = TRUE) & xlim(c(-1,10)) & ylim(c(-7,10))

The other solution posted above also works but the second thing I would add is that as Seurat has moved to patchwork system CombinePlots is being deprecated and new way of implementing that same code using patchwork is:
wrap_plots(plist, ncol = 3)

Best,
Sam

Was this page helpful?
0 / 5 - 0 ratings

Related issues

milanmlft picture milanmlft  路  3Comments

RuiyangLiu94 picture RuiyangLiu94  路  3Comments

kathirij picture kathirij  路  3Comments

farhanma picture farhanma  路  3Comments

tmccra2 picture tmccra2  路  3Comments