Skip to content

Regression: geom_sf() is now too aggressive in removing rows #3536

Closed

Description

@clauswilke

I just encountered this problem where geom_sf() removes polygons that are plotted without outline. This is a regression in current ggplot2 master. I assume it's due to #3491.

cc @yutannihilation

library(ggplot2)
library(sf)
#> Linking to GEOS 3.7.2, GDAL 2.4.2, PROJ 5.2.0

# make outline of the world in robinson coordinates
lats <- c(90:-90, -90:90, 90)
longs <- c(rep(c(180, -180), each = 181), 180)

robin_outline <- 
  list(cbind(longs, lats)) %>%
  st_polygon() %>%
  st_sfc(crs = "+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs") %>% 
  st_sf() %>%
  st_transform(crs = "+proj=robin +lat_0=0 +lon_0=0 +x0=0 +y0=0")

# plot with line
ggplot(robin_outline) +
  geom_sf(fill = "#56B4E950", color = "black")

# plot without line
ggplot(robin_outline) +
  geom_sf(fill = "#56B4E950", color = NA)
#> Warning: Removed 1 rows containing missing values (geom_sf).

Created on 2019-09-22 by the reprex package (v0.3.0)

Activity

  1. yutannihilation commented on Sep 22, 2019

    @yutannihilation
    Member

    Opps..., I think your analysis is correct. Sorry for the regression. Then, we probably need to define a handle_na() that handle NAs differently depending on the type of geometry.

  2. clauswilke commented on Sep 22, 2019

    @clauswilke
    MemberAuthor

    It seems to me that the true, real, underlying issue is that grid is overly conservative with checking input and doesn't gracefully degrade with missing or NA input in many cases.

    @thomasp85 Any chance that we can get grid to be more tolerant to missing input, so we don't have to constantly code circles around grid's limitations?

    Just one of many such examples:

    library(grid)
    
    grid.points(numeric(0), numeric(0))
    #> Error in unit(x, default.units): 'x' and 'units' must have length > 0

    Created on 2019-09-22 by the reprex package (v0.3.0)

  3. thomasp85 commented on Sep 22, 2019

    @thomasp85
    Member

    I won’t rule that out but the call is ultimately Paul’s — I’ll talk with him about it

  4. yutannihilation commented on Sep 23, 2019

    @yutannihilation
    Member

    #3537 is an attempt to fix this. But, I think I don't figure out what to do when the data is of mixed types of geometries. Any ideas...?

    (edit: Sorry, I misunderstood about the process of when missing values are removed)

  5. added this to the ggplot2 3.3.0 milestone on Oct 7, 2019
  6. lock commented on May 5, 2020

    @lock

    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/

  7. locked and limited conversation to collaborators on May 5, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions