Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Color legends for VlnPlot and Stacked_VlnPlot #48

Closed
nikofleischer opened this issue Jul 15, 2022 · 5 comments
Closed

Color legends for VlnPlot and Stacked_VlnPlot #48

nikofleischer opened this issue Jul 15, 2022 · 5 comments

Comments

@nikofleischer
Copy link

Hi,
I think this is a known issue, but would it be possible to add functionality for labeling the colors when using split.by in VlnPlots or Stacked_VlnPlots?

Best,
Niko

@samuel-marsh
Copy link
Owner

Hi Niko,

Can you provide example of the issue you are describing?

Best,
Sam

@nikofleischer
Copy link
Author

nikofleischer commented Jul 15, 2022

Hey Sam,
sorry I didn't attach one as I saw you were commenting on the same issue over at the Seurat GitHub explaining that their Function doesn't support this. Here you go with the mwe and resulting plots:

library(Seurat)
library(scCustomize)
library(tidyverse)
data("pbmc_small")
pbmc_small %>% VlnPlot_scCustom(features = rownames(pbmc_small)[1:10])
pbmc_small %>% Stacked_VlnPlot(features = rownames(pbmc_small)[1:10])

ce973b93-e523-4b86-96d7-e7666046c00a
c4aa0213-2343-4522-ac56-e024e269202b

@samuel-marsh
Copy link
Owner

Oh sorry do you just want the legend to appear on the plot?

@nikofleischer
Copy link
Author

nikofleischer commented Jul 15, 2022

Hey,
sorry I messed the example up and forgot the split.by = 'groups' option.
What I actually meant was:

library(Seurat)
library(scCustomize)
library(tidyverse)
library(patchwork)

data("pbmc_small")
p = list()
p[[1]] = pbmc_small %>% VlnPlot_scCustom(features = rownames(pbmc_small)[1:4],split.by = 'groups') + theme(legend.position = 'bottom')
p[[2]] = pbmc_small %>% VlnPlot_scCustom(features = rownames(pbmc_small)[1:4],split.by = 'groups') & theme(legend.position = 'bottom') 
p[[3]] = pbmc_small %>% Stacked_VlnPlot(features = rownames(pbmc_small)[1:4],split.by = 'groups') + theme(legend.position = 'bottom')
p[[4]] = pbmc_small %>% Stacked_VlnPlot(features = rownames(pbmc_small)[1:4],split.by = 'groups') & theme(legend.position = 'bottom')

wrap_plots(p)

Here we can see that & works to add the legend in both cases, but + only works for VlnPlot and not for Stacked.

Originally I thought it also doesn't work with VlnPlot_scCustom, but this was a problem with patchwork and parentheses as I've just realized. Sorry for that.

6db53be2-f45b-4bf6-94b4-266b30010ea2

@samuel-marsh
Copy link
Owner

Hi,

So fix for this is now live in the develop branch v0.7.09926. I chose to solve the issue by adding extra parameter to the function. You can now use plot_legend = TRUE in order to display a single legend so stacked vlnplots.

This parameter is still compatible with ggplot/patchwork theming in order to move/edit legend.

If you run into any issues getting this work please let me know and I'll reopen the issue.

Best,
Sam

library(tidyverse)
library(Seurat)
library(scCustomize)

pbmc <- pbmc3k.SeuratData::pbmc3k.final
pbmc <- UpdateSeuratObject(pbmc)

Stacked_VlnPlot(pbmc, c("FOS", "CD3E"), plot_legend = TRUE)

Stacked_VlnPlot(pbmc, c("FOS", "CD3E"), plot_legend = TRUE) & theme(legend.position = "bottom")

image

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants