Skip to content

Commit e10663f

Browse files
committed
More workarounds for dev ggplot2
1 parent ee22264 commit e10663f

File tree

1 file changed

+25
-4
lines changed

1 file changed

+25
-4
lines changed

R/ggplotly.R

+25-4
Original file line numberDiff line numberDiff line change
@@ -398,6 +398,9 @@ gg2list <- function(p, width = NULL, height = NULL,
398398
layout$setup_panel_params()
399399
data <- layout$map_position(data)
400400

401+
# Hand off position guides to layout
402+
layout$setup_panel_guides(plot$guides, plot$layers)
403+
401404
# Train and map non-position scales
402405
npscales <- scales$non_position_scales()
403406
if (npscales$n() > 0) {
@@ -416,6 +419,15 @@ gg2list <- function(p, width = NULL, height = NULL,
416419
data <- lapply(data, scales_map_df, scales = npscales)
417420
}
418421

422+
if (npscales$n() > 0) {
423+
plot$guides <- plot$guides$build(
424+
npscales, plot$layers, plot$labels, data
425+
)
426+
} else {
427+
# Assign empty guides if there are no non-position scales
428+
plot$guides <- ggfun("guides_list")()
429+
}
430+
419431
# Fill in defaults etc.
420432
data <- by_layer(function(l, d) l$compute_geom_2(d))
421433

@@ -1005,7 +1017,7 @@ gg2list <- function(p, width = NULL, height = NULL,
10051017
theme$legend.box.just <- theme$legend.box.just %||% c("center", "center")
10061018
# scales -> data for guides
10071019
gdefs <- if (inherits(plot$guides, "ggproto")) {
1008-
get_gdefs_ggproto(npscales$scales, theme, plot, layers)
1020+
get_gdefs_ggproto(npscales$scales, theme, plot, layers, data)
10091021
} else {
10101022
get_gdefs(scales, theme, plot, layers)
10111023
}
@@ -1511,7 +1523,7 @@ scales_add_missing <- function(plot, aesthetics) {
15111523
# which away from guides_train(), guides_merge(), guides_geom()
15121524
# towards ggproto methods attached to `plot$guides`
15131525
# -------------------------------------------------------------------------
1514-
get_gdefs_ggproto <- function(scales, theme, plot, layers) {
1526+
get_gdefs_ggproto <- function(scales, theme, plot, layers, layer_data) {
15151527

15161528
# Unfortunate duplication of logic in tidyverse/ggplot2#5428
15171529
# which ensures a 1:1 mapping between aesthetics and scales
@@ -1520,10 +1532,19 @@ get_gdefs_ggproto <- function(scales, theme, plot, layers) {
15201532
aesthetics <- unlist(aesthetics, recursive = FALSE, use.names = FALSE)
15211533

15221534
guides <- plot$guides$setup(scales, aesthetics = aesthetics)
1523-
guides$train(scales, theme$legend.direction, plot$labels)
1535+
if (get_package_version("ggplot2") > "3.4.4") {
1536+
guides$train(scales, plot$labels)
1537+
} else {
1538+
guides$train(scales, theme$legend.direction, plot$labels)
1539+
}
1540+
15241541
if (length(guides$guides) > 0) {
15251542
guides$merge()
1526-
guides$process_layers(layers)
1543+
if (get_package_version("ggplot2") > "3.4.4") {
1544+
guides$process_layers(layers, layer_data)
1545+
} else {
1546+
guides$process_layers(layers)
1547+
}
15271548
}
15281549
# Add old legend/colorbar classes to guide params so that ggplotly() code
15291550
# can continue to work the same way it always has

0 commit comments

Comments
 (0)