Skip to content

linetype = NA should imply no line, not errors #6269

Closed
@teunbrand

Description

@teunbrand

When using it with lines, the observations get flagged as missing and get removed.

library(ggplot2)

p <- ggplot(data.frame(x = 1:2, y = 1:2), aes(x, y))
p + geom_line(linetype = NA)
#> Warning: Removed 2 rows containing missing values or values outside the scale range
#> (`geom_line()`).

However, if we don't throw away such observations, we invite errors from grid.

p + geom_tile(linetype = NA)
#> Error in grid.Call.graphics(C_rect, x$x, x$y, x$width, x$height, resolveHJust(x$just, : invalid line type

Created on 2025-01-06 with reprex v2.1.1

This can be painful when using scales, as in #6097 we've changed scale_linetype()$na.value to NA.
My suggestion for non-line geometries is to translate these NAs to "blank" or 0, depending on the type.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugan unexpected problem or unintended behavior

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions