microeco icon indicating copy to clipboard operation
microeco copied to clipboard

figure RF-correlation with env variables

Open jamorillo opened this issue 2 years ago • 9 comments

Hello again, I know that this is perhaps not exactly an "issue", but it is an intereting point about a plot that I I think it shoud be doable with the nice microeco package. I am trying to reproduce the Fig.5 of the paper Jiaxing An et al. (Geoderma 2019). (https://www.sciencedirect.com/science/article/pii/S0016706118304798) I can get the 3 pannels easily (RF rank, diffabubd plot and correlations with env variables). But in order to combine them, I need to order the taxa in the third pannel (env corr) in the same order than the other two plots. How could I do that? I guess that I need to manipulate the third pannel (env corr) as ggplot object, but for that I would need to get the taxa order of the previous two pannels and I dont know how. Thanks again! Jose PD: we are preparing a manuscript, we are happy of course to cite Microeco and add cite you and this forum in the acknowledgments section for helping us with this figure.

jamorillo avatar Mar 11 '22 10:03 jamorillo

Hi @jamorillo

Thanks for your 'issue'. After checking this part again, I find that the y axis text can not be adjusted in the previous package version as both x and y axis are treated with the clustering. So I add a new parameter text_y_order to get customized order of y axis text. I have updated the package in github. You can reinstall it from github. But this version is v0.7.0 which will be released in the next couple of weeks. So there may be some differences between this version and v0.6. If some errors occur in your other scipts, you can check the help document or go back to v0.6.5. Please feel free to tell me if you have other issues. The following is my testing code:

`library(microeco) library(magrittr) library(ggplot2) set.seed(123) data(dataset) data(env_data_16S) t2 <- trans_diff$new(dataset = dataset, method = "rf", group = "Group", rf_taxa_level = "Genus") t1 <- trans_env$new(dataset = dataset, add_data = env_data_16S[, 4:11]) t1$cal_cor(use_data = "other", p_adjust_method = "fdr", other_taxa = t2$res_rf$Taxa[1:40]) t1$plot_cor()

new_order <- t2$res_rf$Taxa[1:40] %>% gsub(".*\|", "", .) t1$plot_cor(text_y_order = new_order) `

Chi

ChiLiubio avatar Mar 12 '22 06:03 ChiLiubio

Hi Chi, Thanks a lot for providing a solution and including the new functionality! I have updated to v0.7.0 but for some reason I get the following error: new_order <- t2$res_rf$Taxa[1:40] %>% gsub(".|", "", .) Error: '|' is an unrecognized escape in character string starting "".|" cheers jose

jamorillo avatar Mar 12 '22 19:03 jamorillo

Hi @jamorillo Sorry for that the code I paste was changed because of the escape character. I did not check the page yesterday because of the bad internet. I rewrite this part:

rm(list = ls())
library(microeco)
library(magrittr)
library(ggplot2)
set.seed(123)
data(dataset)
data(env_data_16S)

t2 <- trans_diff$new(dataset = dataset, method = "rf", group = "Group", rf_taxa_level = "Genus")
t1 <- trans_env$new(dataset = dataset, add_data = env_data_16S[, 4:11])
t1$cal_cor(use_data = "other", p_adjust_method = "fdr", other_taxa = t2$res_rf$Taxa[1:40])
t1$plot_cor()

new_order <- t2$res_rf$Taxa[1:40] %>% gsub(".*\\|", "", .)
t1$plot_cor(text_y_order = new_order)

ChiLiubio avatar Mar 13 '22 01:03 ChiLiubio

Now It is ok. The new_order is the names with new order we want to pass to the new plot. So we directly take and trim them from t2$res_rf$Taxa according to the MeanDecreaseGini value. The final gsub is used to trim the long prefix to make them same with the text of names in the first plot we do.

Chi

ChiLiubio avatar Mar 13 '22 02:03 ChiLiubio

Great, I have a draft figure. Thanks a lot for all this! There few aesthetics issues yet, but I dont want to bother you more, I will try alternatives. Greetings from Spain (EEZA-CSIC). I am postdoc working on soil microbiology. Cheers, jose

jamorillo avatar Mar 14 '22 09:03 jamorillo

Please feel free to tell me if you have other new ideas or issues. This can make the project better. Thanks in advance. Good luck! Chi

ChiLiubio avatar Mar 14 '22 12:03 ChiLiubio

Hello, Just a quick question following this analysis. Is it possible to perform RT and heatmap correlation analysis (the same kind of figure) at ASV (or OTU) level? thanks again! cheers jose

jamorillo avatar Mar 16 '22 15:03 jamorillo

Sure. Please first run the add_rownames2taxonomy function of your microtable object, which can add the ASV/OTU names as the taxa in the taxonomic table. Then run cal_abund function and the ASV/OTU level will be in the taxa_abund list like other levels. Then you can do anything like other taxonomic level.

Chi

ChiLiubio avatar Mar 17 '22 02:03 ChiLiubio

Great. I will follow that way. Very clear. Thanks! jose

jamorillo avatar Mar 18 '22 09:03 jamorillo