Skip to content

Commit

Permalink
Updates for recent changes to ggplot2 ggproto guide API (#2315)
Browse files Browse the repository at this point in the history
  • Loading branch information
cpsievert authored Nov 10, 2023
1 parent ee22264 commit d76e87e
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
4 changes: 4 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# plotly (development version)

## Improvements

* `ggplotly()` now works better with the development version of ggplot2 (> v3.4.4). (#2315)

# 4.10.3

## Improvements
Expand Down
8 changes: 4 additions & 4 deletions R/ggplotly.R
Original file line number Diff line number Diff line change
Expand Up @@ -1005,7 +1005,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 +1511,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,10 +1520,10 @@ 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)
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
Expand Down

0 comments on commit d76e87e

Please sign in to comment.