plotting of zeros on log scales in ggplot2

Hi All,

I seem to have run into the following problem following a version change of ggplot2: zeros on the log scale no longer get correctly plotted snug at the bottom of the display area. Warning messages are still produced but since this change is new, if you had been expected this to occur, there is a risk that you might mis-read your data.

The issue seems to be internally related to -Inf and NA, and can be sporadic, but I'm reporting it in case it is something more fundamental. The default vertical jitter on position_jitter() is also now no longer zero which I know was a potential issue in the past.

I can send an Rmarkdown generated file it this helps: did not have permission as a Newbie on this site.

Yours,
David


Zeros on a log scale (a.k.a. -Inf) no longer get plotted neatly as half points
at the bottom of the plot. Whilst the below works fine

A=data.frame(group=rep(LETTERS[1:2],each=5),value=rep(0:1,each=5))
g1=ggplot(A,aes(group,value)) + geom_point(position=position_jitter(0.2,0))
g1

the points (group A)

g1 + scale_y_log10()

now just disappear with an error message about missing values as distinct from -Infs.
As a possible workaround you can still do

g1 + scale_y_log10(na.value=-Inf)

which gives the required plot re-coding the 'missings' as the desired -Infs (i.e. under the
hood the code is all still there) but the behaviour is still unexpected and might mean that you
miss some data points (e.g. zeros) you would expect to be able to see if you were not aware. You also need to be sure that you have no real missings in your data.

For reference, the following is the output of sessionInfo().

## R version 4.0.4 (2021-02-15)
## Platform: x86_64-w64-mingw32/x64 (64-bit)
## Running under: Windows 10 x64 (build 19042)
## 
## Matrix products: default
## 
## locale:
## [1] LC_COLLATE=English_United Kingdom.1252 
## [2] LC_CTYPE=English_United Kingdom.1252   
## [3] LC_MONETARY=English_United Kingdom.1252
## [4] LC_NUMERIC=C                           
## [5] LC_TIME=English_United Kingdom.1252    
## 
## attached base packages:
## [1] stats     graphics  grDevices utils     datasets  methods   base     
## 
## other attached packages:
## [1] forcats_0.5.1   stringr_1.4.0   dplyr_1.0.5     purrr_0.3.4    
## [5] readr_1.4.0     tidyr_1.1.3     tibble_3.1.0    ggplot2_3.3.6  
## [9] tidyverse_1.3.0
## 
## loaded via a namespace (and not attached):
##  [1] tidyselect_1.1.0 xfun_0.30        bslib_0.3.1      haven_2.3.1     
##  [5] colorspace_2.0-0 vctrs_0.3.6      generics_0.1.0   htmltools_0.5.2 
##  [9] yaml_2.2.1       utf8_1.1.4       rlang_0.4.10     jquerylib_0.1.3 
## [13] pillar_1.5.1     withr_2.4.1      glue_1.4.2       DBI_1.1.1       
## [17] dbplyr_2.1.0     modelr_0.1.8     readxl_1.3.1     lifecycle_1.0.0 
## [21] munsell_0.5.0    gtable_0.3.0     cellranger_1.1.0 rvest_0.3.6     
## [25] evaluate_0.14    labeling_0.4.2   knitr_1.31       fastmap_1.1.0   
## [29] fansi_0.4.2      highr_0.8        broom_0.7.5      Rcpp_1.0.7      
## [33] backports_1.2.1  scales_1.1.1     jsonlite_1.7.2   farver_2.1.0    
## [37] fs_1.5.0         hms_1.0.0        digest_0.6.27    stringi_1.5.3   
## [41] grid_4.0.4       cli_2.3.1        tools_4.0.4      magrittr_2.0.1  
## [45] sass_0.4.1       crayon_1.4.1     pkgconfig_2.0.3  ellipsis_0.3.1  
## [49] xml2_1.3.2       reprex_1.0.0     lubridate_1.7.10 rstudioapi_0.13 
## [53] assertthat_0.2.1 rmarkdown_2.14   httr_1.4.2       R6_2.5.0        
## [57] compiler_4.0.4

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.