Skip to content

Updates for recent changes to ggplot2 ggproto guide API #2315

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Nov 10, 2023
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions R/ggplotly.R
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,9 @@ gg2list <- function(p, width = NULL, height = NULL,
layout$setup_panel_params()
data <- layout$map_position(data)

# Hand off position guides to layout
layout$setup_panel_guides(plot$guides, plot$layers)

# Train and map non-position scales
npscales <- scales$non_position_scales()
if (npscales$n() > 0) {
Expand Down Expand Up @@ -1005,7 +1008,7 @@ gg2list <- function(p, width = NULL, height = NULL,
theme$legend.box.just <- theme$legend.box.just %||% c("center", "center")
# scales -> data for guides
gdefs <- if (inherits(plot$guides, "ggproto")) {
get_gdefs_ggproto(npscales$scales, theme, plot, layers)
get_gdefs_ggproto(npscales$scales, theme, plot, layers, data)
} else {
get_gdefs(scales, theme, plot, layers)
}
Expand Down Expand Up @@ -1511,7 +1514,7 @@ scales_add_missing <- function(plot, aesthetics) {
# which away from guides_train(), guides_merge(), guides_geom()
# towards ggproto methods attached to `plot$guides`
# -------------------------------------------------------------------------
get_gdefs_ggproto <- function(scales, theme, plot, layers) {
get_gdefs_ggproto <- function(scales, theme, plot, layers, layer_data) {

# Unfortunate duplication of logic in tidyverse/ggplot2#5428
# which ensures a 1:1 mapping between aesthetics and scales
Expand All @@ -1520,11 +1523,14 @@ get_gdefs_ggproto <- function(scales, theme, plot, layers) {
aesthetics <- unlist(aesthetics, recursive = FALSE, use.names = FALSE)

guides <- plot$guides$setup(scales, aesthetics = aesthetics)
guides$train(scales, theme$legend.direction, plot$labels)
guides$train(scales, plot$labels)

if (length(guides$guides) > 0) {
guides$merge()
guides$process_layers(layers)
# TODO: seems as though this should be dropping guides?
guides$process_layers(layers, layer_data)
}

# Add old legend/colorbar classes to guide params so that ggplotly() code
# can continue to work the same way it always has
for (i in which(vapply(guides$guides, inherits, logical(1), "GuideColourbar"))) {
Expand Down