the legend doesn't appear in ggplotly when I use guide in ggplot :
library(plotly)
library(ggplot2)
library(dplyr)
diamonds %>%
group_by(cut,color) %>%
summarise(price = mean(price)) %>%
ggplot(aes(x=cut,y=price,fill= color))+
geom_bar(stat='identity') +
guides(fill = guide_legend(reverse = TRUE)) -> t
ggplotly(t)
If I remove the line with guides, no problem :
diamonds %>%
group_by(cut,color) %>%
summarise(price = mean(price)) %>%
ggplot(aes(x=cut,y=price,fill= color))+
geom_bar(stat='identity') -> t
ggplotly(t)
How could I use the guide but still keep the legend in ggplotly ?
Edit : As spotted by @Stefan, the problem was that I used plotly 4.10.3, after updating, legend appears normally.
guides()in the past, i.e. check your plotly version. Mine is4.10.4.reverse=TRUEseems to have no effect. So you probably have to that by converting to a factor with reversed levels.