diff --git a/NEWS.md b/NEWS.md index 1ab0b563a1..a8b7b1019f 100644 --- a/NEWS.md +++ b/NEWS.md @@ -8,6 +8,8 @@ ## Bug fixes * `ggplotly()` now converts `stat_ecdf()` properly. (#2065) +* `ggplotly()` now correctly handles `geom_tile()` with no `fill` aesthetic. (#2063) + # 4.10.0 diff --git a/R/layers2traces.R b/R/layers2traces.R index 3c040d9781..6a6ad2dd6b 100644 --- a/R/layers2traces.R +++ b/R/layers2traces.R @@ -368,7 +368,7 @@ to_basic.GeomRasterAnn <- function(data, prestats_data, layout, params, p, ...) #' @export to_basic.GeomTile <- function(data, prestats_data, layout, params, p, ...) { # geom2trace.GeomTile is a heatmap, which requires continuous fill - if (is.discrete(prestats_data$fill)) { + if (is.discrete(prestats_data$fill %||% NA_character_)) { data <- prefix_class(data, "GeomRect") to_basic(data, prestats_data, layout, params, p) } else { diff --git a/tests/testthat/test-ggplot-heatmap.R b/tests/testthat/test-ggplot-heatmap.R index 28ccb1be0c..44b6c0cc14 100644 --- a/tests/testthat/test-ggplot-heatmap.R +++ b/tests/testthat/test-ggplot-heatmap.R @@ -63,3 +63,12 @@ test_that("geom_tile() with discrete x/y", { expect_equivalent(L$data[[1]]$type, "heatmap") }) +test_that("geom_tile() with no fill aesthetic", { + df <- data.frame( + x = rep(c(2, 5, 7, 9, 12), 2), + y = rep(c(1, 2), each = 5) + ) + p <- ggplot(df, aes(x, y)) + geom_tile(colour = "grey50") + expect_doppelganger(ggplotly(p), "tile-no-fill") +}) +