Skip to content

geom_curve() removes missing data #5832

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

Merged
merged 4 commits into from
Apr 29, 2024

Conversation

teunbrand
Copy link
Collaborator

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

@agneeshbarua
Copy link

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.

@teunbrand
Copy link
Collaborator Author

teunbrand commented Apr 11, 2024

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.

Copy link
Member

@thomasp85 thomasp85 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@teunbrand teunbrand merged commit 09bcda6 into tidyverse:main Apr 29, 2024
7 of 12 checks passed
@teunbrand teunbrand deleted the curve_remove_missing branch April 29, 2024 08:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

geom_segment and geom_curve discrepancy
3 participants