Skip to content

ggplotly does not work when adding scale_fill_binned #5926

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

Closed
thgsponer opened this issue Jun 1, 2024 · 1 comment
Closed

ggplotly does not work when adding scale_fill_binned #5926

thgsponer opened this issue Jun 1, 2024 · 1 comment

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
@teunbrand
Copy link
Collaborator

We updated guide_coloursteps() recently, and I think plotly just hasn't caught up yet.
It is up to {plotly} to decide what features they implement and which they don't, it isn't really something that can be fixed in ggplot2. The alternative is to reverse the change, but we made the change for a good reason.
You can use guide = "colourbar" to display the regular colourbar guide.

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

No branches or pull requests

2 participants