Skip to content

geom_sf(): "polygon edge not found" intermittent error #2252

@johngoldin

Description

@johngoldin

I am using geom_sf to do some county maps based on tigris data. I successfully followed some examples, but when I try to do my local county (New Haven, CT), I got the following error while doing geom_sf():

Error in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, :
polygon edge not found

I spent some time to create a reproducible error and even learned to use the reprex package. But I didn't actually post the issue. Then I opened my lap top this morning and ran the reprex example again. No error. I couldn't think of any reason why it started working, but it worked so I went on about my business. After several hours of work I hit the same error again, under somewhat different circumstances. Given the earlier inconsistency, I tried running the same call multiple times and did not get the error when the same call was repeated.

I think there is a problem, but I have only a nebulous idea of what the problem is. So I will put my non-reproduced reproducible error code below and maybe I won't be the only person who gets an intermittent "polygon edge not found" error. I realize this is not a terribly helpful issue report.

First, here is a copy of my console showing several variations of a geom_sf() call. I was varying the size parameter because I thought that triggered the error in this case. But if you look closely you can see that I make the identical call to geom_sf() and get an error in one instance and no error in another )with the same parameters (size = 0.1).

ggplot() +

  • geom_sf(data = p2) +
  • geom_sf(data = newhaven_necta, fill = NA, color = "red")

ggplot() +

  • geom_sf(data = p2, size = 1) +
  • geom_sf(data = newhaven_necta, fill = NA, color = "red")
    Warning message:
    In getNamespace("grDevices") : reached elapsed time limit

ggplot() +

  • geom_sf(data = p2, size = 0.1) +
  • geom_sf(data = newhaven_necta, fill = NA, color = "red")
    Error in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, :
    polygon edge not found

ggplot() +

  • geom_sf(data = p2, size = 0.3) +
  • geom_sf(data = newhaven_necta, fill = NA, color = "red")

ggplot() +

  • geom_sf(data = p2, size = 0.1) +
  • geom_sf(data = newhaven_necta, fill = NA, color = "red")

OK, next is the description what I thought was going to be a reproducible error:

I am using the tracts function of the tigris package to get shapefiles from the census. I thought the key factor in whether geom_sf gave me an error was whether or not the tracts functions specified cb = FALSE.

library(tigris)
#> To enable 
#> caching of data, set `options(tigris_use_cache = TRUE)` in your R script or .Rprofile.
#> 
#> Attaching package: 'tigris'
#> The following object is masked from 'package:graphics':
#> 
#>     plot
library(sf)
#> Linking to GEOS 3.6.1, GDAL 2.1.3, proj.4 4.9.3
library(tidyverse)
#> Loading tidyverse: ggplot2
#> Loading tidyverse: tibble
#> Loading tidyverse: tidyr
#> Loading tidyverse: readr
#> Loading tidyverse: purrr
#> Loading tidyverse: dplyr
#> Conflicts with tidy packages ----------------------------------------------
#> filter(): dplyr, stats
#> lag():    dplyr, stats

options(tigris_class = "sf")

# this interior Connecticut county works OK:
hartford_tigris <- tracts("CT", county = "Hartford", cb = TRUE)
#> 
  
ggplot(hartford_tigris) + geom_sf(data = hartford_tigris)

# New Haven works OK if I specifiy cb = FALSE
nh_tigris <- tracts("CT", county = "New Haven", cb = FALSE)
#> 
  
ggplot(nh_tigris) + geom_sf()

# New Haven fails if cb = TRUE.
# Error message I get is:
# Error in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y,  : 
#                      polygon edge not found

nh_tigris_cb <- tracts("CT", county = "New Haven", cb = TRUE)
ggplot(nh_tigris_cb) + geom_sf()

# From the successful example when cb = FALSE, one can see that New Haven county shows with
# a boundary far out into Long Sound. I'm guessing this is related to the polygon edge
# that is causing problems. I tried this for some counties in Rhode Island.
# Washington county fails with "polygon edge not found" when cb = TRUE.
# Newport county does not fail.

