Skip to content

Error message not that helpful in labs() if set to element_blank() #6619

@olivroy

Description

@olivroy

I used to do this to remove axis labels

ggplot(mtcars, aes(cyl, mpg)) + geom_point() + labs(x = element_blank())

With the new ggplot2, I get the new warning.

#> `label` cannot be a <ggplot2::element_blank> object. 

The warning isn't that helpful. Took me a while to figure it out in a big plot construction.

Turns out I just have to use labs(x = NULL) instead.

I will change that everywhere in my code. But the problem comes when I use ggplotly().

ggplotly(ggplot(mtcars, aes(cyl, mpg)) + geom_point() + labs(x = element_blank()))
#> Erreur in as.vector(x, "character") : 
#>  cannot coerce type 'object' to vector of type 'character'

I wonder if that's an issue that should be fixed in ggplot2 (better warning), plotly (work with this), or my code. Possibly all 3, but I guess we can wait for more reports before taking action. I will update my code to get rid of element_blank() in the labs() calls.

Research notes
Changes occured in #6364

https://github.com/tidyverse/ggplot2/blame/961b194941380faa77addafd9d9f46b2d105ba8e/tests/testthat/_snaps/theme.md#L124

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