Skip to content

Colorbar created with legendry::guide_colbar and ggplot2::scale_color/fill_gradient2 not rendered correctly in version 1.4.0 #192

Description

@trekonom

"Diverging" colorbars created with legendry::guide_colbar and scale_color/fill_gradient2 are no longer rendered correctly in ragg version 1.4.0, i.e. the "upper" part of the colorbar looks like a binned guide, whereas the "lower" one is fine.

Not sure whether this is an issue on side of ragg as the issue does not arise with e.g. ggplot2::guide_colorbar, but as the same code worked fine with version 1.3.3 ...

library(legendry)
#> Loading required package: ggplot2
library(ragg)

packageVersion("legendry")
#> [1] '0.2.1'
packageVersion("ragg")
#> [1] '1.4.0'

p <- ggplot(mtcars, aes(mpg, hp, color = cyl)) +
  geom_point() +
  scale_color_gradient2(
    midpoint = 6,
    guide = guide_colbar()
  )

file <- tempfile(fileext = ".png")
ggsave(file, device = ragg::agg_png)
#> Saving 7 x 5 in image

knitr::include_graphics(file)

Created on 2025-05-28 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-05-28
#>  pandoc   3.4 @ /Applications/RStudio.app/Contents/Resources/app/quarto/bin/tools/aarch64/ (via rmarkdown)
#>  quarto   1.6.39 @ /usr/local/bin/quarto
#> 
#> ─ Packages ───────────────────────────────────────────────────────────────────
#>  package      * version date (UTC) lib source
#>  cli            3.6.5   2025-04-23 [1] CRAN (R 4.4.1)
#>  curl           6.2.3   2025-05-24 [1] CRAN (R 4.4.1)
#>  dichromat      2.0-0.1 2022-05-02 [1] CRAN (R 4.4.0)
#>  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.3   2025-01-10 [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)
#>  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)
#>  labeling       0.4.3   2023-08-29 [1] CRAN (R 4.4.0)
#>  legendry     * 0.2.1   2025-03-04 [1] CRAN (R 4.4.1)
#>  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)
#>  pillar         1.10.2  2025-04-05 [1] CRAN (R 4.4.1)
#>  pkgconfig      2.0.3   2019-09-22 [1] CRAN (R 4.4.0)
#>  png            0.1-8   2022-11-29 [1] CRAN (R 4.4.0)
#>  R6             2.6.1   2025-02-15 [1] CRAN (R 4.4.1)
#>  ragg         * 1.4.0   2025-04-10 [1] CRAN (R 4.4.1)
#>  RColorBrewer   1.1-3   2022-04-03 [1] CRAN (R 4.4.0)
#>  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)
#>  rstudioapi     0.17.1  2024-10-22 [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)
#>  systemfonts    1.2.3   2025-04-30 [1] CRAN (R 4.4.1)
#>  textshaping    1.0.1   2025-05-01 [1] CRAN (R 4.4.1)
#>  tibble         3.2.1   2023-03-20 [1] CRAN (R 4.4.0)
#>  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] /Library/Frameworks/R.framework/Versions/4.4-arm64/Resources/library
#>  * ── Packages attached to the search path.
#> 
#> ──────────────────────────────────────────────────────────────────────────────

And as a reference, using ragg version 1.3.3 gives the desired result:

library(legendry)
#> Loading required package: ggplot2
library(ragg)

packageVersion("legendry")
#> [1] '0.2.1'
packageVersion("ragg")
#> [1] '1.3.3'

p <- ggplot(mtcars, aes(mpg, hp, color = cyl)) +
  geom_point() +
  scale_color_gradient2(
    midpoint = 6,
    guide = guide_colbar()
  )

file <- tempfile(fileext = ".png")
ggsave(file, device = ragg::agg_png)
#> Saving 7 x 5 in image

knitr::include_graphics(file)

Created on 2025-05-28 with reprex v2.1.1

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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