Skip to content

ggplotly error when xlab is element_blank() #1731

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
doorisajar opened this issue Mar 30, 2020 · 1 comment
Closed

ggplotly error when xlab is element_blank() #1731

doorisajar opened this issue Mar 30, 2020 · 1 comment

Comments

@doorisajar
Copy link

Reprex:

library(ggplot2)
library(plotly)

p <- ggplot(iris, aes(Petal.Length, Sepal.Width, color = Species)) + 
    geom_point() + 
    xlab(element_blank())

ggplotly(p)
#> Error in if (nchar(axisTitleText) > 0) {: argument is of length zero

That seems to be happening here:

https://github.com/ropensci/plotly/blob/ebb017a6fbd1a582787017f98e8e40cb4f1431b3/R/ggplotly.R#L817

xlab("") works, so the issue is definitely that nchar of a theme element that is set to element_blank() is NULL. The same check happens a few lines later:

https://github.com/ropensci/plotly/blob/ebb017a6fbd1a582787017f98e8e40cb4f1431b3/R/ggplotly.R#L839

I get the same error when setting ylab and ggtitle to element_blank, but not for setting the legend title to blank via theme(legend.title = element_blank()).

I might be able to do a pretty minimal PR for this. The tests look reasonably straightforward.

@doorisajar
Copy link
Author

I submitted a PR for this: #1732

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

Successfully merging a pull request may close this issue.

1 participant