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

Plot options for beta_2d/3d_plot and taxa_abundance_box_plot methods #39

Closed
khemlalnirmalkar opened this issue Apr 12, 2022 · 13 comments · Fixed by #42
Closed

Plot options for beta_2d/3d_plot and taxa_abundance_box_plot methods #39

khemlalnirmalkar opened this issue Apr 12, 2022 · 13 comments · Fixed by #42
Labels
enhancement New feature or request

Comments

@khemlalnirmalkar
Copy link

khemlalnirmalkar commented Apr 12, 2022

Hi @sbslee

Recently, I noticed two minor things on Dokdo and thought you could help

  1. beta_3D_plot doesn't have an option for colors, if possible please can you add
  2. initially, I used to use the add_datapoints option for box plots, it's not working anymore

Thanks

@sbslee
Copy link
Owner

sbslee commented Apr 12, 2022

@khemlalnirmalkar,

Thanks for the issue.

As for beta_3d_plot, the hue option already gives you the control to color data points according to the specified group (e.g. hue='body-site'):

import dokdo
import matplotlib.pyplot as plt
%matplotlib inline
import seaborn as sns
sns.set()
qza_file = '/Users/sbslee/Desktop/dokdo/data/moving-pictures-tutorial/unweighted_unifrac_pcoa_results.qza'
metadata_file = '/Users/sbslee/Desktop/dokdo/data/moving-pictures-tutorial/sample-metadata.tsv'
dokdo.beta_3d_plot(qza_file,
                   metadata=metadata_file,
                   hue='body-site',
                   figsize=(8, 8))
plt.tight_layout()

beta-3d-plot

Is this what you want?

And for add_datapoints of taxa_abundance_box_plot, this option was deprecated in 1.11.0 (see CHANGELOG) because it was making the code unnecessarily complicated. If you think having this option is important, I will consider bringing it back. Could you please explain to me what's your use case?

@khemlalnirmalkar
Copy link
Author

@sbslee
For the beta_3D plot, i can't control the colors, e.g. if i want "gut" in red and "tongue" in blue, i can't do that. If I compare with bar plot where it allows me to use RGB color codes to choose the bacteria. it would be great to control the colors for other plots too.
For box_plot it was a useful option adding data points. It helps a lot to see the variation in samples within a plot, specifically for longitudinal studies for microbiota, but if you think it makes the code complicated, then never mind
thanks for the response.

@sbslee
Copy link
Owner

sbslee commented Apr 13, 2022

For the beta_3D plot, i can't control the colors, e.g. if i want "gut" in red and "tongue" in blue, i can't do that. If I compare with bar plot where it allows me to use RGB color codes to choose the bacteria. it would be great to control the colors for other plots too.

I see, thanks for the explanation. One way to work around this is to use the hue_order option as follows:

dokdo.beta_3d_plot(qza_file,
                   metadata=metadata_file,
                   hue='body-site',
                   hue_order=['tongue', 'left palm', 'right palm', 'gut'],
                   figsize=(8, 8))
plt.tight_layout()

beta-3d-plot-2

This gives you "gut in red and tongue in blue". But I will look into ways to more robustly control group color.

As for add_datapoints, again, thanks for the details. While the option was making the code more complicated, it's certainly not impossible :) I will try to bring it back in the next release.

Please leave this issue open until I resolve above issues.

@sbslee sbslee added the enhancement New feature or request label Apr 13, 2022
@sbslee sbslee changed the title plot options Plot options for beta_3d_plot and taxa_abundance_box_plot methods Apr 13, 2022
@khemlalnirmalkar
Copy link
Author

Thanks @sbslee

@sbslee
Copy link
Owner

sbslee commented Apr 16, 2022

New in 1.14.0-dev (3ba0b63): A new optional argument, palette, has been added to the beta_2d_plot method so that users can manually select the group-to-color mapping (documentation).

@sbslee
Copy link
Owner

sbslee commented Apr 16, 2022

Example usage:

import dokdo
import matplotlib.pyplot as plt
%matplotlib inline
import seaborn as sns
sns.set()
qza_file = '/Users/sbslee/Desktop/dokdo/data/moving-pictures-tutorial/unweighted_unifrac_pcoa_results.qza'
metadata_file = '/Users/sbslee/Desktop/dokdo/data/moving-pictures-tutorial/sample-metadata.tsv'
palette = {'gut': 'yellow', 'left palm': 'green', 'right palm': 'blue', 'tongue': 'red'}
dokdo.beta_2d_plot(qza_file, metadata_file, hue='body-site', palette=palette, figsize=(5, 5))
plt.tight_layout()

beta_2d_plot-3

sbslee added a commit that referenced this issue Apr 16, 2022
* :issue:`39`: Add new argument ``palette`` to :meth:`beta_2d_plot` and 
:meth:`beta_3d_plot` methods so that users can control categorical color 
mapping.
@sbslee
Copy link
Owner

sbslee commented Apr 16, 2022

Also updated the beta_3d_plot method.

