Skip to content

Let geom_sf() remove rows when shape, size or colour is NA - #3491

Merged
yutannihilation merged 4 commits into
tidyverse:masterfrom
yutannihilation:fix/issue-3483-geom-sf-handle-na
Aug 24, 2019
Merged

yutannihilation merged 4 commits into
tidyverse:masterfrom
yutannihilation:fix/issue-3483-geom-sf-handle-na

Conversation

@yutannihilation

Copy link
Copy Markdown
Member

Fix #3483

Currently, GeomSf doesn't have non_missing_aes, but it should be set to avoid errors reported on #3483. I chose shape, size and colour here because

  • As GeomSf is a mix of points, lines, and polygons, it should use the combination of non_missing_aes of GeomPoint, GeomLine and GeomPolygon.
    • GeomPoint uses shape, size and colour
    • GeomLine and GeomPolygon don't have their non_missing_aes.
  • For lines and polygons, GeomSf removes rows (e.g. the size is NA) that GeomLine and GeomPolygon won't. But, the result is the same; lines and polygons whose sizes are all NA won't be drawn. So, I think it's no problem to remove the whole rows.
devtools::load_all("~/repo/R/ggplot2")
#> Loading ggplot2

pts <- sf::st_sf(
  geometry = sf::st_sfc(sf::st_point(0:1), sf::st_point(1:2)),
  size = c(1, NA),
  shape = c("a", NA),
  colour = c("red", NA)
)

ggplot(pts) + geom_sf(aes(size = size))
#> Warning: Removed 1 rows containing missing values (geom_sf).

ggplot(pts) + geom_sf(aes(shape = shape))
#> Warning: Removed 1 rows containing missing values (geom_sf).

# default colour scale maps a colour even to a NA, so identity scale is needed to see if NA is removed
ggplot(pts) + geom_sf(aes(colour = colour)) + scale_colour_identity()
#> Warning: Removed 1 rows containing missing values (geom_sf).

Created on 2019-08-18 by the reprex package (v0.3.0)

@thomasp85 thomasp85 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM

@yutannihilation

Copy link
Copy Markdown
Member Author

Thanks!

@yutannihilation
yutannihilation merged commit 9870890 into tidyverse:master Aug 24, 2019
@yutannihilation
yutannihilation deleted the fix/issue-3483-geom-sf-handle-na branch August 24, 2019 14:49
@lock

lock Bot commented Feb 21, 2020

Copy link
Copy Markdown

This old issue has been automatically locked. If you believe you have found a related problem, please file a new issue (with reprex) and link to this issue. https://reprex.tidyverse.org/

@lock lock Bot locked and limited conversation to collaborators Feb 21, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Sizing geom_sf point data with variable containing NAs

2 participants