ggplot2 icon indicating copy to clipboard operation
ggplot2 copied to clipboard

`geom_curve()` removes missing data

Open teunbrand opened this issue 2 months ago • 2 comments

This PR aims to fix #5831.

Briefly, it now applies remove_missing() before forwarding the data to curveGrob(). This prevents an issue with when the endpoints are missing values.

In the reprex from the issue below, the NA produced by dplyr::lead() is appropriately removed and warned about, and the plot renders as expected.

devtools::load_all("~/packages/ggplot2")
#> ℹ Loading ggplot2

dtc <- data.frame(
  node = c("A","B","C"),
  x_connect = c(60,32,80),
  y_connect = c(39,88,110)
)

ggplot(dtc, aes(x = x_connect, y = y_connect)) + 
  geom_point(size=5)+
  geom_curve(aes(xend = dplyr::lead(x_connect), yend = dplyr::lead(y_connect)))
#> Warning: Removed 1 row containing missing values or values outside the scale range
#> (`geom_curve()`).

Created on 2024-04-08 with reprex v2.1.0

teunbrand avatar Apr 08 '24 08:04 teunbrand

Greetings,

Thank you for the fix!

Any idea when this PR will be merged? I am writing a publication and would need this bug fix for plotting and reproducibility.

agneeshbarua avatar Apr 10 '24 08:04 agneeshbarua

It will probably not be included in the upcoming version, so it might be quite a wait. If you'd need a reproducible way to do this before then, I'd recommend either defining a small extension to GeomCurve in a helper script that wraps the proposed changes in this PR, or omitting the rows with NAs manually.

teunbrand avatar Apr 11 '24 15:04 teunbrand