zktuong / ktplots

Some tools for plotting single-cell data
https://zktuong.github.io/ktplots/
MIT License
162 stars 31 forks source link

x-axis order using split.by #16

Closed misterygirl2 closed 3 years ago

misterygirl2 commented 3 years ago

Hi,

I used split.by="Experiment" function to list the order of the x-axis labels like the first image, but the order of the x-axis keeps appearing as in the image below. How can I fix it?

Thanks!

스크린샷 2021-04-19 오전 12 10 02

스크린샷 2021-04-19 오전 12 11 39

zktuong commented 3 years ago

Hi @misterygirl2, thank you for alerting me to this.

I've added a fix to this in #17 which I will merge to master once checks are complete.

The way to interact with this once the fix is merged is to change the factor levels of the split.by column in the single-cell data:

library(ktplots)
library(Seurat)
data(kidneyimmune)
data(cpdb_output)

levels(kidneyimmune$Experiment)
#  [1] "PapRCC"  "RCC1"    "RCC2"    "RCC3"    "Teen Tx" "TxK1"    "TxK2"    "TxK3"    "TxK4"    "VHLRCC"  "Wilms1" 
# [12] "Wilms2"  "Wilms3" 

plot_cpdb(cell_type1 = 'B cell', cell_type2 = 'CD4T cell', scdata = kidneyimmune,
    idents = 'celltype', # column name where the cell ids are located in the metadata
    split.by = 'Experiment', # column name where the grouping column is. Optional.
    means = means, pvals = pvals,
    genes = c("XCR1", "CXCL10", "CCL5"))

This is the original, and creates the following plot: image

Now, by adjusting the factor levels in the split.by column in the single-cell data:

kidneyimmune$Experiment <- factor(kidneyimmune$Experiment, levels = c("Wilms2", "TxK1",  "RCC2", "RCC3", "TxK4", "VHLRCC", "Wilms1", "PapRCC", "RCC1",  "Teen Tx", "TxK2", "TxK3",  "Wilms3"))

plot_cpdb(cell_type1 = 'B cell', cell_type2 = 'CD4T cell', scdata = kidneyimmune,
    idents = 'celltype', # column name where the cell ids are located in the metadata
    split.by = 'Experiment', # column name where the grouping column is. Optional.
    means = means, pvals = pvals,
    genes = c("XCR1", "CXCL10", "CCL5"))

we get this plot: image

I will update this thread again once it's been merged.

zktuong commented 3 years ago

Ok it's now been merged. Please re-install and check that ktplots is now version 1.1.10.

Feel free to let me know if there's any other issues.

Thank you,

Kelvin

misterygirl2 commented 3 years ago

It works well! Thanks!!