import dokdo
import matplotlib.pyplot as plt
%matplotlib inline
import seaborn as sns
sns.set()
qza_file = '/Users/sbslee/Desktop/dokdo/data/moving-pictures-tutorial/unweighted_unifrac_pcoa_results.qza'
metadata_file = '/Users/sbslee/Desktop/dokdo/data/moving-pictures-tutorial/sample-metadata.tsv'
palette = {'gut': 'yellow', 'left palm': 'green', 'right palm': 'blue', 'tongue': 'red'}
dokdo.beta_3d_plot(qza_file, metadata=metadata_file, hue='body-site', palette=palette, figsize=(8, 8))
plt.tight_layout()

beta_3d_plot-3

@sbslee sbslee changed the title Plot options for beta_3d_plot and taxa_abundance_box_plot methods Plot options for beta_2d/3d_plot and taxa_abundance_box_plot methods Apr 16, 2022
sbslee added a commit that referenced this issue Apr 16, 2022
* :issue:`39`: Bring back ``add_datapoints`` argument to 
:meth:`taxa_abundance_box_plot` method to display data points on top of 
the boxes (note that it was deprecated in 1.11.0 version).
@sbslee
Copy link
Owner

sbslee commented Apr 16, 2022

@khemlalnirmalkar,

I brought back the add_datapoints option to the taxa_abundance_box_plot method! Hope this helps.

import dokdo
import matplotlib.pyplot as plt
%matplotlib inline
import seaborn as sns
sns.set()

qzv_file = '/Users/sbslee/Desktop/dokdo/data/moving-pictures-tutorial/taxa-bar-plots.qzv'
dokdo.taxa_abundance_box_plot(
    qzv_file,
    level=2,
    count=4,
    pretty_taxa=True,
    figsize=(8, 7),
    add_datapoints=True
)
plt.tight_layout()

taxa_abundance_box_plot-6

@sbslee
Copy link
Owner

sbslee commented Apr 16, 2022

I believe all of the requested features have been added to the 1.14.0-dev branch. Please try these when you get a chance and let me know if they all behave as expected. I will close this issue once testing is finished.

@khemlalnirmalkar
Copy link
Author

Hi @sbslee
This new version v1.14 is working great with all updated features
Thank you so much for doing it

@sbslee sbslee closed this as completed Apr 17, 2022
@khemlalnirmalkar
Copy link
Author

khemlalnirmalkar commented Apr 24, 2022

Hi @sbslee
One strange thing i observed with beta_2D plot,
when i am making only one 2D plot, color combination is working well, but when i am 4 plots together, colors are chnaging,
please can you suggest, whats going on
***my code was

import dokdo
import matplotlib.pyplot as plt
%matplotlib inline
import seaborn as sns
sns.set()

weg_file = '/mnt/storage//run1/placebo_donors//core-metrics-results_30k/weighted_unifrac_pcoa_results.qza'
unweg_file = '/mnt/storage//run1/placebo_donors//core-metrics-results_30k/unweighted_unifrac_pcoa_results.qza'
jacc_file = '/mnt/storage//run1/placebo_donors//core-metrics-results_30k/jaccard_pcoa_results.qza'
bray_file = '/mnt/storage//run1/placebo_donors//core-metrics-results_30k/bray_curtis_pcoa_results.qza'

metadata_file = '/mnt/storage//run1/placebo_donors/sample-metadata.tsv'
palette = {'pl_Baseline':'red','pl_Vancomycin':'blue','pl_wk3':'cyan','pl_EndPart1':'lime','Donor':'black'}


fig, [[ax1, ax2], [ax3, ax4]] = plt.subplots(2, 2, figsize=(15, 15))
dokdo.beta_2d_plot(weg_file,
                   metadata_file,
                   ax=ax1,
                   hue='TreatPoints')
dokdo.beta_2d_plot(unweg_file,
                   metadata_file,
                   ax=ax2,
                   hue='TreatPoints')
dokdo.beta_2d_plot(jacc_file,
                   metadata_file,
                   ax=ax3,
                   hue='TreatPoints')
dokdo.beta_2d_plot(bray_file,
                   metadata_file,
                   ax=ax4,
                   hue='TreatPoints',
                   )
ax1.set_title("Weighted_unifrac'", fontsize=20)
ax2.set_title("Uneighted_unifrac", fontsize=20)
ax3.set_title("Jaccard_distance", fontsize=20)
ax4.set_title('Bray-Curtis', fontsize=20)
for ax in [ax1, ax2, ax3, ax4]:
    ax.xaxis.label.set_size(20)
    ax.yaxis.label.set_size(20)
    ax.tick_params(axis='both', which='major', labelsize=15)
![Screenshot from 2022-04-23 19-39-46](https://user-images.githubusercontent.com/32944151/164953761-e975acd1-df69-4d0f-a003-2c3b53a0808d.png)

    ax.legend(loc='upper left')
plt.tight_layout()

fig1= plt.gcf()

see the attached image, baseline suppose to be red but it turned into blue

@sbslee
Copy link
Owner

sbslee commented Apr 24, 2022

@khemlalnirmalkar,

I see that you've defined the palette variable, but you've never used it. For example,

dokdo.beta_2d_plot(weg_file,
                   metadata_file,
                   ax=ax1,
                   palette= palette, # <----- Add this
                   hue='TreatPoints')

Try again with palette added.

@khemlalnirmalkar
Copy link
Author

A silly mistake, my apologies,
Thanks

@sbslee sbslee linked a pull request Jun 24, 2022 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants