Error message not that helpful in `labs()` if set to `element_blank()`
Opened this issue · 1 comments
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
I agree that the warning isn't helpful: it should be an error instead.
I don't think it is right for ggplot2 to police what {grid} accepts as display text.
The warning is a backward compatibility measure to not break every package that put theme elements as labels.
It will be removed in favor of an error at some point in the future once packages have been afforded some time to change.
IMO, plotly is handling this correctly and it is ggplot2 who should handle it the same way (in a while).