-
Notifications
You must be signed in to change notification settings - Fork 2k
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
geom_sf(): "polygon edge not found" intermittent error #2252
Comments
I have even less idea what triggers the "polygon edge not found" error. In the project that I am working on with tigris maps I have made the same call to geom_sf multiple times with no problem and then suddenly have it switch to throwing this error and no longer able to run. As far as I can tell the calling parameters are identical. |
Sigh, one more problem with my attempt to create a repeatable example: to run the tigris and tidycensus calls you have to have a Census API key. |
This appears to be some grid bug. Unfortunately I haven't been able to reliably reproduce it either. |
hi @hadley and @johngoldin - I came across this error (and subsequently this issue) while getting ready for a lecture on I have been able to reproduce the error with a set of data that I use for teaching. The data are packaged up and available on GitHub:
Here is a reprex that I have been using to trigger the error:
The error does not happen every time I re-create the plot. This afternoon, I was able to trigger the error every other time or every third time I created the plot:
I hope this is helpful for you @hadley in terms of getting to the bottom of what is happening! Thanks for all of your hard work on this package (and others) - they are a joy to use and to teach with. |
I ran into the same error on this tutorial for making a map in ggplot: https://github.com/grssnbchr/thematic-maps-ggplot2 Since all data and code is on Github, perhaps that is easily replicable. Specifically, the error appears in this code chunk:
The addition of the |
@tbrambor does it happen every time? If so, can you please make a small reprex that I can run by copying and pasting? |
@hadley . The following reprex shows the error. Oddly, it appears to be related to using a font that is not installed on my system in defining the theme of the plot. If the title and labels of the plot axes are surpressed, the error disappears.
|
@tbrambor does this error also occur when you do not use the |
No. If the (incorrect) theme mapping is excluded, the plot works fine. It appears the plotting function tries to use the non-installed font which results in the error. |
@tbrambor I suspect that's a different problem which generates the same error |
@hadley. Quite possible. I was just looking for a solution and came across this filed issue here. Feel free to exclude -- I will just adjust the theme to rely on installed fonts and the error is resolved for me. Thank you. |
@hadley I have a little more info on how to replicate this error consistently. I am able to trigger the > library(colorblindr)
> library(ggplot2)
> library(stlData)
> map <- ggplot() +
+ geom_sf(data = stlBoundary, fill = "#5d5d5d", color = "#5d5d5d") +
+ geom_sf(data = stlHistoric, fill = "#d48a72", color = "#d48a72") +
+ geom_sf(data = stlHydro, fill = "#72bcd4", color = "#72bcd4")
> cvd_grid(map)
Error in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, :
polygon edge not found What is a little nuts is that it works fine in code chunks in library(colorblindr)
#> Loading required package: colorspace
#> Loading required package: ggplot2
library(ggplot2)
library(stlData)
map <- ggplot() +
geom_sf(data = stlBoundary, fill = "#5d5d5d", color = "#5d5d5d") +
geom_sf(data = stlHistoric, fill = "#d48a72", color = "#d48a72") +
geom_sf(data = stlHydro, fill = "#72bcd4", color = "#72bcd4")
cvd_grid(map) Created on 2018-02-18 by the reprex package (v0.2.0). |
Due to some updates I'm working on to the package I've been using for these reprexes, anyone who wants to investigate this error should install a specific release: devtools::install_github("chris-prener/stlData", ref = "f51fe10") |
Hello, I have the same error message: I am using the following code:
After some runs the error appears. I am not able to reproduce the error each time I run the code but if I run the same code inside an Rmd file then everythink works fine and I get my plots without any error. I hope this can help. Cheers, Mathieu |
Any fix? |
Not yet. When there is a fix, the issue will be automatically closed. 👍 |
I am getting this error in ubuntu 16.04. Error in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : Is there a solution? |
I'm also fighting with this error and would love to see it fixed. Here's my reproducible example
|
This appears to be a low-level grid problem. I don't think there's much hope of getting it fixed unless someone can generate a minimal reprex using only grid calls. |
Quick question - has anyone seen this problem outside of RStudio? |
I just tried @chris-prener's reprex in both RStudio and ESS and got the error in RStudio but not ESS. |
I have seen it many times running R in the terminal.
Op do 3 mei 2018 00:23 schreef Hadley Wickham <[email protected]>:
… Quick question - has anyone seen this problem outside of RStudio?
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#2252 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AA9kTPJwDK3_tDJDs0T25RzDZ9Z5f7Xzks5tujHkgaJpZM4PDpFw>
.
|
It's hard for me to provide a reprex because some external factor/program seems to induce the onset of "Polygon edge not found" errors, after which the only remedy I've found is to reboot my machine. Restarting R won't help. I'm on a 2015 MacBook Pro running High Sierra. |
This comment has been minimized.
This comment has been minimized.
Possibly related: #2514 |
I'm not sure if this solves anyone's problems, but I've noticed that if I ever have a chr variable with spaces in the string then it will generate this error--even if I'm not calling that variable at all in what I'm doing. As long as it's present in the data object I get the error, when I drop those variables it goes away. |
I seem to have stumbled across a minimal ggplot2 example to generate this problem. The following code causes this error for me every time: library(ggplot2)
ggplot(data.frame(), aes(1, 1)) + theme(text = element_text(family = 0))
#> Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, :
#> no font could be found for family "0"
#> Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, :
#> no font could be found for family "0"
#> Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, :
#> no font could be found for family "0"
#> Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, :
#> no font could be found for family "0"
#> Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, :
#> no font could be found for family "0"
#> Error in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : polygon edge not found Traceback:
The error arises in library(grid)
x <- textGrob("abcd", gp = gpar(fontfamily = 0))
widthDetails(x)
#> [1] 0.361409505208333inches |
Just came across this issue from RStudio IDE. The error is sporadic, sometimes it works, at other times it throws error. To work around this issue add "theme_void()" before geom_sf.
I am suspecting a "graphic Device issue on RStudio IDE" |
In theory this should be fixed in the latest release of RStudio. What version are you using? |
Version 1.0.136 |
I have problem: R v. 3.6.1 |
I see this is closed, but I'm still having this problem -- "polygon edge not found" error is intermittent. Reprex is hard, but did any of the reprexes above get tested and resolved?
RStudio, Mac.... |
Hi. This problem was solved for me after I removed the values that were infinite. |
@tbrambor I have encountered this exact issue and couldn't figure out why for several days. Your comment was spot on - it helped me solve the issue! Thanks!! The solution that worked for me: I was using a font that is specific to my company. I replaced that font with a regular system font (e.g. Arial) throughout server.R & UI.R, and the bug was fixed. No idea why that company font is not available on my company laptop, but that solved my issue. Hope that helps.
|
For what it's worth, I saw this issue again yesterday. The environment is Mac OS X Catalina. Appeared suddenly, then was reproducible 100% (the only way to see anything plotted was to use theme_void()), and there were the additional warnings about fonts. In retrospect, this happened in the middle of a session after I uninstalled a bunch of unneeded software from the Mac. I googled for the error, tried workarounds, upgraded R and RStudio to latest stable, nothing helped. I got rid of it by rebooting the computer. Looks like it may be system related, but who knows how. |
Had this error. Found the Google Font that missing and installed it on my Mac. Then restarted the R session and the code works! |
I saw the |
The The vignette where the error occurs is here.
Many thanks, Session info.
|
Since this discussion keeps growing though it's not a ggplot2 issue, let me try to move this forward and propose a way somebody could dig deeper and figure out what's going on. The error is triggered by grid, here: The code tries to find the edge on a convex polygon: I suspect there are some numerical edge cases that cause the algorithm to fail. If we can figure out what those edge cases are we can try to improve the algorithm or try to make sure it isn't fed bad data. The way to debug this further would be to attach a break point or otherwise log the input data to the function In any case, all of this discussion and further digging should happen on an issue tracker for grid. Not sure if one exists. |
thanks for the context, Claus! I can also not reproduce @bschilder 's problem on my computer. I would be happy to dive into it, if only I had a Mac! |
The `polygon edge not found` error that keeps popping up seems to be related to `macOS` only. See tidyverse/ggplot2#2252
I had a vague recollection that @pmur002 fixed this in R? But it seems like maybe it is cropping up again, so something may have changed to re-trigger it. |
Code coverage generates an error when knitting the vignette: polygon edge not found. Only on MacOS, see tidyverse/ggplot2#2252
I don't want to create noise on this thread, but seeing that there is no other place for this … I have an RStudio session open with which I can more or less reliably trigger that error. It happens when I have the session open for some time, and something (perhaps switching displays or having had the screensaver enabled) triggers that error whenever I try to plot anything. The error only appears after some time, not immediately after the session is started. Re-starting the R session always fixes it. So even a simple call to:
raises the error:
So there you have your set of input data, at least. It is not related to the actual data, and it seems to be an issue with RStudio or R itself. This is Rstudio 2021.09.2 Build 382 under macOS 12.1 (Apple Silicon) with R 4.1.2 from Homebrew. |
See this for more details: - tidyverse/ggplot2#2252 (comment) - lcolladotor/biocthis#27
… here: tidyverse/ggplot2#2252) by not building vignettes on macos
I finally got this to replicate for me (using @clauswilke simple example) and I think I may have fixed it (r-devel r82550). Would be great if anyone could confirm the fix. |
r-devel r82861has some more improvements to the code around this topic. |
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).
Warning message:
In getNamespace("grDevices") : reached elapsed time limit
Error in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, :
polygon edge not found
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.
Session info
The text was updated successfully, but these errors were encountered: