Skip to content

Commit

Permalink
Fixes for ggplot2 3.3.4 (#1952)
Browse files Browse the repository at this point in the history
* Close #1951: use computed_[geom/stat]_params over [geom/stat]_params if available

* Merge instead of combine layer and plot aes mappings

* update news
  • Loading branch information
cpsievert authored May 17, 2021
1 parent e02a704 commit 598120b
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 5 deletions.
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 10 additions & 1 deletion R/ggplotly.R
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
}
}
2 changes: 1 addition & 1 deletion R/layers2layout.R
Original file line number Diff line number Diff line change
Expand Up @@ -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, ]

Expand Down
7 changes: 4 additions & 3 deletions R/layers2traces.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down

0 comments on commit 598120b

Please sign in to comment.