Skip to content
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

Drop lines in geom_sf() with missing linewidth #5516

Merged
merged 4 commits into from
Nov 27, 2023

Conversation

teunbrand
Copy link
Collaborator

This PR aims to fix #5204.

Briefly, this PR just populates the non_missing_aes field of GeomPath, which is used in sf_grob() to determine what rows should be removed. Previously, missing linewidth would result in an error, now a warning. Also GeomPath$handle_na() now reads this field instead of hardcoding the aesthetics (because it seemed the right thing to do).

Reprex from #5204:

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

pts <- sf::st_sf(
  geometry = sf::st_sfc(
    sf::st_linestring(matrix(0:3, nrow = 2)),
    sf::st_linestring(matrix(2:5, nrow = 2))
  ),
  linewidth = c(1, NA)
)

ggplot(pts) + geom_sf(aes(linewidth = linewidth))
#> Warning: Removed 1 row containing missing values or values outside the scale range
#> (`geom_sf()`).

Created on 2023-11-13 with reprex v2.0.2

@teunbrand teunbrand added this to the ggplot2 3.5.0 milestone Nov 21, 2023
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
Copy link
Collaborator Author

Thanks for reviewing!

@teunbrand teunbrand merged commit 091d92a into tidyverse:main Nov 27, 2023
@teunbrand teunbrand deleted the sf_missing_linewidth branch November 27, 2023 14:12
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_sf can't deal with NA-containing linewidth
2 participants