Skip to content
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

ggplotly is not working properly with scale_fill_binned #2357

Closed
thgsponer opened this issue Jun 1, 2024 · 2 comments · Fixed by #2359
Closed

ggplotly is not working properly with scale_fill_binned #2357

thgsponer opened this issue Jun 1, 2024 · 2 comments · Fixed by #2359

Comments

@thgsponer
Copy link

I had exactly the same issue as described in #5892. After updating the plotly package to version 4.10.4 most of my plots worked well.

However, in the follwing situation ggplotly does not work properly.

library(ggplot2)
library(plotly)

xy_grid <- expand.grid(ps=seq(-1,3, length=100),
                       trs=seq(-1,3,length=100))
xy_grid$ptl <-  xy_grid$ps^2 + xy_grid$trs^2

theme_set(theme_bw())
g1 <- ggplot(xy_grid) +
  geom_raster(aes(y=ps,x=trs,fill=ptl), interpolate = TRUE) +
  geom_contour(aes(y=ps,x=trs,z=ptl), breaks = c(2,4,6,8,10), color='black')

# this works
ggplotly(g1)

# adding scale_fill_binned
g2 <- g1 + scale_fill_binned(low = 'red', high = 'green', breaks = c(2,4,6,8,10))

# this does not work
ggplotly(g2)

For the second plot (g2), when using ggplotly I get the following error:

Error in `[.data.frame`(decor, c("value", "colour")) : 
  undefined columns selected

sessionInfo:

R version 4.3.2 (2023-10-31 ucrt)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 11 x64 (build 22631)

Matrix products: default


locale:
[1] LC_COLLATE=English_Switzerland.utf8  LC_CTYPE=English_Switzerland.utf8   
[3] LC_MONETARY=English_Switzerland.utf8 LC_NUMERIC=C                        
[5] LC_TIME=English_Switzerland.utf8    

time zone: Europe/Zurich
tzcode source: internal

attached base packages:
[1] stats     graphics  grDevices datasets  utils     methods   base     

other attached packages:
[1] plotly_4.10.4 ggplot2_3.5.1

The example above works in the following session:

R version 4.3.2 (2023-10-31 ucrt)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 11 x64 (build 22631)

Matrix products: default


locale:
[1] LC_COLLATE=English_Switzerland.utf8  LC_CTYPE=English_Switzerland.utf8   
[3] LC_MONETARY=English_Switzerland.utf8 LC_NUMERIC=C                        
[5] LC_TIME=English_Switzerland.utf8    

time zone: Europe/Zurich
tzcode source: internal

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] plotly_4.10.3 ggplot2_3.4.4

Ursprünglich gepostet von @thgsponer in tidyverse/ggplot2#5926

cpsievert added a commit that referenced this issue Jun 3, 2024
cpsievert added a commit that referenced this issue Jun 3, 2024
…hinytest2 (#2359)

* Use new complete_theme() function to get the complete set of theme elements

* Refactor and reuse logic in tests

* Fix kaleido install

* Accept good snapshot changes

* Disable windows oldrel

* Close #2357. In some cases, decor has min/max instead of value. In that case, treat max like value

* Accept new historgram binning changes

* Make sure layout-specific shapes go underneath traces

* Accept new snapshots; migrate to shinytest2

* Check-in snapshots
@mbarkdull
Copy link

I am also having this issue (with scale_fill_steps2). I tried installing the latest development version with remotes::install_github("plotly/plotly"), and the error persists.

@cpsievert
Copy link
Collaborator

Hi @mbarkdull, sorry to hear that. A new issue with a reproducible example would help us keep track of it (and thus more likely to fix it)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants