Skip to content

regression in geom_sf (+ geom_bin2d) after latest update #4527

Closed
@Mashin6

Description

@Mashin6

I am not sure if this should be posted here or in r-spatial/sf. Recently I updated several packages in my "R version 4.0.4 (2021-02-15) MacOS 11.4 " and noticed several weird behaviors when plotting 2d density over spatial map of countries.

  1. Performance issue: Plotting takes unusually long. e.g. before ~10s , now >1min
  2. I get warning message: In st_cast.GEOMETRYCOLLECTION(X[[i]], ...) : only first part of geometrycollection is retained
  3. 2d density square bins are now plotted with outlines (overlaps). geom_bin2d works fine alone but gives this issue in combination with geom_sf
``` r
library(tidyverse)
library(ggspatial)
library(sf)
#> Linking to GEOS 3.8.1, GDAL 3.2.1, PROJ 7.2.1
library(rnaturalearth)
library(rnaturalearthdata)
library(rgeos)
#> Loading required package: sp
#> rgeos version: 0.5-5, (SVN revision 640)
#>  GEOS runtime version: 3.8.1-CAPI-1.13.3 
#>  Linking to sp version: 1.4-2 
#>  Polygon checking: TRUE
    

world <- ne_countries(scale = "medium", returnclass = "sf")
csvData <- data.frame(lat = rnorm(10^5, 41.5, 0.1),
                      lon = rnorm(10^5, -72.75, 0.1))

# OK plot
world %>% 
    ggplot() +
        geom_bin2d(data = csvData, 
                   aes(x = lon, 
                       y = lat, 
                       fill = after_stat(log10(count))), 
                   binwidth = 0.005)

# Bins with borders
world %>% 
    ggplot() +
        geom_bin2d(data = csvData, 
                   aes(x = lon, 
                       y = lat, 
                       fill = after_stat(log10(count))), 
                   binwidth = 0.005) +
        geom_sf(color = "grey70", size = 0.1, fill = "transparent") +
        coord_sf(expand = FALSE, xlim = c(-73.7, -71.8), ylim = c(41.0, 42.0))
#> Warning in st_cast.GEOMETRYCOLLECTION(X[[i]], ...): only first part of
#> geometrycollection is retained

Created on 2021-06-22 by the reprex package (v2.0.0)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions