2

Is there a general way to include legends in Seurat graphs? For example, if my code is,

DimHeatmap(norm_data3, dims = 1, cells = 500, balanced = TRUE)

how can I include a legend with color corresponding to value of PCA component?

algebroo
  • 132
  • 6
  • 1
    Could you please share some reproducible data using `dput`? – Quinten Jun 30 '22 at 12:56
  • 1
    It's easier to help you if you provide a [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) with sample input that can be used to test and verify possible solutions. – MrFlick Jun 30 '22 at 12:57

1 Answers1

2

It is a bit vague, but you should set fast = FALSE:

If true, use image to generate plots; faster than using ggplot2, but not customizable

Here is a reproducible example using the pbmc_small dataset from the Seurat pacakage:

library(Seurat)
#> Warning: package 'Seurat' was built under R version 4.1.2
#> Attaching SeuratObject
#> Attaching sp
data("pbmc_small")
DimHeatmap(pbmc_small, dims = 1, cells = 500, balanced = TRUE, nfeatures = 4, fast = FALSE)
#> Warning: Requested number is larger than the number of available items (80).
#> Setting to 80.

Created on 2022-06-30 by the reprex package (v2.0.1)

Quinten
  • 35,235
  • 5
  • 20
  • 53
  • Thank you so much! Is there a way to do this with ggplot also? – algebroo Jun 30 '22 at 13:13
  • @AryanDugar, No problem! You mean creating a heatmap using `ggplot`? – Quinten Jun 30 '22 at 13:14
  • Sorry, nevermind. I just read that setting ''' fast = false ''' makes it use ggplot2. I also wanted to ask more broadly, is there a general way to customize plots (so that we can adjust their titles and legends) in Seurat? Something like calling a function that creates a plot, and then doing ''' + geom_raster ''' ...? I understand if this might be suitable as another question, but I wanted to check with you anyway! – algebroo Jun 30 '22 at 13:19