# One can examine some other coastal counties. Some have this problem and some don't.
ri_washington_cb <- tracts("RI", county = "Washington", cb = TRUE)
#> 
  
ri_newport_cb <- tracts("RI", county = "Newport", cb = TRUE)
ri_newport <- tracts("RI", county = "Newport")

ggplot(ri_newport_cb) + geom_sf()

ggplot(ri_newport) + geom_sf()

ggplot(ri_washington_cb) + geom_sf()

ggplot(ri_washington) + geom_sf()

Session info
devtools::session_info()
#> Session info -------------------------------------------------------------
#>  setting  value                       
#>  version  R version 3.4.1 (2017-06-30)
#>  system   x86_64, darwin15.6.0        
#>  ui       X11                         
#>  language (EN)                        
#>  collate  en_US.UTF-8                 
#>  tz       America/New_York            
#>  date     2017-08-26
#> Packages -----------------------------------------------------------------
#>  package    * version    date       source                            
#>  assertthat   0.2.0      2017-04-11 CRAN (R 3.4.0)                    
#>  backports    1.1.0      2017-05-22 CRAN (R 3.4.0)                    
#>  base       * 3.4.1      2017-07-07 local                             
#>  bindr        0.1        2016-11-13 CRAN (R 3.4.0)                    
#>  bindrcpp     0.2        2017-06-17 CRAN (R 3.4.0)                    
#>  bitops       1.0-6      2013-08-17 CRAN (R 3.4.0)                    
#>  broom        0.4.2      2017-02-13 CRAN (R 3.4.0)                    
#>  cellranger   1.1.0      2016-07-27 CRAN (R 3.4.0)                    
#>  colorspace   1.3-2      2016-12-14 CRAN (R 3.4.0)                    
#>  compiler     3.4.1      2017-07-07 local                             
#>  curl         2.8.1      2017-07-21 CRAN (R 3.4.1)                    
#>  datasets   * 3.4.1      2017-07-07 local                             
#>  DBI          0.7        2017-06-18 CRAN (R 3.4.0)                    
#>  devtools     1.13.3     2017-08-02 CRAN (R 3.4.1)                    
#>  digest       0.6.12     2017-01-27 CRAN (R 3.4.0)                    
#>  dplyr      * 0.7.2      2017-07-20 CRAN (R 3.4.1)                    
#>  evaluate     0.10.1     2017-06-24 CRAN (R 3.4.1)                    
#>  forcats      0.2.0      2017-01-23 CRAN (R 3.4.0)                    
#>  foreign      0.8-69     2017-06-22 CRAN (R 3.4.1)                    
#>  ggplot2    * 2.2.1.9000 2017-08-24 Github (tidyverse/ggplot2@41f154f)
#>  glue         1.1.1      2017-06-21 CRAN (R 3.4.1)                    
#>  graphics   * 3.4.1      2017-07-07 local                             
#>  grDevices  * 3.4.1      2017-07-07 local                             
#>  grid         3.4.1      2017-07-07 local                             
#>  gtable       0.2.0      2016-02-26 CRAN (R 3.4.0)                    
#>  haven        1.1.0      2017-07-09 CRAN (R 3.4.1)                    
#>  hms          0.3        2016-11-22 CRAN (R 3.4.0)                    
#>  htmltools    0.3.6      2017-04-28 CRAN (R 3.4.0)                    
#>  httr         1.3.1      2017-08-20 cran (@1.3.1)                     
#>  jsonlite     1.5        2017-06-01 CRAN (R 3.4.0)                    
#>  knitr        1.17       2017-08-10 CRAN (R 3.4.1)                    
#>  lattice      0.20-35    2017-03-25 CRAN (R 3.4.1)                    
#>  lazyeval     0.2.0      2016-06-12 CRAN (R 3.4.0)                    
#>  lubridate    1.6.0      2016-09-13 CRAN (R 3.4.0)                    
#>  magrittr     1.5        2014-11-22 CRAN (R 3.4.0)                    
#>  maptools     0.9-2      2017-03-25 CRAN (R 3.4.0)                    
#>  memoise      1.1.0      2017-04-21 CRAN (R 3.4.0)                    
#>  methods    * 3.4.1      2017-07-07 local                             
#>  mnormt       1.5-5      2016-10-15 CRAN (R 3.4.0)                    
#>  modelr       0.1.1      2017-07-24 CRAN (R 3.4.1)                    
#>  munsell      0.4.3      2016-02-13 CRAN (R 3.4.0)                    
#>  nlme         3.1-131    2017-02-06 CRAN (R 3.4.1)                    
#>  parallel     3.4.1      2017-07-07 local                             
#>  pkgconfig    2.0.1      2017-03-21 CRAN (R 3.4.0)                    
#>  plyr         1.8.4      2016-06-08 CRAN (R 3.4.0)                    
#>  psych        1.7.5      2017-05-03 CRAN (R 3.4.1)                    
#>  purrr      * 0.2.3      2017-08-02 CRAN (R 3.4.1)                    
#>  R6           2.2.2      2017-06-17 CRAN (R 3.4.0)                    
#>  rappdirs     0.3.1      2016-03-28 CRAN (R 3.4.0)                    
#>  Rcpp         0.12.12    2017-07-15 CRAN (R 3.4.1)                    
#>  RCurl        1.95-4.8   2016-03-01 CRAN (R 3.4.0)                    
#>  readr      * 1.1.1      2017-05-16 CRAN (R 3.4.0)                    
#>  readxl       1.0.0      2017-04-18 CRAN (R 3.4.0)                    
#>  reshape2     1.4.2      2016-10-22 CRAN (R 3.4.0)                    
#>  rgdal        1.2-8      2017-07-01 CRAN (R 3.4.1)                    
#>  rgeos        0.3-23     2017-04-06 CRAN (R 3.4.0)                    
#>  rlang        0.1.2      2017-08-09 CRAN (R 3.4.1)                    
#>  rmarkdown    1.6        2017-06-15 CRAN (R 3.4.0)                    
#>  rprojroot    1.2        2017-01-16 CRAN (R 3.4.0)                    
#>  rvest        0.3.2      2016-06-17 CRAN (R 3.4.0)                    
#>  scales       0.5.0      2017-08-24 Github (hadley/scales@21bf4c0)    
#>  sf         * 0.5-3      2017-07-30 CRAN (R 3.4.1)                    
#>  sp           1.2-5      2017-06-29 CRAN (R 3.4.1)                    
#>  stats      * 3.4.1      2017-07-07 local                             
#>  stringi      1.1.5      2017-04-07 CRAN (R 3.4.0)                    
#>  stringr      1.2.0      2017-02-18 CRAN (R 3.4.0)                    
#>  tibble     * 1.3.3      2017-05-28 CRAN (R 3.4.0)                    
#>  tidyr      * 0.7.0      2017-08-16 CRAN (R 3.4.1)                    
#>  tidyverse  * 1.1.1      2017-01-27 CRAN (R 3.4.0)                    
#>  tigris     * 0.5.9      2017-08-25 Github (walkerke/tigris@4d6a38a)  
#>  tools        3.4.1      2017-07-07 local                             
#>  udunits2     0.13       2016-11-17 CRAN (R 3.4.0)                    
#>  units        0.4-5      2017-06-15 CRAN (R 3.4.0)                    
#>  utils      * 3.4.1      2017-07-07 local                             
#>  uuid         0.1-2      2015-07-28 CRAN (R 3.4.0)                    
#>  withr        2.0.0      2017-08-19 Github (jimhester/withr@0c4a86d)  
#>  XML          3.98-1.9   2017-06-19 CRAN (R 3.4.1)                    
#>  xml2         1.1.1      2017-01-24 CRAN (R 3.4.0)                    
#>  yaml         2.1.14     2016-11-12 CRAN (R 3.4.0)

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugan unexpected problem or unintended behaviorlayers 📈

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions