tidymodels / infer

An R package for tidyverse-friendly statistical inference
https://infer.tidymodels.org
Other
726 stars 80 forks source link

Warnings about aesthetic length and no non-missing argument to min in visualise + shade_p_value functions #528

Closed pietervreeburg closed 7 months ago

pietervreeburg commented 7 months ago

The problem

When running the visualise + shade_p_value function on a generated and or calculated dataset I receive two warnings:

Warning messages:
1: In (function (mapping = NULL, data = NULL, stat = "identity", position = "identity",  :
  All aesthetics have length 1, but the data has 1000 rows.
ℹ Did you mean to use `annotate()`?
2: In min(diff(unique_loc)) :
  no non-missing arguments to min; returning Inf

Could the cause of these warnings be in the recent ggplot2 release?

Thanks in advance for looking into the issue.

Regards,

Pieter Vreeburg

Reproducible example

library(dplyr)
#> Warning: package 'dplyr' was built under R version 4.2.3
#> 
#> Attaching package: 'dplyr'
#> The following objects are masked from 'package:stats':
#> 
#>     filter, lag
#> The following objects are masked from 'package:base':
#> 
#>     intersect, setdiff, setequal, union
library(forcats)
library(infer)
#> Warning: package 'infer' was built under R version 4.2.3

set.seed(123)

gss <- gss |> 
  mutate(class = fct_drop(class))

h0 <- gss |> 
  specify(class ~ college) |> 
  hypothesise("independence") |> 
  generate(1000, "permute") |> 
  calculate("chisq")

hA <- gss |> 
  specify(class ~ college) |> 
  calculate("chisq")

# no warnings
visualise(h0)

shade_p_value(hA, "right")
#> A p-value shading layer.

# two warnings
visualise(h0) +
  shade_p_value(hA, "right")
#> Warning in (function (mapping = NULL, data = NULL, stat = "identity", position = "identity", : All aesthetics have length 1, but the data has 1000 rows.
#> ℹ Did you mean to use `annotate()`?
#> Warning in min(diff(unique_loc)): no non-missing arguments to min; returning
#> Inf

Created on 2024-03-25 with reprex v2.1.0

Session info ``` r sessioninfo::session_info() #> ─ Session info ─────────────────────────────────────────────────────────────── #> setting value #> version R version 4.2.2 (2022-10-31 ucrt) #> os Windows 10 x64 (build 22631) #> system x86_64, mingw32 #> ui RTerm #> language (EN) #> collate Dutch_Netherlands.utf8 #> ctype Dutch_Netherlands.utf8 #> tz Europe/Berlin #> date 2024-03-25 #> pandoc 3.1.1 @ C:/Program Files/RStudio/resources/app/bin/quarto/bin/tools/ (via rmarkdown) #> #> ─ Packages ─────────────────────────────────────────────────────────────────── #> package * version date (UTC) lib source #> cli 3.6.2 2023-12-11 [1] CRAN (R 4.2.3) #> colorspace 2.1-0 2023-01-23 [1] CRAN (R 4.2.2) #> curl 5.2.1 2024-03-01 [1] CRAN (R 4.2.3) #> digest 0.6.34 2024-01-11 [1] CRAN (R 4.2.3) #> dplyr * 1.1.4 2023-11-17 [1] CRAN (R 4.2.3) #> evaluate 0.23 2023-11-01 [1] CRAN (R 4.2.3) #> fansi 1.0.6 2023-12-08 [1] CRAN (R 4.2.3) #> farver 2.1.1 2022-07-06 [1] CRAN (R 4.2.1) #> fastmap 1.1.1 2023-02-24 [1] CRAN (R 4.2.3) #> forcats * 1.0.0 2023-01-29 [1] CRAN (R 4.2.2) #> fs 1.6.3 2023-07-20 [1] CRAN (R 4.2.3) #> generics 0.1.3 2022-07-05 [1] CRAN (R 4.2.1) #> ggplot2 3.5.0 2024-02-23 [1] CRAN (R 4.2.3) #> glue 1.7.0 2024-01-09 [1] CRAN (R 4.2.3) #> gtable 0.3.4 2023-08-21 [1] CRAN (R 4.2.3) #> highr 0.10 2022-12-22 [1] CRAN (R 4.2.1) #> htmltools 0.5.7 2023-11-03 [1] CRAN (R 4.2.3) #> infer * 1.0.6 2024-01-31 [1] CRAN (R 4.2.3) #> knitr 1.45 2023-10-30 [1] CRAN (R 4.2.3) #> labeling 0.4.3 2023-08-29 [1] CRAN (R 4.2.3) #> lifecycle 1.0.4 2023-11-07 [1] CRAN (R 4.2.3) #> magrittr 2.0.3 2022-03-30 [1] CRAN (R 4.2.0) #> munsell 0.5.0 2018-06-12 [1] CRAN (R 4.2.0) #> pillar 1.9.0 2023-03-22 [1] CRAN (R 4.2.3) #> pkgconfig 2.0.3 2019-09-22 [1] CRAN (R 4.2.0) #> purrr 1.0.2 2023-08-10 [1] CRAN (R 4.2.3) #> R.cache 0.16.0 2022-07-21 [1] CRAN (R 4.2.3) #> R.methodsS3 1.8.2 2022-06-13 [1] CRAN (R 4.2.2) #> R.oo 1.26.0 2024-01-24 [1] CRAN (R 4.2.3) #> R.utils 2.12.3 2023-11-18 [1] CRAN (R 4.2.3) #> R6 2.5.1 2021-08-19 [1] CRAN (R 4.2.0) #> reprex 2.1.0 2024-01-11 [1] CRAN (R 4.2.3) #> rlang 1.1.3 2024-01-10 [1] CRAN (R 4.2.3) #> rmarkdown 2.25 2023-09-18 [1] CRAN (R 4.2.3) #> rstudioapi 0.15.0 2023-07-07 [1] CRAN (R 4.2.3) #> scales 1.3.0 2023-11-28 [1] CRAN (R 4.2.3) #> sessioninfo 1.2.2 2021-12-06 [1] CRAN (R 4.2.2) #> styler 1.10.2 2023-08-29 [1] CRAN (R 4.2.3) #> tibble 3.2.1 2023-03-20 [1] CRAN (R 4.2.3) #> tidyselect 1.2.0 2022-10-10 [1] CRAN (R 4.2.1) #> utf8 1.2.4 2023-10-22 [1] CRAN (R 4.2.3) #> vctrs 0.6.5 2023-12-01 [1] CRAN (R 4.2.3) #> withr 3.0.0 2024-01-16 [1] CRAN (R 4.2.3) #> xfun 0.42 2024-02-08 [1] CRAN (R 4.2.3) #> xml2 1.3.6 2023-12-04 [1] CRAN (R 4.2.3) #> yaml 2.3.8 2023-12-11 [1] CRAN (R 4.2.3) #> #> [1] C:/Users/piete/AppData/Local/R/win-library/4.2 #> [2] C:/Program Files/R/R-4.2.2/library #> #> ────────────────────────────────────────────────────────────────────────────── ```
simonpcouch commented 7 months ago

Thank you, I can reproduce! Both CRAN and dev infer see these warnings. Some notes-to-self...

With the previous ggplot2 release, 3.4.4, one is addressed but the other is still there:

# pak::pak("tidyverse/ggplot2@v3.4.4")

library(dplyr)
#> 
#> Attaching package: 'dplyr'
#> The following objects are masked from 'package:stats':
#> 
#>     filter, lag
#> The following objects are masked from 'package:base':
#> 
#>     intersect, setdiff, setequal, union
library(forcats)
library(infer)

set.seed(123)

gss <- gss |> 
   mutate(class = fct_drop(class))

h0 <- gss |> 
   specify(class ~ college) |> 
   hypothesise("independence") |> 
   generate(1000, "permute") |> 
   calculate("chisq")

hA <- gss |> 
   specify(class ~ college) |> 
   calculate("chisq")

# two warnings
visualise(h0) +
   shade_p_value(hA, "right")
#> Warning in min(diff(unique_loc)): no non-missing arguments to min; returning
#> Inf

Created on 2024-03-25 with reprex v2.1.0

Same output with with 3.4.0, only warnings with 3.3.0 are linewidth ones, which infer introduced.

simonpcouch commented 7 months ago

The warnings come from print.ggplot (and won't appear if you just assign the output, which might explain our lack of test failures).

simonpcouch commented 7 months ago

All aesthetics have length 1 warning from:

https://github.com/tidymodels/infer/blob/7c7c3aac8cffcb8795fdf8c4ee02868421904959/R/shade_p_value.R#L182-L187

Related to https://github.com/tidyverse/ggplot2/issues/5762.

pietervreeburg commented 7 months ago

Thanks for your prompt follow-up @simonpcouch. Very happy that this bug is fixed!

github-actions[bot] commented 7 months ago

This issue has been automatically locked. If you believe you have found a related problem, please file a new issue (with a reprex: https://reprex.tidyverse.org) and link to this issue.