MarioniLab / miloR

R package implementation of Milo for testing for differential abundance in KNN graphs
https://bioconductor.org/packages/release/bioc/html/miloR.html
GNU General Public License v3.0
339 stars 22 forks source link

Error in `scale_color_gradient2()` #321

Closed ShashTrip1 closed 1 day ago

ShashTrip1 commented 4 months ago

Reran some old code I had (last ran 1 month aga without any errors) however today it threw an error. Code below:

I ran: plotDAbeeswarm(da_results, group.by = "ident")

And it gave the following error: converting group.by to factor... Error in scale_color_gradient2(): ! Discrete values supplied to continuous scale.

MikeDMorgan commented 4 months ago

Hi @ShashTrip1 can you check if the 'ident' variable is a factor, character or numeric type. Pre-converting to character may help.

shuaizh117 commented 4 months ago

Reran some old code I had (last ran 1 month aga without any errors) however today it threw an error. Code below:

I ran: plotDAbeeswarm(da_results, group.by = "ident")

And it gave the following error: converting group.by to factor... Error in scale_color_gradient2(): ! Discrete values supplied to continuous scale.

I encountered the same problem. I group.by = "celltype", but it still gave me the same error, even I converted "celltype" to character. Did you solve it?

MikeDMorgan commented 4 months ago

Your code states that the group.by variable is "ident" not "celltype".

ionzhanghui commented 3 months ago

I also met this problem when I run " plotDAbeeswarm": Converting group_by to factor... Error in scale_color_gradient2(): ! Discrete values supplied to continuous scale. ℹ Example values: NA, NA, NA, NA, and NA Run rlang::last_trace() to see where the error occurred.

I check the 'ident' variable I used is a factor. Do you have any suggestion?

MikeDMorgan commented 3 months ago

Yes - you have NA values in your variables, as stated in the error traceback.

Elo-mars commented 2 months ago

does someone have a straight answer? I have the exact same error as @ionzhanghui

I created a new environment (conda) today with all the up to date packages still have the issue

ps: I used miloR a couple of weeks before, with the exact same code, and it ran fine I do not have NA values in my idents

MikeDMorgan commented 2 months ago

Please give the output of your sessionInfo() whenever posting issues. There is no guarantee that the conda versions are the most up to date.

Elo-mars commented 2 months ago
head(da_results)
class(da_results$Cluster)

pdf(paste0(condition,"_epithelium_plotDAbeeswarm.pdf"),height= 15, width=17)
plotDAbeeswarm(da_results, group.by = "Cluster") + theme(text = element_text(size = 40)) 
dev.off()
  logFC   logCPM         F     PValue       FDR Nhood SpatialFDR NhoodGroup

1 -4.528506 13.11798 1.1565313 0.28239395 0.3968780 1 0.3851987 1 2 -6.788070 11.67183 4.2893203 0.03855765 0.2823152 2 0.2670588 1 3 1.391347 11.78975 0.2876107 0.59185130 0.6808005 3 0.6684219 1 4 -7.740415 12.46967 4.5495640 0.03312179 0.2823152 4 0.2670588 1 5 6.110077 11.19585 2.3146440 0.12841396 0.2823152 5 0.2670588 2 6 6.128929 11.20877 2.3420949 0.12617354 0.2823152 6 0.2670588 2 Cluster Cluster_fraction anno_celltype_cluster 1 HES1+ Macs 1.0000000 HES1+ Macs 2 HES1+ Macs 1.0000000 HES1+ Macs 3 HES1+ Macs 1.0000000 HES1+ Macs 4 HES1+ Macs 1.0000000 HES1+ Macs 5 Cytokine-rich Mono 2 0.7297297 Cytokine-rich Mono 2 6 HES1+ Macs 1.0000000 HES1+ Macs [1] "character" Converting group_by to factor... Error in scale_color_gradient2(): ! Discrete values supplied to continuous scale. ℹ Example values: NA, NA, NA, NA, and NA Run rlang::last_trace() to see where the error occurred.

sessioninfo:

R version 4.3.3 (2024-02-29)                             
Platform: x86_64-conda-linux-gnu (64-bit)                
Running under: Rocky Linux 8.9 (Green Obsidian)          

Matrix products: default                                 
BLAS/LAPACK: /lustre1/project/stg_00075/software/miniconda/envs/miloR/lib/libopenblasp-r0.3.27.so;  LAPACK version 3.12.0

locale:                                                  
 [1] LC_CTYPE=en_US.utf-8       LC_NUMERIC=C              
 [3] LC_TIME=en_US.utf-8        LC_COLLATE=en_US.utf-8    
 [5] LC_MONETARY=en_US.utf-8    LC_MESSAGES=en_US.utf-8   
 [7] LC_PAPER=en_US.utf-8       LC_NAME=C                 
 [9] LC_ADDRESS=C               LC_TELEPHONE=C            
[11] LC_MEASUREMENT=en_US.utf-8 LC_IDENTIFICATION=C       

time zone: NA                                            
tzcode source: system (glibc)                            

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

other attached packages:                                 
 [1] Seurat_5.1.0                SeuratObject_5.0.2         
 [3] sp_2.1-4                    patchwork_1.2.0            
 [5] dplyr_1.1.4                 miloR_1.10.0               
 [7] edgeR_4.0.16                limma_3.58.1               
 [9] scater_1.30.1               ggplot2_3.5.1              
[11] scuttle_1.12.0              SingleCellExperiment_1.24.0
[13] SummarizedExperiment_1.32.0 Biobase_2.62.0             
[15] GenomicRanges_1.54.1        GenomeInfoDb_1.38.8        
[17] IRanges_2.36.0              S4Vectors_0.40.2           
[19] BiocGenerics_0.48.1         MatrixGenerics_1.14.0      
[21] matrixStats_1.3.0                                   

loaded via a namespace (and not attached):               
  [1] RcppAnnoy_0.0.22          splines_4.3.3            
  [3] later_1.3.2               bitops_1.0-8             
  [5] tibble_3.2.1              polyclip_1.10-7          
  [7] fastDummies_1.7.3         lifecycle_1.0.4          
  [9] globals_0.16.3            lattice_0.22-6           
 [11] MASS_7.3-60.0.1           magrittr_2.0.3           
 [13] plotly_4.10.4             httpuv_1.6.15            
 [15] sctransform_0.4.1         spam_2.10-0              
 [17] spatstat.sparse_3.1-0     reticulate_1.38.0        
 [19] cowplot_1.1.3             pbapply_1.7-2            
 [21] RColorBrewer_1.1-3        abind_1.4-5              
 [23] zlibbioc_1.48.2           Rtsne_0.17               
 [25] purrr_1.0.2               ggraph_2.2.1             
 [27] RCurl_1.98-1.16           tweenr_2.0.3             
 [29] GenomeInfoDbData_1.2.11   ggrepel_0.9.5            
 [31] irlba_2.3.5.1             listenv_0.9.1            
 [33] spatstat.utils_3.0-5      goftest_1.2-3            
 [35] RSpectra_0.16-2           spatstat.random_3.3-1    
 [37] fitdistrplus_1.2-1        parallelly_1.38.0        
 [39] DelayedMatrixStats_1.24.0 leiden_0.4.3.1           
 [41] codetools_0.2-20          DelayedArray_0.28.0      
 [43] ggforce_0.4.2             tidyselect_1.2.1         
 [45] farver_2.1.2              ScaledMatrix_1.10.0      
 [47] viridis_0.6.5             spatstat.explore_3.3-1   
 [49] jsonlite_1.8.8            BiocNeighbors_1.20.2     
 [51] tidygraph_1.3.1           progressr_0.14.0         
 [53] ggridges_0.5.6            survival_3.7-0           
 [55] tools_4.3.3               ica_1.0-3                
 [57] Rcpp_1.0.13               glue_1.7.0               
 [59] gridExtra_2.3             SparseArray_1.2.4        
 [61] withr_3.0.0               BiocManager_1.30.23      
 [63] fastmap_1.2.0             fansi_1.0.6              
 [65] digest_0.6.36             rsvd_1.0.5               
 [67] R6_2.5.1                  mime_0.12                
 [69] colorspace_2.1-1          scattermore_1.2          
 [71] gtools_3.9.5              tensor_1.5               
 [73] spatstat.data_3.1-2       utf8_1.2.4               
 [75] tidyr_1.3.1               generics_0.1.3           
 [77] data.table_1.15.4         graphlayouts_1.1.1       
 [79] httr_1.4.7                htmlwidgets_1.6.4        
 [81] S4Arrays_1.2.1            uwot_0.2.2               
 [83] pkgconfig_2.0.3           gtable_0.3.5             
 [85] lmtest_0.9-40             XVector_0.42.0           
 [87] htmltools_0.5.8.1         dotCall64_1.1-1          
 [89] scales_1.3.0              png_0.1-8                
 [91] spatstat.univar_3.0-0     reshape2_1.4.4           
 [93] nlme_3.1-165              cachem_1.1.0             
 [95] zoo_1.8-12                stringr_1.5.1            
 [97] KernSmooth_2.23-24        parallel_4.3.3           
 [99] miniUI_0.1.1.1            vipor_0.4.7              
[101] pillar_1.9.0              grid_4.3.3               
[103] vctrs_0.6.5               RANN_2.6.1               
[105] promises_1.3.0            BiocSingular_1.18.0      
[107] beachmat_2.18.1           xtable_1.8-4             
[109] cluster_2.1.6             beeswarm_0.4.0           
[111] cli_3.6.3                 locfit_1.5-9.10          
[113] compiler_4.3.3            rlang_1.1.4              
[115] crayon_1.5.3              future.apply_1.11.2      
[117] labeling_0.4.3            plyr_1.8.9               
[119] ggbeeswarm_0.7.2          stringi_1.8.4            
[121] deldir_2.0-4              viridisLite_0.4.2        
[123] BiocParallel_1.36.0       munsell_0.5.1            
[125] lazyeval_0.2.2            spatstat.geom_3.3-2      
[127] Matrix_1.6-5              RcppHNSW_0.6.0           
[129] sparseMatrixStats_1.14.0  future_1.34.0            
[131] statmod_1.5.0             shiny_1.9.0              
[133] ROCR_1.0-11               igraph_2.0.3             
[135] memoise_2.0.1 
MikeDMorgan commented 2 months ago

The current version of miloR is 2.0.0: https://www.bioconductor.org/packages/release/bioc/html/miloR.html Please make sure you are using the most up to date version first.

Also note that the error traceback gives example values causing the problem - these are all NA - so check if you have NA values in your da_results object.

Elo-mars commented 2 months ago

The current version of miloR is 2.0.0: https://www.bioconductor.org/packages/release/bioc/html/miloR.html Please make sure you are using the most up to date version first.

Also note that the error traceback gives example values causing the problem - these are all NA - so check if you have NA values in your da_results object.

thanks for your reply. I'm reinstalling the last version of miloR (don't know why it installed a 1.10) Also, i exported my "da_result" and check for NA values - I do not have any After it re-install the last version of miloR, I will see if it has anything to do with the fact that my "group.by" has "+" characters in that column of da_result, maybe that is causing the whole issue

==> update: still doesn't work

new update: adding "alpha=0.3" solved it for me !