Skip to content

geom_text throws error when angle = NA #2757

Closed
@baderstine

Description

@baderstine

When using geom_text() if the angle parameter is set using a variable whose value can be NA then geom_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).

library(ggplot2)
df <- data.frame(x=seq(1,10,1), y=seq(1,10,1), angle=c(seq(0,80,10),NA))

# this works:
ggplot(df[1:9,], aes(x=x, y=y)) + geom_text(label="-", aes(angle=angle))

# this breaks:
ggplot(df, aes(x=x, y=y)) + geom_text(label="-", aes(angle=angle))
# with error:
# Error in validDetails.text(x) : invalid 'rot' value
# also a confusing error because the user did not pass a 'rot' parameter.
# that 'rot' == 'rotation' == 'angle' may not be entirely clear to users.

image

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions