From ae7cd4bfc7bb6847e6b3362646e169dc486006be Mon Sep 17 00:00:00 2001 From: Carson Date: Mon, 1 Nov 2021 16:26:48 -0500 Subject: [PATCH 1/3] Close #1562: handle geom_tile() with no fill aesthetic --- R/layers2traces.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/layers2traces.R b/R/layers2traces.R index 8ddd90c156..6970560147 100644 --- a/R/layers2traces.R +++ b/R/layers2traces.R @@ -367,7 +367,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)) { data <- prefix_class(data, "GeomRect") to_basic(data, prestats_data, layout, params, p) } else { From 0af684b0ec00d48a26755f629f25d6cf92bae6f6 Mon Sep 17 00:00:00 2001 From: Carson Date: Mon, 1 Nov 2021 16:30:21 -0500 Subject: [PATCH 2/3] add visual test --- tests/testthat/test-ggplot-heatmap.R | 9 +++++++++ 1 file changed, 9 insertions(+) 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") +}) + From 3cb46d46ab51450c2201c055d58ff6d06c1b4473 Mon Sep 17 00:00:00 2001 From: Carson Date: Mon, 1 Nov 2021 16:34:23 -0500 Subject: [PATCH 3/3] update news --- NEWS.md | 4 ++++ R/layers2traces.R | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/NEWS.md b/NEWS.md index 56775ea13a..cdbe6cd2eb 100644 --- a/NEWS.md +++ b/NEWS.md @@ -4,6 +4,10 @@ * `ggplotly()` does not issue warnings with `options(warnPartialMatchArgs = TRUE)` any longer. (#2046, @bersbersbers) +## Bug fixes + +* `ggplotly()` now correctly handles `geom_tile()` with no `fill` aesthetic. (#2063) + # 4.10.0 ## Breaking changes in JavaScript API diff --git a/R/layers2traces.R b/R/layers2traces.R index 6970560147..c7443cc179 100644 --- a/R/layers2traces.R +++ b/R/layers2traces.R @@ -367,7 +367,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 %||% NA)) { + if (is.discrete(prestats_data$fill %||% NA_character_)) { data <- prefix_class(data, "GeomRect") to_basic(data, prestats_data, layout, params, p) } else {