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

Persistent warnings from ggrepel::geom_label_repel() printed randomly when running other commands afterward #187

Open
YoannPa opened this issue Feb 27, 2021 · 2 comments

Comments

@YoannPa
Copy link

YoannPa commented Feb 27, 2021

Summary

I have made a function that is able to draw a ggplot2 plot using ggrepel::geom_label_repel() for the labels.
I have the same warning printed multiple time (ggrepel: 15 unlabeled data points (too many overlaps). Consider increasing max.overlaps with 15 being just an example, the number can vary following the use).

For some reason, even after having these warnings displayed right after the use of the function, if I just continue with other manual commands, the warnings are printed again randomly, which is very strange.

When I check baseenv()$last.warning the warnings are still here indeed. But that doesn't explain why the warnings are printed randomly.

Minimal code example

I don't really have a "minimal" example to provide. But instead I would say any kind of plot you produce that could raise the warnings cited above when using ggrepel::geom_label_repel.

The function creates the plot following these steps, and everything works great on the output plot:

#Make PCA ggplot
  biplt <- ggplot() +
    theme(axis.ticks = element_blank(),
          panel.background = element_blank(),
          panel.grid = element_line(colour = "grey"),
          axis.title = element_text(size = 13),
          axis.text = element_text(size = 12),
          legend.title = element_text(size = 13),
          legend.text = element_text(size = 12),
          legend.key = element_blank())
  if(!is.null(color.data) & is.null(shape.data)){
    biplt <- biplt +
      #Draw sample distribution
      geom_point(data = dt.scaled.pc, mapping = aes(
        x = PCx, y = PCy, color = color.data), size = point.size) +
      labs(x = lab.PC[1], y = lab.PC[2], color = color.data)
  } else if(!is.null(color.data) & !is.null(shape.data)){
    if(color.data != shape.data){
      biplt <- biplt +
        #Draw sample distribution
        geom_point(data = dt.scaled.pc, mapping = aes(
          x = PCx, y = PCy, color = color.data, shape = shape.data),
          size = point.size) +
        labs(
          x = lab.PC[1], y = lab.PC[2], shape = shape.data, color = color.data)
    } else {
      biplt <- biplt +
        #Draw sample distribution
        geom_point(data = dt.scaled.pc, mapping = aes(
          x = PCx, y = PCy, color = color.data, shape = color.data),
          size = point.size) +
        labs(
          x = lab.PC[1], y = lab.PC[2], shape = color.data, color = color.data)
    }
  } else if(is.null(color.data) & is.null(shape.data)){
    biplt <- biplt +
      geom_point(data = dt.scaled.pc, mapping = aes(x = PCx, y = PCy),
                 color = "black", size = point.size) +
      labs(x = lab.PC[1], y = lab.PC[2])
  } else if(is.null(color.data) & !is.null(shape.data)){
    biplt <- biplt +
      geom_point(data = dt.scaled.pc, mapping = aes(
        x = PCx, y = PCy, shape = shape.data),
        color = "black", size = point.size) +
      labs(x = lab.PC[1], y = lab.PC[2], shape = shape.data)
  }
  if(!is.null(scale.color.manual)){
    biplt <- biplt + scale_color_manual(values = scale.color.manual)
  }
  if(!is.null(scale.shape.manual)){
    biplt <- biplt + scale_shape_manual(values = scale.shape.manual)
  }
  #Draw loadings
  if(loadings){
    biplt <- biplt + geom_segment(
      data = loadings.data, mapping = aes(x = 0, y = 0, xend = PCx, yend = PCy),
      arrow = grid::arrow(length = grid::unit(8, "points")),
      colour = loadings.col) +
      ggrepel::geom_label_repel(
        data = loadings.data, mapping = aes(x = PCx, y = PCy, label = labels),
        size = 3)
  }

Suggestions

Currently, I fix this issue using the following command, after executing my function when this specific warning is raised (printed once or multiple times) : assign("last.warning", NULL, envir = baseenv())
This stops the warnings from being printed randomly.

Version information

Here is the output from sessionInfo() in my R session (be aware that some of the packages loaded are mine and are not all publicly available):

R version 4.0.2 (2020-06-22)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 16.04.7 LTS

Matrix products: default
BLAS:   /usr/lib/libblas/libblas.so.3.6.0
LAPACK: /usr/lib/lapack/liblapack.so.3.6.0

locale:
 [1] LC_CTYPE=fr_FR.UTF-8       LC_NUMERIC=C               LC_TIME=fr_FR.UTF-8        LC_COLLATE=fr_FR.UTF-8    
 [5] LC_MONETARY=fr_FR.UTF-8    LC_MESSAGES=fr_FR.UTF-8    LC_PAPER=fr_FR.UTF-8       LC_NAME=C                 
 [9] LC_ADDRESS=C               LC_TELEPHONE=C             LC_MEASUREMENT=fr_FR.UTF-8 LC_IDENTIFICATION=C       

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

other attached packages:
 [1] DTrsiv_0.0.24                           RnBeads_2.6.0                           plyr_1.8.6                             
 [4] methylumi_2.34.0                        minfi_1.34.0                            bumphunter_1.30.0                      
 [7] locfit_1.5-9.4                          iterators_1.0.13                        foreach_1.5.1                          
[10] Biostrings_2.56.0                       XVector_0.28.0                          SummarizedExperiment_1.18.2            
[13] DelayedArray_0.14.1                     FDb.InfiniumMethylation.hg19_2.2.0      org.Hs.eg.db_3.11.4                    
[16] TxDb.Hsapiens.UCSC.hg19.knownGene_3.2.2 GenomicFeatures_1.40.1                  AnnotationDbi_1.50.3                   
[19] reshape2_1.4.4                          scales_1.1.1                            Biobase_2.48.0                         
[22] illuminaio_0.30.0                       matrixStats_0.58.0                      limma_3.44.3                           
[25] gridExtra_2.3                           gplots_3.1.1                            fields_11.6                            
[28] spam_2.6-0                              dotCall64_1.0-0                         ff_4.0.4                               
[31] bit_4.0.4                               cluster_2.1.0                           MASS_7.3-53                            
[34] GenomicRanges_1.40.0                    GenomeInfoDb_1.24.2                     IRanges_2.22.2                         
[37] S4Vectors_0.26.1                        BiocGenerics_0.34.0                     ggsci_2.9                              
[40] BiocompR_0.0.97                         ggfortify_0.4.11                        ggplot2_3.3.3                          
[43] data.table_1.13.6                      

loaded via a namespace (and not attached):
 [1] BiocFileCache_1.12.1      splines_4.0.2             BiocParallel_1.22.0       digest_0.6.27            
 [5] magrittr_2.0.1            memoise_2.0.0             readr_1.4.0               annotate_1.66.0          
 [9] askpass_1.1               siggenes_1.62.0           prettyunits_1.1.1         colorspace_2.0-0         
[13] blob_1.2.1                rappdirs_0.3.3            ggrepel_0.9.1             dplyr_1.0.4              
[17] crayon_1.4.0              RCurl_1.98-1.2            genefilter_1.70.0         GEOquery_2.56.0          
[21] survival_3.2-7            glue_1.4.2                gtable_0.3.0              zlibbioc_1.34.0          
[25] Rhdf5lib_1.10.1           maps_3.3.0                HDF5Array_1.16.1          DBI_1.1.1                
[29] rngtools_1.5              Rcpp_1.0.6                xtable_1.8-4              progress_1.2.2           
[33] mclust_5.4.7              preprocessCore_1.50.0     httr_1.4.2                RColorBrewer_1.1-2       
[37] ellipsis_0.3.1            farver_2.0.3              pkgconfig_2.0.3           reshape_0.8.8            
[41] XML_3.99-0.5              dbplyr_2.1.0              tidyselect_1.1.0          labeling_0.4.2           
[45] rlang_0.4.10              munsell_0.5.0             tools_4.0.2               cachem_1.0.3             
[49] generics_0.1.0            RSQLite_2.2.3             stringr_1.4.0             fastmap_1.1.0            
[53] bit64_4.0.5               beanplot_1.2              caTools_1.18.1            scrime_1.3.5             
[57] purrr_0.3.4               nlme_3.1-150              doRNG_1.8.2               nor1mix_1.3-0            
[61] xml2_1.3.2                biomaRt_2.44.4            compiler_4.0.2            rstudioapi_0.13          
[65] curl_4.3                  tibble_3.0.6              stringi_1.5.3             lattice_0.20-41          
[69] Matrix_1.2-18             multtest_2.44.0           vctrs_0.3.6               pillar_1.4.7             
[73] lifecycle_0.2.0           bitops_1.0-6              rtracklayer_1.48.0        R6_2.5.0                 
[77] KernSmooth_2.23-18        codetools_0.2-18          gtools_3.8.2              assertthat_0.2.1         
[81] rhdf5_2.32.4              openssl_1.4.3             withr_2.4.1               GenomicAlignments_1.24.0 
[85] Rsamtools_2.4.0           GenomeInfoDbData_1.2.3    hms_1.0.0                 quadprog_1.5-8           
[89] tidyr_1.1.2               base64_2.0                DelayedMatrixStats_1.10.1
@ghost
Copy link

ghost commented Sep 15, 2021

Mentioned here as well.

@slowkow
Copy link
Owner

slowkow commented Sep 15, 2021

Thanks for reporting this. Pull requests are welcome!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants