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

Is this package compatible with other ggplot functions? #110

Open
chung-wingko opened this issue Jun 19, 2024 · 1 comment
Open

Is this package compatible with other ggplot functions? #110

chung-wingko opened this issue Jun 19, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@chung-wingko
Copy link

Thank you so much for this package -- it's been really helpful for visualisations!

This is not a big issue, but I'm trying to adjust the visualisations (colours, text size, etc) and not sure whether these functions are compatible with the usual ggplot functions?

For example, this works great:
pathway_pca(abundance = metacyc_abundance %>% column_to_rownames("pathway"),
metadata = metadata, group = "Plot")

But when I try to adjust with custom colours, nothing changes.

plot_colors <- c("#DD5129", "#FAB255", "#0F7BA2", "#43B284", "#4c2f61")
pca_picrust <- pathway_pca(abundance = metacyc_abundance %>% column_to_rownames("pathway"),
metadata = metadata, group = "Plot")
pca_picrust + scale_color_manual(values = plot_colors)

@chung-wingko chung-wingko added the bug Something isn't working label Jun 19, 2024
@cafferychen777
Copy link
Owner

Hi @chung-wingko,

Thank you for your question and for using our package! I understand your desire to customize the visualizations using familiar ggplot2 syntax. While we would love to directly support ggplot2 functions, there are some limitations due to our use of the ggh4x package.

However, you can still achieve the customization you're looking for by accessing and modifying the individual layers of the plot. Here's how you can adjust the colors in your example:

pca_picrust <- pathway_pca(abundance = metacyc_abundance %>% column_to_rownames("pathway"), 
                           metadata = metadata, 
                           group = "Plot")

plot_colors <- c("#DD5129", "#FAB255", "#0F7BA2", "#43B284", "#4c2f61")

# Modify the color scale of the specific layer
pca_picrust$layers[[2]]$aes_params$colour <- NULL
pca_picrust$layers[[2]]$mapping$colour <- quote(Plot)

pca_picrust + scale_color_manual(values = plot_colors)

In this approach, we're first removing the hard-coded color mapping from the second layer (which typically contains the points), and then reassigning the color mapping to the 'Plot' variable. After these modifications, the scale_color_manual() function should work as expected.

For other ggplot2 customizations, you may need to use a similar approach of identifying and modifying specific layers. While it's not as straightforward as direct ggplot2 syntax, it does provide a way to achieve the customizations you're looking for.

We appreciate your feedback and will continue to explore ways to make our package more compatible with standard ggplot2 functions in future updates. If you have any more questions or need further clarification, please don't hesitate to ask!

Best,

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants