Skip to content

Using annotate() rather than geom_segment in critical difference plots to avoid warning #45

Description

@jemus42

Reprex:

library(mlr3benchmark)
library(ggplot2)

# Create a simple benchmark aggregation dataset
set.seed(123)

xdat = expand.grid(
  task_id = factor(paste0("Task", 1:10)),
  learner_id = factor(paste0("Learner", 1:3))
)

xdat$RMSE[xdat$learner_id == "Learner1"] <- runif(10, 1, 2)
xdat$RMSE[xdat$learner_id == "Learner2"] <- runif(10, 5, 6)
xdat$RMSE[xdat$learner_id == "Learner3"] <- runif(10, 8, 10)

# Create BenchmarkAggr object
ba <- BenchmarkAggr$new(xdat)

autoplot(
  ba,
  type = "cd",
  test = "bd",
  meas = "RMSE",
  style = 1
)
#> Warning in geom_segment(aes(x = 0, xend = max(rank) + 1, y = 0, yend = 0)): All aesthetics have length 1, but the data has 3 rows.
#> ℹ Please consider using `annotate()` or provide this layer with data containing
#>   a single row.

packageVersion("ggplot2")
#> [1] '3.5.2'
packageVersion("mlr3benchmark")
#> [1] '0.1.7.9000'

Created on 2025-08-04 with reprex v2.1.1

Session info

sessioninfo::session_info()
#> ─ Session info ───────────────────────────────────────────────────────────────
#>  setting  value
#>  version  R version 4.4.3 (2025-02-28)
#>  os       macOS Sequoia 15.5
#>  system   aarch64, darwin20
#>  ui       X11
#>  language (EN)
#>  collate  en_US.UTF-8
#>  ctype    en_US.UTF-8
#>  tz       Europe/Berlin
#>  date     2025-08-04
#>  pandoc   3.7.0.2 @ /usr/local/bin/ (via rmarkdown)
#>  quarto   1.7.32 @ /Applications/quarto/bin/quarto
#> 
#> ─ Packages ───────────────────────────────────────────────────────────────────
#>  package       * version    date (UTC) lib source
#>  backports       1.5.0      2024-05-23 [1] CRAN (R 4.4.0)
#>  BWStest         0.2.3      2023-10-10 [1] CRAN (R 4.4.0)
#>  cachem          1.1.0      2024-05-16 [1] CRAN (R 4.4.0)
#>  checkmate       2.3.2      2024-07-29 [1] CRAN (R 4.4.0)
#>  cli             3.6.5      2025-04-23 [1] CRAN (R 4.4.1)
#>  curl            6.4.0      2025-06-22 [1] CRAN (R 4.4.1)
#>  data.table      1.17.8     2025-07-10 [1] CRAN (R 4.4.1)
#>  digest          0.6.37     2024-08-19 [1] CRAN (R 4.4.1)
#>  dplyr           1.1.4      2023-11-17 [1] CRAN (R 4.4.0)
#>  evaluate        1.0.4      2025-06-18 [1] CRAN (R 4.4.1)
#>  farver          2.1.2      2024-05-13 [1] CRAN (R 4.4.0)
#>  fastmap         1.2.0      2024-05-15 [1] CRAN (R 4.4.0)
#>  fs              1.6.6      2025-04-12 [1] CRAN (R 4.4.1)
#>  generics        0.1.4      2025-05-09 [1] CRAN (R 4.4.1)
#>  ggplot2       * 3.5.2      2025-04-09 [1] CRAN (R 4.4.1)
#>  glue            1.8.0      2024-09-30 [1] CRAN (R 4.4.1)
#>  gmp             0.7-5      2024-08-23 [1] CRAN (R 4.4.1)
#>  gtable          0.3.6      2024-10-25 [1] CRAN (R 4.4.1)
#>  htmltools       0.5.8.1    2024-04-04 [1] CRAN (R 4.4.0)
#>  knitr           1.50       2025-03-16 [1] CRAN (R 4.4.1)
#>  kSamples        1.2-10     2023-10-07 [1] CRAN (R 4.4.0)
#>  labeling        0.4.3      2023-08-29 [1] CRAN (R 4.4.0)
#>  lifecycle       1.0.4      2023-11-07 [1] CRAN (R 4.4.0)
#>  magrittr        2.0.3      2022-03-30 [1] CRAN (R 4.4.0)
#>  MASS            7.3-65     2025-02-28 [1] CRAN (R 4.4.1)
#>  memoise         2.0.1      2021-11-26 [1] CRAN (R 4.4.0)
#>  mlr3benchmark * 0.1.7-9000 2025-08-04 [1] Github (mlr-org/mlr3benchmark@a87e639)
#>  mlr3misc        0.18.0     2025-05-26 [1] CRAN (R 4.4.1)
#>  multcompView    0.1-10     2024-03-08 [1] CRAN (R 4.4.0)
#>  mvtnorm         1.3-3      2025-01-10 [1] CRAN (R 4.4.1)
#>  pillar          1.11.0     2025-07-04 [1] CRAN (R 4.4.1)
#>  pkgconfig       2.0.3      2019-09-22 [1] CRAN (R 4.4.0)
#>  PMCMRplus       1.9.12     2024-09-08 [1] CRAN (R 4.4.1)
#>  R6              2.6.1      2025-02-15 [1] CRAN (R 4.4.1)
#>  RColorBrewer    1.1-3      2022-04-03 [1] CRAN (R 4.4.0)
#>  Rcpp            1.1.0      2025-07-02 [1] CRAN (R 4.4.1)
#>  reprex          2.1.1      2024-07-06 [1] CRAN (R 4.4.0)
#>  rlang           1.1.6      2025-04-11 [1] CRAN (R 4.4.1)
#>  rmarkdown       2.29       2024-11-04 [1] CRAN (R 4.4.1)
#>  Rmpfr           1.1-1      2025-07-18 [1] CRAN (R 4.4.1)
#>  scales          1.4.0      2025-04-24 [1] CRAN (R 4.4.1)
#>  sessioninfo     1.2.3      2025-02-05 [1] CRAN (R 4.4.1)
#>  SuppDists       1.1-9.9    2025-03-24 [1] CRAN (R 4.4.1)
#>  tibble          3.3.0      2025-06-08 [1] CRAN (R 4.4.1)
#>  tidyselect      1.2.1      2024-03-11 [1] CRAN (R 4.4.0)
#>  vctrs           0.6.5      2023-12-01 [1] CRAN (R 4.4.0)
#>  withr           3.0.2      2024-10-28 [1] CRAN (R 4.4.1)
#>  xfun            0.52       2025-04-02 [1] CRAN (R 4.4.1)
#>  xml2            1.3.8      2025-03-14 [1] CRAN (R 4.4.1)
#>  yaml            2.3.10     2024-07-26 [1] CRAN (R 4.4.0)
#> 
#>  [1] /Users/Lukas/Library/R/arm64/4.4/library
#>  [2] /Library/Frameworks/R.framework/Versions/4.4-arm64/Resources/library
#>  * ── Packages attached to the search path.
#> 
#> ──────────────────────────────────────────────────────────────────────────────

Fix is probably trivial, will make a PR later

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions