From dc6598d1aa0d89d84e6369461b8c8af0dc41f987 Mon Sep 17 00:00:00 2001 From: Teun van den Brand Date: Thu, 27 Mar 2025 13:01:38 +0100 Subject: [PATCH 1/3] exclude non-linear Cartesian children --- R/geom-raster.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/geom-raster.R b/R/geom-raster.R index 819692cea5..b4b29b6bb0 100644 --- a/R/geom-raster.R +++ b/R/geom-raster.R @@ -90,7 +90,7 @@ GeomRaster <- ggproto("GeomRaster", Geom, draw_panel = function(self, data, panel_params, coord, interpolate = FALSE, hjust = 0.5, vjust = 0.5) { - if (!inherits(coord, "CoordCartesian")) { + if (!inherits(coord, "CoordCartesian") || !coord$is_linear()) { cli::cli_inform(c( "{.fn {snake_class(self)}} only works with {.fn coord_cartesian}.", i = "Falling back to drawing as {.fn {snake_class(GeomRect)}}." From a6fd43f4881644f86255d55ec70beabd7b0aac3f Mon Sep 17 00:00:00 2001 From: Teun van den Brand Date: Mon, 19 May 2025 12:45:14 +0200 Subject: [PATCH 2/3] simplify case --- R/geom-raster.R | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/R/geom-raster.R b/R/geom-raster.R index b4b29b6bb0..e687466fda 100644 --- a/R/geom-raster.R +++ b/R/geom-raster.R @@ -90,9 +90,10 @@ GeomRaster <- ggproto("GeomRaster", Geom, draw_panel = function(self, data, panel_params, coord, interpolate = FALSE, hjust = 0.5, vjust = 0.5) { - if (!inherits(coord, "CoordCartesian") || !coord$is_linear()) { + if (!coord$is_linear()) { cli::cli_inform(c( - "{.fn {snake_class(self)}} only works with {.fn coord_cartesian}.", + "{.fn {snake_class(self)}} only works with linear coordinate systems, \\ + not {.fn {snake_class(coord)}}.", i = "Falling back to drawing as {.fn {snake_class(GeomRect)}}." )) data$linewidth <- 0.3 # preventing anti-aliasing artefacts From 1c80441427dc8e8eaee2e73ff3605fd55804b31d Mon Sep 17 00:00:00 2001 From: Teun van den Brand Date: Mon, 19 May 2025 12:54:02 +0200 Subject: [PATCH 3/3] use snapshot test --- tests/testthat/_snaps/geom-raster.md | 8 ++++++++ tests/testthat/test-geom-raster.R | 2 +- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/tests/testthat/_snaps/geom-raster.md b/tests/testthat/_snaps/geom-raster.md index 4deac92872..fb949273c1 100644 --- a/tests/testthat/_snaps/geom-raster.md +++ b/tests/testthat/_snaps/geom-raster.md @@ -14,6 +14,14 @@ `vjust` must be a number, not the string "a". +--- + + Code + b <- ggplotGrob(p) + Message + `geom_raster()` only works with linear coordinate systems, not `coord_polar()`. + i Falling back to drawing as `geom_rect()`. + # geom_raster() fails with pattern fills Problem while converting geom to grob. diff --git a/tests/testthat/test-geom-raster.R b/tests/testthat/test-geom-raster.R index 2a3ed66a31..4ce3ad2a7d 100644 --- a/tests/testthat/test-geom-raster.R +++ b/tests/testthat/test-geom-raster.R @@ -6,7 +6,7 @@ test_that("geom_raster() checks input and coordinate system", { df <- data_frame(x = rep(c(-1, 1), each = 3), y = rep(-1:1, 2), z = 1:6) p <- ggplot(df, aes(x, y, fill = z)) + geom_raster() + coord_polar() - expect_message(ggplotGrob(p), "only works with") + expect_snapshot(b <- ggplotGrob(p)) }) test_that("geom_raster() fails with pattern fills", {