Open peter-yufan-zeng opened 4 years ago
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"))
This link might help: http://www.cookbook-r.com/Graphs/Axes_(ggplot2)/
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.
Hi @peter-yufan-zeng
can you please provide an R code that you use to do that? Including the repClonality
part
Ping about the sample order on figures @peter-yufan-zeng
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.)
Thank you, I will look into it!
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.
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
2) 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.
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.
Thanks!