diff --git a/NEWS.md b/NEWS.md index a8b7b1019f..0c8c4ab142 100644 --- a/NEWS.md +++ b/NEWS.md @@ -9,7 +9,7 @@ * `ggplotly()` now converts `stat_ecdf()` properly. (#2065) * `ggplotly()` now correctly handles `geom_tile()` with no `fill` aesthetic. (#2063) - +* Fixed an issue with translating `GGally::ggcorr()` via `ggplotly()`. (#2012) # 4.10.0 diff --git a/R/ggplotly.R b/R/ggplotly.R index acaceee702..44aaf73ba9 100644 --- a/R/ggplotly.R +++ b/R/ggplotly.R @@ -1390,10 +1390,13 @@ gdef2trace <- function(gdef, theme, gglayout) { rng <- range(gdef$bar$value) gdef$bar$value <- scales::rescale(gdef$bar$value, from = rng) gdef$key$.value <- scales::rescale(gdef$key$.value, from = rng) + vals <- lapply(gglayout[c("xaxis", "yaxis")], function(ax) { + if (identical(ax$tickmode, "auto")) ax$ticktext else ax$tickvals + }) list( - x = with(gglayout$xaxis, if (identical(tickmode, "auto")) ticktext else tickvals)[[1]], - y = with(gglayout$yaxis, if (identical(tickmode, "auto")) ticktext else tickvals)[[1]], - # esentially to prevent this getting merged at a later point + x = vals[[1]][[1]], + y = vals[[2]][[1]], + # essentially to prevent this getting merged at a later point name = gdef$hash, type = "scatter", mode = "markers", diff --git a/tests/testthat/test-plotly-subplot.R b/tests/testthat/test-plotly-subplot.R index bdde04fc04..e91b733cfe 100644 --- a/tests/testthat/test-plotly-subplot.R +++ b/tests/testthat/test-plotly-subplot.R @@ -134,10 +134,23 @@ test_that("subplot accepts a list of plots", { expect_true(l$layout[[sub("y", "yaxis", xaxes[[1]]$anchor)]]$domain[1] == 0) }) -test_that("ggplotly understands ggmatrix", { +test_that("ggplotly understands GGally", { skip_if_not_installed("GGally") - L <- expect_doppelganger_built(GGally::ggpairs(iris), - "plotly-subplot-ggmatrix") + expect_doppelganger( + GGally::ggpairs(iris), + "plotly-subplot-ggmatrix" + ) + d <- tibble::tibble( + v1 = 1:100 + rnorm(100, sd = 20), + v2 = 1:100 + rnorm(100, sd = 27), + v3 = rep(1, 100) + rnorm(100, sd = 1), + v4 = v1 ** 2, + v5 = v1 ** 2 + ) + expect_doppelganger( + ggcorr(data, method = c("everything", "pearson")), + "ggally-ggcorr" + ) }) test_that("annotation paper repositioning", {