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

Issue with pathway_errorbar : "The legend.text.align theme element is not defined in the element hierarchy." #94

Closed
scilexenko opened this issue Feb 27, 2024 · 6 comments
Labels
bug Something isn't working

Comments

@scilexenko
Copy link

Hello @cafferychen777,

I was trying to use your package for PICRUST2 data visualization, but I encounter some problems.
I have an issue with pathway_errorbar function. It simply doesn't work.
Here is my code :

library(ggkegg)
library(dplyr)
library(tidygraph)
library(readr)
library(ggpicrust2)
library(tibble)
#library(tidyverse)
library(ggprism)
library(patchwork)

metadata <- read_delim("/outputs/sample_metadata.txt", delim = "\t", escape_double = FALSE, trim_ws = TRUE) 
kegg_abundance <- ko2kegg_abundance("/KO_metagenome_out/pred_metagenome_unstrat.tsv") 

daa_results_df <- pathway_daa(abundance = kegg_abundance, metadata = metadata, group = "TreatmentGroup", daa_method = "DESeq2", select = NULL, reference = NULL) 

daa_sub_method_results_df <- daa_results_df[daa_results_df$method == "DESeq2", ] %>% 
  filter(p_adjust < 0.01,
         group1 =="g_WD_NA",
         group2 =="g_WW_NA")

daa_sub_method_results_df %>% 
  filter(p_adjust < 0.000001)

daa_annotated_sub_method_results_df <- pathway_annotation(pathway = "KO", daa_results_df = daa_sub_method_results_df, ko_to_kegg = TRUE)
daa_annotated_sub_method_results_df <- daa_annotated_sub_method_results_df[!is.na(daa_annotated_sub_method_results_df$pathway_name),] %>% 
  filter(method == "DESeq2")

daa_annotated_sub_method_results_df_f <- daa_annotated_sub_method_results_df %>% 
  filter(feature %in% c("ko05340", "ko00564", "ko00562", "ko00561", "ko00250", "ko00195", "ko03450", "ko00310", "ko00600", "ko04141", "ko04260", "ko05142", "ko04973"))


ggpicrust2::pathway_errorbar(abundance = kegg_abundance,
                      daa_results_df = daa_annotated_sub_method_results_df_f,
                      Group = metadata$Code,
                      p_values_threshold = 0.05,
                      order = "pathway_class",
                      select = NULL,
                      ko_to_kegg = TRUE,
                      p_value_bar = F,
                      colors = NULL,
                      x_lab = "pathway_name"
                      )
# And here i have this error : 

Error in `plot_theme()`:
! The `legend.text.align` theme element is not defined in the element hierarchy.
Run `rlang::last_trace()` to see where the error occurred.
> rlang::last_trace()
<error/rlang_error>
Error in `plot_theme()`:
! The `legend.text.align` theme element is not defined in the element hierarchy.
---
Backtrace:1. ├─base (local) `<fn>`(x)
  2. └─patchwork:::print.patchwork(x)
  3.   └─patchwork:::build_patchwork(plot, plot$layout$guides %||% "auto")
  4.     └─base::lapply(x$plots, plot_table, guides = guides)
  5.       ├─patchwork (local) FUN(X[[i]], ...)
  6.       └─patchwork:::plot_table.ggplot(X[[i]], ...)
  7.         └─ggplot2::ggplotGrob(x)
  8.           ├─ggplot2::ggplot_gtable(ggplot_build(x))
  9.           └─ggplot2:::ggplot_gtable.ggplot_built(ggplot_build(x))
 10.             └─ggplot2:::plot_theme(plot)

I think it's link to the packages version or something.. I reinstalled ggpicrust2, patchwork and ggprism, but it didn't help. I had the impression that there was some conflict between ggplot and ggprism, but deactivation of ggprism changed nothing.
Interestingly, when I tried to launch the pathway_errorbar without xlab, the issue changes its nature

ggpicrust2::pathway_errorbar(abundance = kegg_abundance,
                      daa_results_df = daa_annotated_sub_method_results_df_f,
                      Group = metadata$TreatmentGroup,
                      p_values_threshold = 0.05,
                      order = "pathway_class",
                      select = NULL,
                      ko_to_kegg = TRUE,
                      p_value_bar = T,
                      colors = NULL
                      #x_lab = "pathway_name"
                      )
#problem : 

