Skip to content

Commit 598120b

Browse files
authored
Fixes for ggplot2 3.3.4 (#1952)
* Close #1951: use computed_[geom/stat]_params over [geom/stat]_params if available * Merge instead of combine layer and plot aes mappings * update news
1 parent e02a704 commit 598120b

File tree

4 files changed

+16
-5
lines changed

4 files changed

+16
-5
lines changed

NEWS.md

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
* Duplicate `highlight(selectize=T)` dropdowns are no longer rendered in Shiny (#1936).
66
* `group_by.plotly()` now properly retains crosstalk information across `{dplyr}` versions (#1920).
7+
* Adds fixes in `ggplotly()` for the upcoming `{ggplot2}` >3.3.3 release (#1952).
78
* Fixes some issues with `name` and `frames` when both attributes are specified. (#1903 and #1618).
89

910
# 4.9.3

R/ggplotly.R

+10-1
Original file line numberDiff line numberDiff line change
@@ -1099,7 +1099,7 @@ gg2list <- function(p, width = NULL, height = NULL,
10991099
# start build a plotly object with meta information about the ggplot
11001100
# first, translate layer mappings -> plotly attrs
11011101
mappingFormulas <- lapply(layers, function(x) {
1102-
mappings <- c(x$mapping, if (isTRUE(x$inherit.aes)) plot$mapping)
1102+
mappings <- getAesMap(plot, x)
11031103
if (originalData) {
11041104
lapply(mappings, lazyeval::f_new)
11051105
} else {
@@ -1427,3 +1427,12 @@ gdef2trace <- function(gdef, theme, gglayout) {
14271427
NULL
14281428
}
14291429
}
1430+
1431+
1432+
getAesMap <- function(plot, layer) {
1433+
if (isTRUE(layer$inherit.aes)) {
1434+
modify_list(plot$mapping, layer$mapping)
1435+
} else {
1436+
layer$mapping
1437+
}
1438+
}

R/layers2layout.R

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ layers2layout <- function(gglayout, layers, layout) {
33
geoms <- sapply(layers, function(x) class(x[["geom"]])[1])
44
RasterGeom <- which(geoms %in% "GeomRasterAnn")
55
for (i in RasterGeom) {
6-
params <- layers[[i]]$geom_params
6+
params <- layers[[i]]$computed_geom_params %||% layers[[i]]$geom_params
77
for (j in seq_len(nrow(layout))) {
88
lay <- layout[j, ]
99

R/layers2traces.R

+4-3
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,13 @@ layers2traces <- function(data, prestats_data, layout, p) {
66
# Extract parameters (and "hovertext aesthetics") in each layer
77
params <- Map(function(x, y) {
88
param <- c(
9-
y[["geom_params"]], y[["stat_params"]], y[["aes_params"]],
9+
y[["computed_geom_params"]] %||% y[["geom_params"]],
10+
y[["computed_stat_params"]] %||% y[["stat_params"]],
11+
y[["aes_params"]],
1012
position = ggtype(y, "position")
1113
)
1214

13-
# add on plot-level mappings, if they're inherited
14-
map <- c(y$mapping, if (isTRUE(y$inherit.aes)) p$mapping)
15+
map <- getAesMap(p, y)
1516

1617
# consider "calculated" aesthetics (e.g., density, count, etc)
1718
calc_aes <- y$stat$default_aes[ggfun("is_calculated_aes")(y$stat$default_aes)]

0 commit comments

Comments
 (0)