Black Lives Matter. Please consider donating to Black Girls Code today.

Plotly misrenders legend on a ggplot2 filled bar chart

I am having some issues with ggplotly not rendering legends correctly on certain types of plots. If I create a filled bar chart with ggplot with more than one fill value, the legend works fine. If I create a chart with just a single fill value, the legend does not display correctly.

A correct plot can be generated with the following code:

a=data.frame(data=rep(1:5,4),cat=rep(c("a","b","c","d"),5))
qplot(data=a, data, fill=cat)
ggplotly()

The error can be reproduced as follows:

a=data.frame(data=rep(1:5,4),cat=rep("a",20))
qplot(data=a, data, fill=cat, binwidth = .5)
ggplotly()

Note that ggplot renders the chart correctly.

ggplotly however generates this:

Note that the plot renders the same way to the RStudio viewer and an external browser.

I am running plotly version 3.4.13 and R version 3.2.4. sessionInfo():

R version 3.2.4 (2016-03-10)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 7 x64 (build 7601) Service Pack 1

locale:
[1] LC_COLLATE=English_United States.1252  LC_CTYPE=English_United States.1252   
[3] LC_MONETARY=English_United States.1252 LC_NUMERIC=C                          
[5] LC_TIME=English_United States.1252    

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

other attached packages:
[1] plotly_3.4.13    ggplot2_2.1.0    RJDBC_0.2-5      rJava_0.9-8      DBI_0.3.1       
[6] manipulate_1.0.1 plotrix_3.6-1    googleVis_0.5.10

loaded via a namespace (and not attached):
 [1] Rcpp_0.12.3       magrittr_1.5      whisker_0.3-2     munsell_0.4.3     colorspace_1.2-6 
 [6] lattice_0.20-33   R6_2.1.2          dplyr_0.4.3       httr_1.1.0        plyr_1.8.3       
[11] tools_3.2.4       rCharts_0.4.2     parallel_3.2.4    grid_3.2.4        gtable_0.2.0     
[16] htmltools_0.3     assertthat_0.1    yaml_2.1.13       digest_0.6.9      RJSONIO_1.3-0    
[21] gridExtra_2.2.1   tidyr_0.4.1       viridis_0.3.4     base64enc_0.1-3   htmlwidgets_0.6  
[26] rsconnect_0.4.1.4 labeling_0.3      scales_0.4.0      jsonlite_0.9.19  

Thanks.

Tom

P.S. Is the the right place to put this bug report, or should I enter an issue on github?

Tom

This for now is a known bug i believe.

Ok, thanks for the update. Do you happen to know the bug id on github? I’d like to be able to track the progress.

Thanks.

Tom

This is part of the issue - https://github.com/ropensci/plotly/issues/510