diff --git a/R/geom-raster.R b/R/geom-raster.R index 819692cea5..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")) { + 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 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", {