Error ggplot?

164 views
Skip to first unread message

Ana Filipa Sobral

unread,
Mar 9, 2022, 7:39:14 PM3/9/22
to dartR
Hi dartR team,
I recently installed the developing version of dartR and am now realizing I need to update  the code for a few of the functions and I am running into some errors when plotting is needed.

For example, for gl.filter.maf, I used to run:

gl.filter.maf(mtgl6, threshold = 0.01666, v = 5)

by running that now I get the following error:

Error in layer(data = data, mapping = mapping, stat = stat, geom = GeomBar,  : 
  object 'plot_colors' not found

If I run ?gl.filter.maf and follow the suggested function and respective arguments:

gl.filter.maf(mtgl6, threshold = 0.01, by.pop = FALSE, maf.limit = 0.5, pop.limit = 4,
  ind.limit = 1, recalc = FALSE, plot.out = TRUE, plot_theme = theme_dartR(),
  plot_colors_pop = discrete_palette, plot_colors_all = two_colors, bins = 25,
  save2tmp = FALSE, verbose = NULL)

I still get a similar error:
Error in layer(data = data, mapping = mapping, stat = stat, geom = GeomBoxplot,  :
  object 'two_colors' not found

What could be the problem?
Thanks!

sessionInfo()
R version 4.0.4 (2021-02-15)
Platform: x86_64-apple-darwin17.0 (64-bit)
Running under: macOS 12.2.1

Matrix products: default
LAPACK: /Library/Frameworks/R.framework/Versions/4.0/Resources/lib/libRlapack.dylib

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

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

other attached packages:
 [1] ggplotify_0.1.0    forcats_0.5.1      stringr_1.4.0      dplyr_1.0.8        purrr_0.3.4      
 [6] readr_2.1.2        tidyr_1.2.0        tibble_3.1.6       tidyverse_1.3.1    ggplotAssist_0.1.3
[11] dartR_2.4          ggplot2_3.3.5      adegenet_2.1.5     ade4_1.7-18      

loaded via a namespace (and not attached):
  [1] readxl_1.3.1        backports_1.4.1     spam_2.8-0          StAMPP_1.6.3      
  [5] plyr_1.8.6          igraph_1.2.11       sp_1.4-6            splines_4.0.4      
  [9] digest_0.6.29       yulab.utils_0.0.4   foreach_1.5.2       htmltools_0.5.2    
 [13] viridis_0.6.2       gdata_2.18.0        fansi_1.0.2         magrittr_2.0.2    
 [17] cluster_2.1.2       doParallel_1.0.17   PopGenReport_3.0.4  tzdb_0.2.0        
 [21] openxlsx_4.2.5      modelr_0.1.8        R.utils_2.11.0      colorspace_2.0-3  
 [25] rvest_1.0.2         mmod_1.3.3          haven_2.4.3         xfun_0.30          
 [29] rgdal_1.5-28        crayon_1.5.0        jsonlite_1.8.0      iterators_1.0.14  
 [33] ape_5.6-2           glue_1.6.2          gtable_0.3.0        seqinr_4.2-8      
 [37] maps_3.4.0          scales_1.1.1        mvtnorm_1.1-3       DBI_1.1.2          
 [41] GGally_2.1.2        miniUI_0.1.1.1      Rcpp_1.0.8          viridisLite_0.4.0  
 [45] xtable_1.8-4        gridGraphics_0.5-1  foreign_0.8-82      dotCall64_1.0-1    
 [49] DT_0.21             dismo_1.3-5         htmlwidgets_1.5.4   httr_1.4.2        
 [53] RColorBrewer_1.1-2  shinyAce_0.4.1      genetics_1.3.8.1.3  calibrate_1.7.7    
 [57] ellipsis_0.3.2      pkgconfig_2.0.3     reshape_0.8.8       R.methodsS3_1.8.1  
 [61] farver_2.1.0        sass_0.4.0          dbplyr_2.1.1        utf8_1.2.2        
 [65] tidyselect_1.1.2    labeling_0.4.2      rlang_1.0.2         reshape2_1.4.4    
 [69] later_1.3.0         munsell_0.5.0       cellranger_1.1.0    tools_4.0.4        
 [73] cli_3.2.0           generics_0.1.2      broom_0.7.12        fastmap_1.1.0      
 [77] knitr_1.37          fs_1.5.2            gdsfmt_1.26.1       zip_2.2.0          
 [81] RgoogleMaps_1.4.5.3 nlme_3.1-155        mime_0.12           R.oo_1.24.0        
 [85] xml2_1.3.3          gap_1.2.3-1         compiler_4.0.4      rstudioapi_0.13    
 [89] curl_4.3.2          png_0.1-7           reprex_2.0.1        bslib_0.3.1        
 [93] stringi_1.7.6       gdistance_1.3-6     fields_13.3         lattice_0.20-45    
 [97] Matrix_1.4-0        vegan_2.5-7         permute_0.9-7       vctrs_0.3.8        
[101] pillar_1.7.0        lifecycle_1.0.1     combinat_0.0-8      editData_0.1.8    
[105] jquerylib_0.1.4     data.table_1.14.2   SNPRelate_1.24.0    raster_3.5-15      
[109] httpuv_1.6.5        patchwork_1.1.1     R6_2.5.1            promises_1.2.0.1  
[113] gridExtra_2.3       rio_0.5.29          codetools_0.2-18    MASS_7.3-55        
[117] gtools_3.9.2        assertthat_0.2.1    shinyWidgets_0.6.4  withr_2.5.0        
[121] pegas_1.1           mgcv_1.8-39         parallel_4.0.4      hms_1.1.1          
[125] terra_1.5-21        grid_4.0.4          shiny_1.7.1         lubridate_1.8.0    

Jose Luis Mijangos

unread,
Mar 10, 2022, 9:21:18 AM3/10/22
to dartR
Hello Ana,

I have fixed that error. Could you please install again the dev version:

> library(dartR)
> gl.install.vanilla.dartR(flavour = "dev")
# Restart your R session: Menu > Session > Restart R
> library(dartR)
> gl.filter.maf(bandicoot.gl)

Cheers,
Luis

Ana Filipa Sobral

unread,
Mar 10, 2022, 7:55:20 PM3/10/22
to dartR
Hi Luis,
It worked, but now I am getting the same error when running:

gl.dist.pop(mtgl8, method = "euclidean", plot.out = TRUE,
            scale = FALSE, output = "dist", plot_theme = theme_dartR(),
            plot_colors = two_colors, save2tmp = FALSE, verbose = 5)

It seems to happen anytime plotting is needed.

However, if I run:

gl.dist.pop(mtgl8, verbose = 5)

It works.

Cheers,
Ana

Jose Luis Mijangos

unread,
Mar 10, 2022, 9:23:50 PM3/10/22
to dartR
Hi Ana,

Thank you for reporting this bug.

The issue is that the variable "two_colors", that is used to set the colors for the plot, is within the "environment" of dartR and not in the environment from which you are running the function. So, as long you don't use this variable when you call the function, it will run smoothly because the function "knows" where to find the variable. If you want to use this variable, you need to specify the environment where to find the variable (dartR's environment), for example:

res_1 <- gl.dist.pop(platypus.gl, method = "euclidean", plot.out = TRUE,
            scale = FALSE, output = "dist", plot_theme = dartR:::theme_dartR(),
            plot_colors = dartR:::two_colors, save2tmp = FALSE, verbose = 5)

# if you want to use your own colors:

res_2 <- gl.dist.pop(platypus.gl, method = "euclidean", plot.out = TRUE,
                     scale = FALSE, output = "dist", plot_theme = dartR:::theme_dartR(),
                     plot_colors =c("red","blue"), save2tmp = FALSE, verbose = 5)

In the following release of dartR, we will solve this in all the functions with the same issue by adding dartR:::

Regards,
Luis

Arthur Georges

unread,
Mar 12, 2022, 1:23:22 AM3/12/22
to da...@googlegroups.com
Hi Ana,

You can also choose colours using 

gl.select.colors(library='baseR',palette='rainbow',ncolors=12) # look at the displayed palette
mytwocolors <- gl.select.colors(library='baseR',palette='rainbow',ncolors=12,select=c(1,8)) # pick two colours

then apply them using

res_2 <- gl.dist.pop(platypus.gl, method = "euclidean", plot.out = TRUE,
                     scale = FALSE, output = "dist", plot_colors =mytwocolors, save2tmp = FALSE, verbose = 5)

Arthur

PS For shapes, try 
gl.select.shapes()
mytwoshapes <- gl.select.shapes(select=c(8,1))




--
You received this message because you are subscribed to the Google Groups "dartR" group.
To unsubscribe from this group and stop receiving emails from it, send an email to dartr+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/dartr/b051270c-4940-4207-aeaf-3615bbb88096n%40googlegroups.com.

Ana Filipa Sobral

unread,
Mar 14, 2022, 9:10:34 AM3/14/22
to dartR
Hi,
Glad it was helpful.
Thank you both for your help.
Cheers,
Ana
Reply all
Reply to author
Forward
0 new messages