gmteunisse / fantaxtic

Fantaxtic - Nested Bar Plots for Phyloseq Data
26 stars 3 forks source link

Color palette, rgb, color name etc... or possible insertion from other packages? #29

Closed luigallucci closed 2 months ago

luigallucci commented 2 months ago

Hi!

I'm starting to use fantaxtic, I appreciate the integrated version for the relative abundances and so on.

I was wondering if there is a way to implement a personalised palette (e.g. from RColorBrewer) to be used inside the plot_nested_bar( palette= ...).

Do you have an already implemented solution or can you give me a suggestion to do so?

gmteunisse commented 2 months ago

You can provide a personalised palette to plot_nested_bar, please see the documentation here: https://github.com/gmteunisse/fantaxtic?tab=readme-ov-file#palette

If you want further control, you can also build the plot from scratch using ggnested, the core functionality of the plot function. There is an example of how to do this at the end of the documentation: https://github.com/gmteunisse/fantaxtic?tab=readme-ov-file#advanced-usage

Let me know if that answers your question.


From: l.gallucci @.> Sent: Wednesday, April 17, 2024 10:46:04 PM To: gmteunisse/fantaxtic @.> Cc: Subscribed @.***> Subject: [gmteunisse/fantaxtic] Color palette, rgb, color name etc... or possible insertion from other packages? (Issue #29)

Hi!

I'm starting to use fantaxtic, I appreciate the integrated version for the relative abundances and so on.

I was wondering if there is a way to implement a personalised palette (e.g. from RColorBrewer) to be used inside the plot_nested_bar( palette= ...).

Do you have an already implemented solution or can you give me a suggestion to do so?

— Reply to this email directly, view it on GitHubhttps://github.com/gmteunisse/fantaxtic/issues/29, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AHBWS3XKLT7HAP45DBDLNNLY53NQZAVCNFSM6AAAAABGMAZJS2VHI2DSMVQWIX3LMV43ASLTON2WKOZSGI2DSMRUGA4DENQ. You are receiving this because you are subscribed to this thread.Message ID: @.***>

luigallucci commented 2 months ago

@gmteunisse thank you for the fast reply!

I saw the palette section, I was wondering if instead of using:

 palette = c(Bacteroidetes = "red", 
                            Proteobacteria = "blue"),

I can also use a personalized object like this or directly a command of RColorBrewer

colourCount1=length(get_taxa_unique(e1_sub, taxonomic.rank = "Genus"))

pal <- colorRampPalette(brewer.pal(12,"Paired"))(colourCount1))

plot_nested_bar(top_e1$ps_obj,
                top_level = "Class",
                nested_level = "Genus",
                nested_merged_label = "NA and other <tax>",
                palette= pal,
                legend_title = "Phyla and genera") 

to assign the colour to the nested_level? e.g. trying this, just a blue color appears in the plot.

If that is not possible, could I also provide a color code in hex, like this, when defining the palette with taxoun_colours()?

pal3 <- taxon_colours(top_e1$ps_obj, 
                     tax_level = "Phylum", 
                     palette = c(Alphaproteobacteria = "#6d4c3d", 
                                 Campylobacterota = "#095256",
                                Gammaproteobacteria= "#ec7357"))
gmteunisse commented 2 months ago

Can you provide an image of your output for your first question? It seems to me that your example with colorramppalette should work.

To your second question: yes, you can provide hex codes.


From: l.gallucci @.> Sent: Thursday, April 18, 2024 9:11:00 AM To: gmteunisse/fantaxtic @.> Cc: gmteunisse @.>; Mention @.> Subject: Re: [gmteunisse/fantaxtic] Color palette, rgb, color name etc... or possible insertion from other packages? (Issue #29)

@gmteunissehttps://github.com/gmteunisse thank you for the fast reply!

I saw the palette section, I was wondering if instead of using:

palette = c(Bacteroidetes = "red", Proteobacteria = "blue"),

I can also use a personalized object like this or directly a command of RColorBrewer

colourCount1=length(get_taxa_unique(e1_sub, taxonomic.rank = "Genus"))

pal <- colorRampPalette(brewer.pal(12,"Paired"))(colourCount1))

plot_nested_bar(top_e1$ps_obj, top_level = "Class", nested_level = "Genus", nested_merged_label = "NA and other ", palette= pal, legend_title = "Phyla and genera")

to assign the colour to the nested_level? e.g. trying this, just a blue color appears in the plot.

If that is not possible, could I also provide a color code in hex, like this, when defining the palette with taxoun_colours()?

pal3 <- taxon_colours(top_e1$ps_obj, tax_level = "Phylum", palette = c(Alphaproteobacteria = "#6d4c3d", Campylobacterota = "#095256", Gammaproteobacteria= "#ec7357"))

— Reply to this email directly, view it on GitHubhttps://github.com/gmteunisse/fantaxtic/issues/29#issuecomment-2063176574, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AHBWS3X4HJXZQI6U3R67QVLY55WYJAVCNFSM6AAAAABGMAZJS2VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDANRTGE3TMNJXGQ. You are receiving this because you were mentioned.Message ID: @.***>

luigallucci commented 2 months ago

Yes, is working but is following the order of priority (I suppose) that RColorBrewer give in the adopted palette...moreover, I have a sample with really low diversity in terms of top_level. I'm plotting with class and genus. So, probably this makes the barplot not completely differentiated aesthetically as I had in mind.

Probably, a suitable alternative for me, could be to better define the plot with the advance usage settings. Can I group the genus less abundant then 5% and NA, make the nested legends and plot it using ggplot, right?

gmteunisse commented 2 months ago

Thanks for checking that, I’m happy to hear that the function is working as intended.

I’m not sure if I understand your second question. Your top level (class) determines the colours, so grouping at the genus level won’t change the number of colours. Furthermore, the low abundance / NA genera should already be grouped together into the Other group (unless your top N genera contains those).

If you have very little diversity at the top level, maybe an option is to go down a level (e.g order or family) to increase the colour diversity?


From: l.gallucci @.> Sent: Friday, April 19, 2024 8:41:26 AM To: gmteunisse/fantaxtic @.> Cc: gmteunisse @.>; Mention @.> Subject: Re: [gmteunisse/fantaxtic] Color palette, rgb, color name etc... or possible insertion from other packages? (Issue #29)

Yes, is working but is following the order of priority (I suppose) that RColorBrewer give in the adopted palette...moreover, I have a sample with really low diversity in terms of top_level. I'm plotting with class and genus. So, probably this makes the barplot not completely differentiated aesthetically as I had in mind.

Probably, a suitable alternative for me, could be to better define the plot with the advance usage settings. Can I group the genus less abundant then 5% and NA, make the nested legends and plot it using ggplot, right?

— Reply to this email directly, view it on GitHubhttps://github.com/gmteunisse/fantaxtic/issues/29#issuecomment-2065861060, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AHBWS3VVJAWVIPSHZ5AMHQLY6C4BNAVCNFSM6AAAAABGMAZJS2VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDANRVHA3DCMBWGA. You are receiving this because you were mentioned.Message ID: @.***>

luigallucci commented 2 months ago

Indeed, this is what I mean with my second question: they are samples from enrichment (most of them), which makes the top level not diverse also at class level, which is my actual top level.

I can manage the colour to arrange it down to the order or family. I want to know if there is a way to have a significant control on the filtering level when choosing the top_taxa.

I'm working on that:

top_e1 <- top_taxa(e1_sub,
                        n_taxa = 10,
                        tax_level = "Genus",
                        grouping = "Sample_id")

If I want to drop all the taxa below a specific value (e.g. less than 10% abundant) and group these together using a label Less abundant < 10% or similar... is there a way to do that in fantaxtic? So, with more fine-tuned filtering.

gmteunisse commented 2 months ago

There’s no native support for that, but you can use some fantaxtic helper functions to do so. You would need to identify the taxon ids of the taxa that you want to merge; fantaxtic can do the rest. See this issue for a code example for merging: https://github.com/gmteunisse/fantaxtic/issues/25

See this stackoverflow answer for an approach of identifying taxa by %: https://stackoverflow.com/questions/76631141/filter-phyloseq-to-use-in-fantaxtic

luigallucci commented 2 months ago

Thank you for the reply and sorry for mine late one.

The second example is working perfectly; I have two additional questions to end that:

In your opinion, what is the difference between using max and sum? It probably is not really clear to me what max is doing.

The second question...plot_nested_bar is a ggplot object, so it can be treated equally. Can I modify the aesthetic parameters of the plot without modifying/losing the legend organization? on the way around, there is a way to reproduce the same legend organization in fantaxtic in a normal ggplot taxa plotbar?

gmteunisse commented 2 months ago

It’s the aggregation function that you’re using, e.g. max abundance, summed abundance, mean abundance, etc. Fantaxtic uses mean abundance by default to get the top taxa; I suggest you do the same to identify the <x% taxa.

Yes, you can modify the plot with regular ggplot; however, note that to keep the legend as is when completely changing the theme, you will have to use ggnested’s ‘theme_nested’. Please refer to the end of the ggnested docs.


From: l.gallucci @.> Sent: Friday, April 26, 2024 2:57:08 PM To: gmteunisse/fantaxtic @.> Cc: gmteunisse @.>; Mention @.> Subject: Re: [gmteunisse/fantaxtic] Color palette, rgb, color name etc... or possible insertion from other packages? (Issue #29)

Thank you for the reply and sorry for mine late one.

The second example is working perfectly; I have two additional questions to end that:

In your opinion, what is the difference between using max and sum? It probably is not really clear to me what max is doing.

The second question...plot_nested_bar is a ggplot object, so it can be treated equally. Can I modify the aesthetic parameters of the plot without modifying/losing the legend organization? on the way around, there is a way to reproduce the same legend organization in fantaxtic in a normal ggplot taxa plotbar?

— Reply to this email directly, view it on GitHubhttps://github.com/gmteunisse/fantaxtic/issues/29#issuecomment-2079342096, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AHBWS3TOWKLEBWL6RZ6QEX3Y7JFKJAVCNFSM6AAAAABGMAZJS2VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDANZZGM2DEMBZGY. You are receiving this because you were mentioned.Message ID: @.***>