Skip to content

plotly not showing legend when using ggplot2::geom_line() #476

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
lucacerone opened this issue Mar 2, 2016 · 2 comments
Closed

plotly not showing legend when using ggplot2::geom_line() #476

lucacerone opened this issue Mar 2, 2016 · 2 comments

Comments

@lucacerone
Copy link

Plotly (version 2.4.4) does not convert correctly legends in plots that have only lines,
for example:

library(ggplot2)
library(plotly)
p <- ggplot(iris, aes(x=Sepal.Width, y = Sepal.Length, color=Species)) + geom_line()
p #note: ggplot2 puts a legend here
ggplotly(p) #does not show the legend

whereas works as expected:

library(ggplot2)
library(plotly)
p <- ggplot(iris, aes(x=Sepal.Width, y = Sepal.Length, color=Species)) + geom_point()
p #note: ggplot2 puts a legend here
ggplotly(p) #plotly puts the legend

here is the output of devtools::session_info()

Session info ----------------------------------------------------------------------------------------------------------------------------------------------------------------
 setting  value                       
 version  R version 3.2.3 (2015-12-10)
 system   x86_64, linux-gnu           
 ui       RStudio (0.99.486)          
 language (EN)                        
 collate  en_US.UTF-8                 
 tz       <NA>                        
 date     2016-03-02                  

Packages --------------------------------------------------------------------------------------------------------------------------------------------------------------------
 package     * version     date       source                          
 base64enc     0.1-3       2015-07-28 CRAN (R 3.2.3)                  
 colorspace    1.2-6       2015-03-11 CRAN (R 3.2.3)                  
 devtools      1.10.0.9000 2016-01-29 Github (hadley/devtools@2c08890)
 digest        0.6.9       2016-01-08 CRAN (R 3.2.3)                  
 ggplot2     * 2.0.0       2015-12-18 CRAN (R 3.2.3)                  
 gridExtra     2.2.1       2016-02-29 CRAN (R 3.2.3)                  
 gtable        0.2.0       2016-02-26 CRAN (R 3.2.3)                  
 htmltools     0.3         2015-12-29 CRAN (R 3.2.3)                  
 htmlwidgets   0.6         2016-02-25 CRAN (R 3.2.3)                  
 httr          1.1.0       2016-01-28 CRAN (R 3.2.3)                  
 jsonlite      0.9.19      2015-11-28 CRAN (R 3.2.3)                  
 labeling      0.3         2014-08-23 CRAN (R 3.2.3)                  
 magrittr      1.5         2014-11-22 CRAN (R 3.2.3)                  
 memoise       1.0.0       2016-01-29 CRAN (R 3.2.3)                  
 munsell       0.4.3       2016-02-13 CRAN (R 3.2.3)                  
 plotly      * 2.4.4       2016-02-29 Github (ropensci/plotly@b79e9d2)
 plyr          1.8.3       2015-06-12 CRAN (R 3.2.3)                  
 R6            2.1.2       2016-01-26 CRAN (R 3.2.3)                  
 Rcpp          0.12.3      2016-01-10 CRAN (R 3.2.3)                  
 scales        0.4.0       2016-02-26 CRAN (R 3.2.3)                  
 viridis       0.3.2       2015-12-31 CRAN (R 3.2.3)                  
 yaml          2.1.13      2014-06-12 CRAN (R 3.2.3) 
@ahsanshah
Copy link

I had this issue...you can force ploly to show a legend bu doing a plotly_build on the object and then using:

p_gg<-plotly_build(p_gg) # convert ggplot object to plotly
p_gg$layout$showlegend = "TRUE"

@cpsievert
Copy link
Collaborator

This should be fixed in f1900cc. Let us know if you still have problems.

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

3 participants