Skip to content

Commit 555a443

Browse files
authored
Avoid with() to better account for missing tickvals/ticktext (#2062)
1 parent 49215db commit 555a443

File tree

3 files changed

+23
-7
lines changed

3 files changed

+23
-7
lines changed

Diff for: NEWS.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
* `ggplotly()` now converts `stat_ecdf()` properly. (#2065)
1111
* `ggplotly()` now correctly handles `geom_tile()` with no `fill` aesthetic. (#2063)
12-
12+
* Fixed an issue with translating `GGally::ggcorr()` via `ggplotly()`. (#2012)
1313

1414
# 4.10.0
1515

Diff for: R/ggplotly.R

+6-3
Original file line numberDiff line numberDiff line change
@@ -1390,10 +1390,13 @@ gdef2trace <- function(gdef, theme, gglayout) {
13901390
rng <- range(gdef$bar$value)
13911391
gdef$bar$value <- scales::rescale(gdef$bar$value, from = rng)
13921392
gdef$key$.value <- scales::rescale(gdef$key$.value, from = rng)
1393+
vals <- lapply(gglayout[c("xaxis", "yaxis")], function(ax) {
1394+
if (identical(ax$tickmode, "auto")) ax$ticktext else ax$tickvals
1395+
})
13931396
list(
1394-
x = with(gglayout$xaxis, if (identical(tickmode, "auto")) ticktext else tickvals)[[1]],
1395-
y = with(gglayout$yaxis, if (identical(tickmode, "auto")) ticktext else tickvals)[[1]],
1396-
# esentially to prevent this getting merged at a later point
1397+
x = vals[[1]][[1]],
1398+
y = vals[[2]][[1]],
1399+
# essentially to prevent this getting merged at a later point
13971400
name = gdef$hash,
13981401
type = "scatter",
13991402
mode = "markers",

Diff for: tests/testthat/test-plotly-subplot.R

+16-3
Original file line numberDiff line numberDiff line change
@@ -134,10 +134,23 @@ test_that("subplot accepts a list of plots", {
134134
expect_true(l$layout[[sub("y", "yaxis", xaxes[[1]]$anchor)]]$domain[1] == 0)
135135
})
136136

137-
test_that("ggplotly understands ggmatrix", {
137+
test_that("ggplotly understands GGally", {
138138
skip_if_not_installed("GGally")
139-
L <- expect_doppelganger_built(GGally::ggpairs(iris),
140-
"plotly-subplot-ggmatrix")
139+
expect_doppelganger(
140+
GGally::ggpairs(iris),
141+
"plotly-subplot-ggmatrix"
142+
)
143+
d <- tibble::tibble(
144+
v1 = 1:100 + rnorm(100, sd = 20),
145+
v2 = 1:100 + rnorm(100, sd = 27),
146+
v3 = rep(1, 100) + rnorm(100, sd = 1),
147+
v4 = v1 ** 2,
148+
v5 = v1 ** 2
149+
)
150+
expect_doppelganger(
151+
ggcorr(data, method = c("everything", "pearson")),
152+
"ggally-ggcorr"
153+
)
141154
})
142155

143156
test_that("annotation paper repositioning", {

0 commit comments

Comments
 (0)