Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ord_val arg to tsg_ind #2

Open
jennbaker95 opened this issue Oct 2, 2020 · 0 comments
Open

Add ord_val arg to tsg_ind #2

jennbaker95 opened this issue Oct 2, 2020 · 0 comments
Assignees
Labels
bug Something isn't working help wanted Extra attention is needed

Comments

@jennbaker95
Copy link
Collaborator

Problem: When plotting individual values using geom_jitter on top of ranked relative abundance geom_col layer using obs_df arg in plot_ra, ordering of the OTUs on the xaxis (determined by ord_val in taxon_sort_gather df prep) is not preserved. Instead, the individual values layer (which is not ranked in any certain order - defaults to alphanumeric ordering) also forces the plot_ra output to revert to alphanumeric & overwrites the order of the geom_col layer.

mock.gg.mean <- dplyr::filter(otu_df, Type == "Mock") %>% 
                taxon_sort_gather(n=20)
mock.gg <- dplyr::filter(otu_df, Type == "Mock") %>% 
           tsg_ind(n=20, sample_col = "Uniq_ID")
plot_ra(df = mock.gg.mean, df_obs = mock.gg, title = "Mean Ranked Relative Abundance for Mock Positive Controls, Both Runs", fill = "OTU", error_bar = TRUE) + theme(axis.text.x = element_text(angle = 45, hjust = 1, vjust=1), legend.position = "top", plot.margin=unit(c(0.5,0.5,0.5,4), "cm"))

image

Proposed Solution: Add an ord_val argument and option in tsg_ind to prepare two dfs that have matching ordering. I fixed this problem outside of a user-defined function by modifying source code from taxon_sort_gather.

gg.alltissues.ceft.95 <- filter(otu_df, !is.na(Organ) & Exp_Group == "Ceftriaxone + 95%") 

ord_df <- dplyr::filter(gg.alltissues.ceft.95, Type=="Lung")
otu_order <- rank_tax(ord_df)
gg.alltissues.ceft.95.ind <- data.frame(dplyr::select_if(gg.alltissues.ceft.95,!(stringr::str_detect(colnames(otu_df), "Otu"))), gg.alltissues.ceft.95[, otu_order[1:50]]) %>% 
        join_tax(tax_levels = "Phylum", tax_df = otu_good_taxonomy) %>% 
        dplyr::group_by(OTU, Phylum, Type)
gg.alltissues.ceft.95.ind <- tsg_ind(gg.alltissues.ceft.95.ind, sample_col = "Uniq_ID") 

gg.alltissues.ceft.95.ordL <- taxon_sort_gather(gg.alltissues.ceft.95, facet_var="Type", ord_val = "Lung")

plot_ra(gg.alltissues.ordL, fill = "Type", error_bar = T, df_obs = gg.alltissues.ceft.95.ind) + facet_grid(Type~.) 
@jennbaker95 jennbaker95 added bug Something isn't working help wanted Extra attention is needed labels Oct 2, 2020
cb-42 added a commit that referenced this issue Oct 14, 2020
Updated tsg_ind() to clarify the purpose of the otu_ord param. This can be used to ensure the OTU levels within tsg_ind() match the levels from taxon_sort_gather()

#2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants