Skip to content

Fixes for ggplot2 3.3.4 #1952

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 3 commits into from
May 17, 2021
Merged
Show file tree
Hide file tree
Changes from all 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
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