ncborcherding / scRepertoire

A toolkit for single-cell immune profiling
https://www.borch.dev/uploads/screpertoire/
MIT License
311 stars 54 forks source link

Questions pertaining to issue #235 in clonalDiversity() #449

Closed zoqaiyum closed 6 days ago

zoqaiyum commented 6 days ago

Hi @ncborcherding

First of all, I just want to thank you for your continued patience with my questions and maintenance of this package. I have a follow up question pertaining to issue 235.

Question #1: I had used the Set2 palette from RColorBrewer package for a plot to annotate the 6 categories of my variable called "Group". I am trying to use the same palette to maintain consistency between that plot and the clonalDiversity() plot.

I used the code you provided in issue 235. So far, my code surrounding the colour palette doesn't appear to work.

set2hue <- scales::hue_pal()(length(brewer.pal(8, "Set2")))

clonalDiversity(mergedseurat2, cloneCall = "aa", group.by = "Group") + scale_color_manual(values = set2)

The output graph is using the default palette. Any thoughts on how to implement colours from RColorBrewer?

image

Question #2: I want to figure out why the levels of my categorical variable, "Group", have been reordered alphabetically? The levels in my seurat object that I'm inputting still show = HC PBMC (level 1), axSpA PBMC (level 2), axSpA SFMC (level 3), InEx (level 4), ReA PBMC (level 5) and ReA SFMC (level 6). But, this is not reflected in my clonalDiversity() plot and instead they are now alphabetical. Any thoughts on how to fix this?

ncborcherding commented 6 days ago

Hey @zoqaiyum

Question 1: I had used the Set2 palette from RColorBrewer package for a plot to annotate the 6 categories of my variable called "Group". I am trying to use the same palette to maintain consistency between that plot and the clonalDiversity() plot.

I think this is just an issue of changing the color of the wrong thing, it should be fill:

set2hue <- scales::hue_pal()(length(brewer.pal(8, "Set2")))
clonalDiversity(combined.TCR, 
                cloneCall = "gene") + scale_fill_manual(values = set2hue)
Screenshot 2024-11-21 at 3 21 59 PM

Question 2: I want to figure out why the levels of my categorical variable, "Group", have been reordered alphabetically? The levels in my seurat object that I'm inputting still show = HC PBMC (level 1), axSpA PBMC (level 2), axSpA SFMC (level 3), InEx (level 4), ReA PBMC (level 5) and ReA SFMC (level 6). But, this is not reflected in my clonalDiversity() plot and instead they are now alphabetical. Any thoughts on how to fix this?

Default plotting in ggplot is alphabetical order. We experimented with preserving the factors and had too many issues with users wanting edge cases. The alternative is just to name the custom palette you just defined:

set2hue <- scales::hue_pal()(length(brewer.pal(8, "Set2")))
names(set2hue) <- names(combined.TCR)[c(1,3,5,7,2,4,6,8)]
clonalDiversity(combined.TCR, 
                cloneCall = "gene") + scale_fill_manual(values = set2hue)
Screenshot 2024-11-21 at 3 34 41 PM

Hope that helps, Nick