Skip to content

Commit 109d049

Browse files
authored
geom_raster() fallback for non-linear Cartesian coordinates (#6383)
* exclude non-linear Cartesian children * simplify case * use snapshot test
1 parent 3914e13 commit 109d049

File tree

3 files changed

+12
-3
lines changed

3 files changed

+12
-3
lines changed

R/geom-raster.R

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,10 @@ GeomRaster <- ggproto("GeomRaster", Geom,
5252

5353
draw_panel = function(self, data, panel_params, coord, interpolate = FALSE,
5454
hjust = 0.5, vjust = 0.5) {
55-
if (!inherits(coord, "CoordCartesian")) {
55+
if (!coord$is_linear()) {
5656
cli::cli_inform(c(
57-
"{.fn {snake_class(self)}} only works with {.fn coord_cartesian}.",
57+
"{.fn {snake_class(self)}} only works with linear coordinate systems, \\
58+
not {.fn {snake_class(coord)}}.",
5859
i = "Falling back to drawing as {.fn {snake_class(GeomRect)}}."
5960
))
6061
data$linewidth <- 0.3 # preventing anti-aliasing artefacts

tests/testthat/_snaps/geom-raster.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,14 @@
1414

1515
`vjust` must be a number, not the string "a".
1616

17+
---
18+
19+
Code
20+
b <- ggplotGrob(p)
21+
Message
22+
`geom_raster()` only works with linear coordinate systems, not `coord_polar()`.
23+
i Falling back to drawing as `geom_rect()`.
24+
1725
# geom_raster() fails with pattern fills
1826

1927
Problem while converting geom to grob.

tests/testthat/test-geom-raster.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ test_that("geom_raster() checks input and coordinate system", {
66

77
df <- data_frame(x = rep(c(-1, 1), each = 3), y = rep(-1:1, 2), z = 1:6)
88
p <- ggplot(df, aes(x, y, fill = z)) + geom_raster() + coord_polar()
9-
expect_message(ggplotGrob(p), "only works with")
9+
expect_snapshot(b <- ggplotGrob(p))
1010
})
1111

1212
test_that("geom_raster() fails with pattern fills", {

0 commit comments

Comments
 (0)