Skip to content

ggplotly error when xlab is element_blank() #1731

Closed
@doorisajar

Description

@doorisajar

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions