-
Notifications
You must be signed in to change notification settings - Fork 2.1k
geom_text throws error when angle = NA #2757
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
Possible hitch in this — with an optional aesthetic you would presumably just not pass a value to it at all if you don't want to use it. Because it's an angle of a label, if the label exists, but the angle does not, I'm not sure it would be expected the label not be plotted at all because of a missing angle. |
I disagree that 'you would presumably just not pass a value to it at all if you don't want to use it'. ggplot(df, aes(x=x, y=y)) + geom_text(label="-", aes(color=angle))
# works perfectly fine My point is that NA values to "angle" should be handled as gracefully as NA values to other aesthetics (whether optional or not), rather than prevent the plot from returning. I do not believe the function's job is to decide whether the user is doing something silly or not. It is to do what the user requested. If the user passes angle = NA, either:
|
This makes more sense (to me), since presumably a label has been passed, but an angle has not. |
Yes, I implement this behavior for themes. It would make sense to implement it for geoms as well. |
I think it makes more sense for this to be fixed in grid, not in ggplot2. |
aha... in the source for geom-text.r, the actual function called is |
Not sure how I would request that to be fixed in grid... |
Send a friendly requests to @pmur002. |
You called ? I want to have a bit of a think about consistency here - as pointed out, col=NA draws nothing (usually), though I also buy the argument that it would be unfortunate that if you accidentally produced rot=NA that nothing gets drawn (silently). But this is now on my list! |
I've updated my previous comments with images of the plots that are produced. To be clear, col=NA does appear to plot the point as I showed above... "when an NA value is encountered by the color aesthetic it (rather arbitrarily) chooses grey and continues to make the plot." (silently) To be honest, I was thinking of the very specific use case of wind direction plots. In this use case, if you choose |
Thanks for clarifying. The color=NA converting to grey is, I think, a 'ggplot2' behaviour (possibly an attempt to represent missing values rather than just drop them?). In the core graphics ('graphics' or 'grid'), col=NA translates to "transparent" ...
There is still a good argument for having rot=NA produce something other than an error (in 'grid'), but there may also be a 'ggplot2' layer of behaviour to add on top of that. |
When using
geom_text()
if the angle parameter is set using a variable whose value can beNA
thengeom_text()
throws an error (Error in validDetails.text(x) : invalid 'rot' value
) when it encounters the NA value. Desired behavior would be to handle this gracefully and simply NOT plot the NA value (as would happen with other aesthetics).The text was updated successfully, but these errors were encountered: