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

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

Closed
pietervreeburg opened this issue Mar 25, 2024 · 5 comments · Fixed by #529
Labels
bug an unexpected problem or unintended behavior

Comments

@pietervreeburg
Copy link

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
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
#> 
#> ──────────────────────────────────────────────────────────────────────────────
@pietervreeburg pietervreeburg changed the title Warnings about aesthetic length and no non-missing argument to min in visualise + shade_p_value function Warnings about aesthetic length and no non-missing argument to min in visualise + shade_p_value functions Mar 25, 2024
@simonpcouch
Copy link
Collaborator

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
Copy link
Collaborator

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
Copy link
Collaborator

simonpcouch commented Mar 25, 2024

All aesthetics have length 1 warning from:

infer/R/shade_p_value.R

Lines 182 to 187 in 7c7c3aa

list(
# Here `aes()` is needed to force {ggplot2} to include segment in the plot
mapping = aes(x = obs_stat, xend = obs_stat, y = 0, yend = Inf),
color = color,
inherit.aes = FALSE
),

Related to tidyverse/ggplot2#5762.

@simonpcouch simonpcouch added the bug an unexpected problem or unintended behavior label Mar 25, 2024
@pietervreeburg
Copy link
Author

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

Copy link

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.

@github-actions github-actions bot locked and limited conversation to collaborators Apr 16, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug an unexpected problem or unintended behavior
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants