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 ignores na.value colour (e.g.: in scale_fill_gradientn and others) [bug] #1149

Open
talgalili opened this issue Nov 11, 2017 · 4 comments
Labels

Comments

@talgalili
Copy link
Contributor

talgalili commented Nov 11, 2017

Code to replicate the bug:

library(ggplot2)
library(plotly)
library(viridis)

# If you want to draw arbitrary rectangles, use geom_tile() or geom_rect()
df <- data.frame(
  x = rep(c(2, 5, 7, 9, 12), 2),
  y = rep(c(1, 2), each = 5),
  z = rep(c(1:4, NA), each = 2)
)
p <- ggplot(df, aes(x, y)) +
  geom_tile(aes(fill = z)) + 
  scale_fill_gradientn(
    colors = viridis(256),
    na.value = "red")
p
ggplotly(p)

Output in ggplot2:

image

But this is how it looks in plotly:

image

This is the cause of talgalili/heatmaply#122

I've used this in the latest cutting edge ggplot2 and plotly


> sessionInfo()
R version 3.4.1 (2017-06-30)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 7 x64 (build 7601) Service Pack 1

Matrix products: default

locale:
[1] LC_COLLATE=Hebrew_Israel.1255  LC_CTYPE=Hebrew_Israel.1255   
[3] LC_MONETARY=Hebrew_Israel.1255 LC_NUMERIC=C                  
[5] LC_TIME=Hebrew_Israel.1255    

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

other attached packages:
[1] viridis_0.4.0      viridisLite_0.2.0  plotly_4.7.1.9000  ggplot2_2.2.1.9000
[5] installr_0.20.0    stringr_1.2.0     

loaded via a namespace (and not attached):
 [1] Rcpp_0.12.13        compiler_3.4.1      git2r_0.18.0       
 [4] plyr_1.8.4          bindr_0.1           tools_3.4.1        
 [7] digest_0.6.12       jsonlite_1.5        memoise_1.1.0      
[10] tibble_1.3.4        gtable_0.2.0        pkgconfig_2.0.1    
[13] rlang_0.1.4         shiny_1.0.3         crosstalk_1.0.0    
[16] yaml_2.1.14         curl_2.7            bindrcpp_0.2       
[19] gridExtra_2.2.1     withr_2.1.0.9000    httr_1.3.1         
[22] dplyr_0.7.4.9000    knitr_1.16          htmlwidgets_0.9    
[25] devtools_1.13.2     grid_3.4.1          tidyselect_0.2.3   
[28] glue_1.2.0          data.table_1.10.4-3 R6_2.2.2           
[31] purrr_0.2.4         tidyr_0.7.2         magrittr_1.5       
[34] scales_0.5.0.9000   htmltools_0.3.6     assertthat_0.2.0   
[37] xtable_1.8-2        mime_0.5            colorspace_1.3-2   
[40] httpuv_1.3.5        labeling_0.3        stringi_1.1.5      
[43] lazyeval_0.2.1      munsell_0.4.3      
@stragu
Copy link

stragu commented Jun 4, 2021

This issue could probably be renamed to a more general "ggplotly ignores na.value colour" as it applies also to other functions, like scale_fill_continuous() or scale_fill_gradient().

Here is a minimal reproducible example:

library(ggplot2)
library(plotly)
# default NA colour is "grey50"
(default_na_colour <- ggplot(mapping = aes(x = 1:2, y = 1:2, fill = c(1, NA))) +
  geom_tile())

ggplotly(default_na_colour)

default

# replace default colour
(custom_na_colour <- ggplot(mapping = aes(x = 1:2, y = 1:2, fill = c(1, NA))) +
    geom_tile() +
    scale_fill_continuous(na.value = "red"))

ggplotly(custom_na_colour)

custom

@talgalili talgalili changed the title Bug: ggplotly ignores na.value in scale_fill_gradientn ggplotly ignores na.value colour (e.g.: in scale_fill_gradientn and others) [bug] Jun 5, 2021
@talgalili
Copy link
Contributor Author

@stragu done.

@talgalili
Copy link
Contributor Author

@cpsievert fyi this is a more general issue, see @stragu 's comment.

@MLopez-Ibanez
Copy link
Contributor

Still a problem with 4.10.2.

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

No branches or pull requests

4 participants