immunarch icon indicating copy to clipboard operation
immunarch copied to clipboard

Is there a way to order my samples in a specific order?

Open peter-yufan-zeng opened this issue 4 years ago • 9 comments

For example, if I visualize my data with vis(.by = cluster, .meta=immdata.opc.tcr$meta), the orders are determined by alphabetical. However, I would like to reorder the group into specific orders (Immune Rich, Mixture, Immune Desert). Is there a way I could do this in R? I have retried rearranging the order of the factors in immdata.opc.tcr$meta, but it doesn't seem to work.

image

Thanks!

peter-yufan-zeng avatar Mar 14 '20 00:03 peter-yufan-zeng

Hi @peter-yufan-zeng

Yes, it is possible using the ggplot2 scale_x_discrete function. Here is the example using the data from the package

data(immdat)
p = repDiversity(immdata$data) %>% vis("Status", immdata$meta)
p + scale_x_discrete(limits = c("MS", "C"))

vadimnazarov avatar Apr 12 '20 14:04 vadimnazarov

This link might help: http://www.cookbook-r.com/Graphs/Axes_(ggplot2)/

vadimnazarov avatar Apr 12 '20 14:04 vadimnazarov

Hi @vadimnazarov thanks for your answer. After my post I used the exact same method to fix the ordering. However, the problem I have is with the Relative Abundance figures (ex. this one you had on your website), where scale_x_discrete no longer works.

image

peter-yufan-zeng avatar Apr 17 '20 03:04 peter-yufan-zeng

Hi @peter-yufan-zeng

can you please provide an R code that you use to do that? Including the repClonality part

vadimnazarov avatar Apr 17 '20 16:04 vadimnazarov

Ping about the sample order on figures @peter-yufan-zeng

vadimnazarov avatar May 04 '20 18:05 vadimnazarov

repClonality(immdata.opc.bcr$data, .method = "homeo", .clone.types = c(Small = .001, Medium = .01, Large = .1, Hyperexpanded = 10)) %>% vis(., .by=c("cluster_order"),.meta=immdata.opc.bcr$meta)+ labs(title = "",subtitle = "") + theme_classic()+ theme(axis.text.x=element_text(angle=45, hjust=1),legend.position = "none") + scale_fill_manual(values = c("Immune Rich" = "#3B4992FF","Mixture"="#EE0000FF","Immune Dessert"="#008B45FF"))+ scale_x_discrete(limits=c("Immune Rich","Mixture","Immune Desert"))+ xlab("") + ylab("Relative abundance (%)")

This is where it breaks down - likely because the x-axis in the right figure is (small, medium, large, hyperexpanded, etc.)

peter-yufan-zeng avatar May 07 '20 01:05 peter-yufan-zeng

Thank you, I will look into it!

vadimnazarov avatar May 07 '20 01:05 vadimnazarov

Oh i did find a crude way around this problem. It seems that the order is based on default alphabetical order, so i just made a new column in .meta and assigned "A", "B","C" to the samples in the order I want them to be, which would then output in the right order.

peter-yufan-zeng avatar May 07 '20 01:05 peter-yufan-zeng

Hi @peter-yufan-zeng

  1. In order to re-shuffle in the left relative abundance plot (per-sample), you can provide just the names of the datasets (in this example I provide them in a random order):
data(immdata)
p <- repClonality(immdata$data, "homeo") %>% vis()
p <- p + scale_x_discrete(limits= sample(names(immdata$data), length(immdata$data), FALSE))
p
  1. Regarding the second plot. Our team will work on the more powerful ordering, thank you! I will leave this issue open until we implement this. You provided a very good workaround, thank you! And using functions such as scale_x_discrete it is possible to rename group names in the legend and of x/y axis.

vadimnazarov avatar May 10 '20 23:05 vadimnazarov