-
Notifications
You must be signed in to change notification settings - Fork 633
ggplotly produces legend even if suppressed in ggplot #842
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
Comments
Here is a dirty solution to get rid of the legend by disabling it in the ggplotly object: library(ggplot2)
library(plotly)
dat <- data.frame( time = factor(c("Lunch","Dinner"), levels=c("Lunch","Dinner")), total_bill = c(14.89, 17.23))
# No legend, since the information is redundant
p <- ggplot(data=dat, aes(x=time, y=total_bill, fill=time)) + geom_bar(colour="black", stat="identity") + guides(fill=FALSE)
p <- ggplotly(p)
for (i in 1:nrow(dat)){
p$x$data[[i]]$text <- c(p$x$data[[i]]$text, "")
p$x$data[[i]]$showlegend <- FALSE
}
p |
you can use |
This is more than satisfactory, thank you. |
Thanks for suggesting the "dirty hack" @supersambo Surely there must be a more elegant way to do this though?
|
any chance this can be re-opened @romunov? I ran into the same problem, and would love a cleaner solution long-term. |
Here you go, @maxheld83. |
Hi, have you guys tired hide_legend. I have tried and it worked for me. |
Please use |
User on Stackoverflow reported that legends/guides are not suppressed even when explicitly told so when constructing the
ggplot
object. For completeness, here's an excerpt from the questionwith
plotly
package version 4.5.6.The text was updated successfully, but these errors were encountered: