diff --git a/NEWS.md b/NEWS.md index 7b9388beb9..45cbe9d2b5 100644 --- a/NEWS.md +++ b/NEWS.md @@ -4,6 +4,7 @@ * Duplicate `highlight(selectize=T)` dropdowns are no longer rendered in Shiny (#1936). * `group_by.plotly()` now properly retains crosstalk information across `{dplyr}` versions (#1920). +* Adds fixes in `ggplotly()` for the upcoming `{ggplot2}` >3.3.3 release (#1952). * Fixes some issues with `name` and `frames` when both attributes are specified. (#1903 and #1618). # 4.9.3 diff --git a/R/ggplotly.R b/R/ggplotly.R index bd55daaa83..19a0850809 100644 --- a/R/ggplotly.R +++ b/R/ggplotly.R @@ -1099,7 +1099,7 @@ gg2list <- function(p, width = NULL, height = NULL, # start build a plotly object with meta information about the ggplot # first, translate layer mappings -> plotly attrs mappingFormulas <- lapply(layers, function(x) { - mappings <- c(x$mapping, if (isTRUE(x$inherit.aes)) plot$mapping) + mappings <- getAesMap(plot, x) if (originalData) { lapply(mappings, lazyeval::f_new) } else { @@ -1427,3 +1427,12 @@ gdef2trace <- function(gdef, theme, gglayout) { NULL } } + + +getAesMap <- function(plot, layer) { + if (isTRUE(layer$inherit.aes)) { + modify_list(plot$mapping, layer$mapping) + } else { + layer$mapping + } +} diff --git a/R/layers2layout.R b/R/layers2layout.R index cf5afac4b5..bf628afd95 100644 --- a/R/layers2layout.R +++ b/R/layers2layout.R @@ -3,7 +3,7 @@ layers2layout <- function(gglayout, layers, layout) { geoms <- sapply(layers, function(x) class(x[["geom"]])[1]) RasterGeom <- which(geoms %in% "GeomRasterAnn") for (i in RasterGeom) { - params <- layers[[i]]$geom_params + params <- layers[[i]]$computed_geom_params %||% layers[[i]]$geom_params for (j in seq_len(nrow(layout))) { lay <- layout[j, ] diff --git a/R/layers2traces.R b/R/layers2traces.R index 3428ea67ac..168307d96e 100644 --- a/R/layers2traces.R +++ b/R/layers2traces.R @@ -6,12 +6,13 @@ layers2traces <- function(data, prestats_data, layout, p) { # Extract parameters (and "hovertext aesthetics") in each layer params <- Map(function(x, y) { param <- c( - y[["geom_params"]], y[["stat_params"]], y[["aes_params"]], + y[["computed_geom_params"]] %||% y[["geom_params"]], + y[["computed_stat_params"]] %||% y[["stat_params"]], + y[["aes_params"]], position = ggtype(y, "position") ) - # add on plot-level mappings, if they're inherited - map <- c(y$mapping, if (isTRUE(y$inherit.aes)) p$mapping) + map <- getAesMap(p, y) # consider "calculated" aesthetics (e.g., density, count, etc) calc_aes <- y$stat$default_aes[ggfun("is_calculated_aes")(y$stat$default_aes)]