The 'method' column in the 'daa_results_df' data frame contains more than one method. Please filter it to contain only one method.
The 'group1' or 'group2' column in the 'daa_results_df' data frame contains more than one group. Please filter each to contain only one group.
Error in ggpicrust2::pathway_errorbar(abundance = kegg_abundance, daa_results_df = daa_annotated_sub_method_results_df_f,  : 
 Visualization with 'pathway_errorbar' cannot be performed because there are no features with statistical significance. For possible solutions, please check the FAQ section of the tutorial.

Here is my system info, if you need:

R version 4.3.2 (2023-10-31)
Platform: aarch64-apple-darwin20 (64-bit)
Running under: macOS Sonoma 14.3.1

Matrix products: default
BLAS:   /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libBLAS.dylib 
LAPACK: /Library/Frameworks/R.framework/Versions/4.3-arm64/Resources/lib/libRlapack.dylib;  LAPACK version 3.11.0

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

time zone: Europe/Paris
tzcode source: internal

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
 [1] patchwork_1.2.0  tibble_3.2.1     ggpicrust2_1.7.3 readr_2.1.5      dplyr_1.1.4      ggkegg_1.1.4     tidygraph_1.3.1 
 [8] igraph_2.0.2     XML_3.99-0.16.1  ggraph_2.1.0     ggplot2_3.5.0   

loaded via a namespace (and not attached):
 [1] tidyselect_1.2.0        viridisLite_0.4.2       farver_2.1.1            blob_1.2.4              filelock_1.0.3         
 [6] viridis_0.6.5           Biostrings_2.70.2       bitops_1.0-7            fastmap_1.1.1           RCurl_1.98-1.14        
[11] GGally_2.2.1            BiocFileCache_2.10.1    tweenr_2.0.3            digest_0.6.34           lifecycle_1.0.4        
[16] Cairo_1.6-2             KEGGREST_1.42.0         RSQLite_2.3.5           magrittr_2.0.3          compiler_4.3.2         
[21] rlang_1.1.3             tools_4.3.2             utf8_1.2.4              data.table_1.15.0       graphlayouts_1.1.0     
[26] bit_4.0.5               curl_5.2.0              plyr_1.8.9              RColorBrewer_1.1-3      withr_3.0.0            
[31] purrr_1.0.2             BiocGenerics_0.48.1     grid_4.3.2              polyclip_1.10-6         stats4_4.3.2           
[36] fansi_1.0.6             ggprism_1.0.4           colorspace_2.1-0        scales_1.3.0            MASS_7.3-60.0.1        
[41] cli_3.6.2               crayon_1.5.2            generics_0.1.3          rstudioapi_0.15.0       httr_1.4.7             
[46] tzdb_0.4.0              rjson_0.2.21            DBI_1.2.2               cachem_1.0.8            ggforce_0.4.2          
[51] stringr_1.5.1           zlibbioc_1.48.0         AnnotationDbi_1.64.1    BiocManager_1.30.22     XVector_0.42.0         
[56] vctrs_0.6.5             shadowtext_0.1.3        IRanges_2.36.0          GetoptLong_1.0.5        hms_1.1.3              
[61] S4Vectors_0.40.2        bit64_4.0.5             ggrepel_0.9.5           magick_2.8.3            tidyr_1.3.1            
[66] glue_1.7.0              ggstats_0.5.1           stringi_1.8.3           gtable_0.3.4            GenomeInfoDb_1.38.6    
[71] munsell_0.5.0           pillar_1.9.0            GenomeInfoDbData_1.2.11 R6_2.5.1                dbplyr_2.4.0           
[76] Biobase_2.62.0          png_0.1-8               memoise_2.0.1           Rcpp_1.0.12             gridExtra_2.3          
[81] org.Hs.eg.db_3.18.0     pkgconfig_2.0.3         GlobalOptions_0.1.2    

Here is a screenshot of daa_annotated_sub_method_results_df_ffile that I'm trying to viz :

image

And here is a snapshot of my metadata :

image

I hope that you can help me!
Thank you in advance.
Cheers
Ivan

@scilexenko scilexenko added the bug Something isn't working label Feb 27, 2024
@CarolaneGiraud
Copy link

Hello,
I'm having the exact same issue running the example data. Please let me know if you manage to fix it.
Cheers,
Carolane

@ko519
Copy link

ko519 commented Mar 7, 2024

Having the same issue on my own data, please give an update.

Cheers,
Katie

@cafferychen777
Copy link
Owner

Dear users,

Thank you for bringing this issue to our attention. The error you encountered with the pathway_errorbar function is caused by a recent update in the ggplot2 package. The legend.text.align theme element is not defined in the current version of ggplot2, which leads to the error message you received.

To resolve this issue, please downgrade your ggplot2 package to version 3.4.0. You can do this by running the following command in your R console:

install.packages("ggplot2", version = "3.4.0")

After downgrading ggplot2, the pathway_errorbar function should work as expected without any errors related to the legend.text.align theme element.

We apologize for any inconvenience caused by this issue. We are working on updating our package to ensure compatibility with the latest version of ggplot2. In the meantime, downgrading to ggplot2 3.4.0 should allow you to use the pathway_errorbar function without any problems.

If you have any further questions or concerns, please don't hesitate to reach out to us.

Best regards,
Chen YANG

@teunbrand
Copy link

Just ran into this issue on SO: https://stackoverflow.com/q/78146457/11374827.
Problem is described here: csdaw/ggprism#26 (comment)

@cafferychen777
Copy link
Owner

Hi Teun,

Thank you for sharing the link. It seems that the issue is indeed related to the legend.text.align theme element in ggprism, as described in the Stack Overflow post and the ggprism GitHub issue. I will update the code to address this problem. Thank you for bringing this to my attention!

Best,
Caffery

@scilexenko
Copy link
Author

Thank you for your answer. Indeed, downgrading ggplot2 helped.
Cheers,
Ivan

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

5 participants