8000 Handle recent changes to ggplot2's `plot_build()` logic by cpsievert · Pull Request #2262 · plotly/plotly.R · GitHub
[go: up one dir, main page]

Skip to content

Handle recent changes to ggplot2's plot_build() logic #2262

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 10 commits into from
May 5, 2023
Prev Previous commit
Next Next commit
Fix more changes in colorscale parameters
  • Loading branch information
cpsievert committed May 4, 2023
commit 33ca9bda9bdb7a02233298cd8865656221bd8167
17 changes: 13 additions & 4 deletions R/ggplotly.R
Original file line number Diff line number Diff line change
Expand Up @@ -1403,12 +1403,21 @@ gdef2trace <- function(gdef, theme, gglayout) {
if (inherits(gdef, "colorbar")) {
# sometimes the key has missing values, which we can ignore
gdef$key <- gdef$key[!is.na(gdef$key$.value), ]
rng <- range(gdef$bar$value)
gdef$bar$value <- scales::rescale(gdef$bar$value, from = rng)
gdef$key$.value <- scales::rescale(gdef$key$.value, from = rng)

# Put values on a 0-1 scale
# N.B. ggplot2 >v3.4.2 (specifically #4879) renamed bar to decor and also
# started returning normalized values for the key field
decor <- gdef$decor %||% gdef$bar
rng <- range(decor$value)
decor$value <- scales::rescale(decor$value, from = rng)
if (!"decor" %in% names(gdef)) {
gdef$key$.value <- scales::rescale(gdef$key$.value, from = rng)
}

vals <- lapply(gglayout[c("xaxis", "yaxis")], function(ax) {
if (identical(ax$tickmode, "auto")) ax$ticktext else ax$tickvals
})

list(
x = vals[[1]][[1]],
y = vals[[2]][[1]],
Expand All @@ -1422,7 +1431,7 @@ gdef2trace <- function(gdef, theme, gglayout) {
# do everything on a 0-1 scale
marker = list(
color = c(0, 1),
colorscale = setNames(gdef$bar[c("value", "colour")], NULL),
colorscale = setNames(decor[c("value", "colour")], NULL),
45FD colorbar = list(
bgcolor = toRGB(theme$legend.background$fill),
bordercolor = toRGB(theme$legend.background$colour),
Expand Down
0