Skip to content

Commit 8a94f66

Browse files
committed
Close #2259: handle recent changes to ggplot2's plot_build() logic
1 parent 9ee5480 commit 8a94f66

File tree

1 file changed

+37
-4
lines changed

1 file changed

+37
-4
lines changed

R/ggplotly.R

+37-4
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,7 @@ gg2list <- function(p, width = NULL, height = NULL,
314314
})
315315

316316
# Transform all scales
317-
data <- lapply(data, ggfun("scales_transform_df"), scales = scales)
317+
data <- lapply(data, scales_transform_df, scales = scales)
318318

319319
# Map and train positions so that statistics have access to ranges
320320
# and all positions are numeric
@@ -368,7 +368,7 @@ gg2list <- function(p, width = NULL, height = NULL,
368368
data <- by_layer(function(l, d) l$map_statistic(d, plot))
369369

370370
# Make sure missing (but required) aesthetics are added
371-
ggfun("scales_add_missing")(plot, c("x", "y"), plot$plot_env)
371+
scales_add_missing(plot, c("x", "y"))
372372

373373
# Reparameterise geoms from (e.g.) y and width to ymin and ymax
374374
data <- by_layer(function(l, d) l$compute_geom_1(d))
@@ -401,7 +401,7 @@ gg2list <- function(p, width = NULL, height = NULL,
401401
# Train and map non-position scales
402402
npscales <- scales$non_position_scales()
403403
if (npscales$n() > 0) {
404-
lapply(data, ggfun("scales_train_df"), scales = npscales)
404+
lapply(data, scales_train_df, scales = npscales)
405405
# this for loop is unique to plotly -- it saves the "domain"
406406
# of each non-positional scale for display in tooltips
407407
for (sc in npscales$scales) {
@@ -413,7 +413,7 @@ gg2list <- function(p, width = NULL, height = NULL,
413413
d
414414
})
415415
}
416-
data <- lapply(data, ggfun("scales_map_df"), scales = npscales)
416+
data <- lapply(data, scales_map_df, scales = npscales)
417417
}
418418

419419
# Fill in defaults etc.
@@ -1459,3 +1459,36 @@ getAesMap <- function(plot, layer) {
14591459
layer$mapping
14601460
}
14611461
}
1462+
1463+
# Handle compatibility for changes in ggplot2 >v3.4.2 (#5144)
1464+
scales_transform_df <- function(scales, df) {
1465+
if (is.function(scales$transform_df)) {
1466+
scales$transform_df(df)
1467+
} else {
1468+
ggfun("scales_transform_df")(df, scales = scales)
1469+
}
1470+
}
1471+
1472+
scales_train_df <- function(scales, df) {
1473+
if (is.function(scales$train_df)) {
1474+
scales$train_df(df)
1475+
} else {
1476+
ggfun("scales_train_df")(df, scales = scales)
1477+
}
1478+
}
1479+
1480+
scales_map_df <- function(scales, df) {
1481+
if (is.function(scales$map_df)) {
1482+
scales$map_df(df)
1483+
} else {
1484+
ggfun("scales_map_df")(df, scales = scales)
1485+
}
1486+
}
1487+
1488+
scales_add_missing <- function(plot, aesthetics) {
1489+
if (length(plot$scales$add_missing)) {
1490+
plot$scales$add_missing(c("x", "y"), plot$plot_env)
1491+
} else {
1492+
ggfun("scales_add_missing")(plot, aesthetics, plot$plot_env)
1493+
}
1494+
}

0 commit comments

Comments
 (0)