Closed
Description
geom_line()
nicely handles NA values in the middle of the data by making the line discontinuous.
I would have expected stat_summary(geom="line")
to do the same, but it connects across the gap which can result in a misleading output plot.
Granted, the docs for stat_summary()
don't promise consistency with geom_line()
so I wouldn't classify this as a bug, but it would be a nice-to-have so I don't need to resort to setting a separate group across every data discontinuity when using stat_summary(geom="line")
library(tidyverse)
# Here, I would expect some way to make stat_summary not connect points
# across an NA value
tibble(x=c(1,2,3,4,5), y=c(1,3,NA,4,2)) |>
ggplot(aes(x, y)) + stat_summary(fun="mean", geom="line")
#> Warning: Removed 1 row containing non-finite outside the scale range
#> (`stat_summary()`).
# geom_line() properly makes the line discontinuous
tibble(x=c(1,2,3,4,5), y=c(1,3,NA,4,2)) |>
ggplot(aes(x, y)) + geom_line()
Created on 2024-12-10 with reprex v2.1.0
Metadata
Metadata
Assignees
Labels
No labels