Error in grid.Call(L_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : Polygon edge not found
Asked Answered
A

16

74

I just installed RStudio on Mac OS X, version 10.7.3. After executing the following commands

library(ggplot2)
qplot(mpg, wt, data=mtcars)

I get the following error:

Error in grid.Call(L_textBounds, as.graphicsAnnot(x$label), x$x, x$y,  : 
  Polygon edge not found
In addition: Warning messages:
1: In grid.Call(L_textBounds, as.graphicsAnnot(x$label), x$x, x$y,  :
  no font could be found for family "Arial"
2: In grid.Call(L_textBounds, as.graphicsAnnot(x$label), x$x, x$y,  :
  no font could be found for family "Arial"

How do I fix this?

Actinomycin answered 14/5, 2012 at 10:19 Comment(1)
In my case it was enough to restart RStudio.Specification
C
47

this happened to me and i discovered that the arial font file had been disabled. first check to see if Arial.ttf has been moved to the disabled fonts directory. from the terminal:

ls /Library/Fonts\ Disabled

if so, move it back to the active fonts directory.

sudo mv /Library/Fonts\ Disabled/Arial.ttf /Library/Fonts

log out, log in, then open the 'Font Book' application. in my case, arial was present before hand, but it was the Microsoft version stored in /Library/fonts/Microsoft/. Font Book may now show a yellow triangle next to the font name, indicating that multiple copies of the font exist. highlight the font name and chose the Resolve Duplicates command from the Edit menu. this should disable the Microsoft copy, which you can confirm by selecting one of the arial type faces (click the expand triangle next to the font name), right-click on the one labelled Off, and choose Reveal in Finder, which should open a window to Microsoft fonts directory.

Coze answered 13/6, 2012 at 22:5 Comment(8)
Thanks! Worked for me. Seems Microsoft Office is the culprit.Kal
@pistachionut. When I first encountered this bug your approach really helped, but despite having Arial.ttf enabled, this bug continues to appear when I use grid.arrange(). Strangely, this seems to occur at random - if I repeat the same call multiple times I get a plot every now and then, and run into the error message the rest of the time! This especially frustrating when generating complex plots for a GIF animation.Tyika
Amazing, thank you. Seems like it was Office for me, too - I opened an Excel file with macros from a colleague right before this error started.Tadzhik
@GChalancon I have the same problem. The error happens sometimes up to five times in a row and then it works again without an issue. I used a tryCatch function to catch the error and suggest to just try it again, but for sure, to get rid of the error message would be the best. Any solution?Hobbema
@GChalancon same here. I tried moving Arial.ttf file and it worked for one chart with the remaining chart still returning the error.Chkalov
This worked - I didn't have to do anything after the "log out, log in" step.Deth
Thanks for the explanation. From what should I log in and log out to make this workFoudroyant
This idea worked, but I also had to move the Arial italic (sudo mv /Library/Fonts\ Disabled/'Arial Italic.ttf' /Library/Fonts) and Arial bold italic (sudo mv /Library/Fonts\ Disabled/Arial Bold Italic.ttf /Library/Fonts) fonts.Alonsoalonzo
R
24

So I bumped into the same problem with a code that was working just a few weeks before, and no massive update of anything on the computer (except maybe the OS, now that I get to think about it...). The way I solved it is that I forced the graphic window to open first by calling

quartz()

before my graphs, and it did the trick. Still unsure about the font, I seem to have the Arial in place.

Resuscitator answered 18/7, 2015 at 20:12 Comment(3)
This nice approach seems to work but if working in RStudio the chart is then produced outside the RStudio chart preview window.Chkalov
This works very well for me. Seems to be a limitation of RstudioSerrano
Amazing. I've been having this issue for years. But this simple trick solved it! KudosChrissychrist
A
12

After a few trials, I think this "fix" could help. First try running this to ensure the fonts actually exist:

loadfonts(dev="win")

If they do, call the following to ensure the name you're calling is similar to that R knows:

windowsFonts()

Otherwise, try the following:

library(extrafont)
extrafont::font_import()

The above fixed problems for me. Hope someone in the future may be helped by the same.

Arbuthnot answered 6/1, 2019 at 6:29 Comment(1)
Thank you - loading the extrafont library worked for me in 2021 with R version 4.0.2 on Win10.Zischke
C
6

After coming across the same problem again and again and trying different solutions I have decided to source the Arial font externally and add it to the Font Book. Prior to this exercise I had a number of fonts that came with MS Office, like Arial Black, Arial Narrow and so no but no plain Arial font visible. I'm guessing that this can be explained by the odd font policy that MS applications on Mac are applying, which is discussed in a greater detail here. Nevertheless, it appears that adding font externally solved the problem.

All Fonts

Chkalov answered 13/2, 2016 at 17:25 Comment(0)
E
4

I added an extra parameter to my qqplot() function like this:

theme(text=element_text(family="Garamond", size=14))

and sure enough - got a chart. End result then is:

ggplot(train, aes(x = pclass, fill = factor(survived))) +
  geom_bar() +
  xlab("Pclass") +
  ylab("Total Count") +
  labs(fill = "Survived") +
  theme(text=element_text(family="Garamond", size=14))

I did open Font Book and on my system (Mac OSX 10.12.3) is shows Arial as being off. I do have Microsoft apps installed including MS Excel but I cannot at this point correlate the disabling of any font with the install of any MS app. HTH

Estimate answered 24/3, 2017 at 23:18 Comment(0)
L
4

As others have cited, this issue definitely seems to be related to a Microsoft Office upgrade (my company had just upgraded the software immediately before the issue surfaced).

After attempting to run a simple ggplot2 plot, I received the following Error and Warning:

Error in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y,  : 
  polygon edge not found
Warning messages:
1: In grid.Call(C_stringMetric, as.graphicsAnnot(x$label)) :
  no font could be found for family "Arial"

I resolved this issue by performing the following actions:

(1) Open Font Book

(2) Navigate to the Arial Font

(3) Right Click -> "Restore Font"

Then the plot rendered perfectly.

I hope this helps!

Luke answered 5/6, 2018 at 11:38 Comment(0)
W
4

I've faceted the same issue and it was enough reseting the plot area (dev.off()).

Weingarten answered 11/1, 2021 at 12:3 Comment(2)
That was my intuition too, worked beautifully! (not for the arial, but for the error) Error in grid.Call(L_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : Polygon edge not foundStowage
font stuff didn't help. This answer did the trick (after also forcing a full reboot of RStudio/R).Michikomichon
M
3

For mac operating system, i tried many options but in the end following worked. - open font book and remove disable (enable) arial fonts. - restart the computer.

Moor answered 29/5, 2018 at 4:53 Comment(1)
Similar to what you described here, but I have Right Clicked Arial and than Validate Font. Found a minor error (unspecified) but worked nonetheless!Billhead
K
2

I resolved by going to Font Book, going to File -> Restore Standard Fonts.

Keble answered 1/5, 2016 at 8:15 Comment(2)
I did so, but the problem persisted.Screwed
I did not help either initially, but solved the problem after logging out and in again.Crave
U
1

I ran into the same problem (interestingly, I received the error when calling the "spplot" function rather than any of the ggplot2 functions). Because I had recently installed MS Office for Mac, I tried disabling the MS duplicate Arial font as was previously suggested, but still received the error message repeatedly even after doing this. I ended up simply removing all MS Office duplicate fonts (Go-->Computer-->Macintosh HD--->Library-->Fonts and then move the Microsoft folder to the trash). I'm not sure what effect this will have on my MS applications, but it seems to have remedied my R issues, which is more important to me at this point anyway!

Unaneled answered 17/9, 2014 at 17:49 Comment(2)
Thanks for contributing your comment. I did the same and it worked, so far no effect on MS Office.Chkalov
Actually, it started to occur again. It appears that running a ggplot2 bar command with axis.text = element_text(size = 12) causes the error whereas axis.text = element_text(size = 11) runs with no problem.Chkalov
K
1

Working on MacOS, I got the same error message with the warnings mentioning instead of Arial the Roboto Condensed fonts. So I installed those, which removed the warnings, but not the error message.

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

Then I found at https://community.rstudio.com/t/still-fighting-with-grid-call-c-textbounds-as-graphicsannot-x-label-x-x-x-y-polygon-edge-not-found-error/65559 the tip to re-install X11 https://www.xquartz.org .

After that the error disappeared ... but it still did not plot when the code was in an R file. It does work, though, when I knit in RStudio from an R-markdown document.

Katabasis answered 12/7, 2020 at 15:53 Comment(0)
T
0

I just ran into the same problem after updating my OS and a fresh install of MS Office, which seems to be the culprit.

Since I couldn't get the terminal approach to work, I simply went straight to the Font Book and enabled the disabled fonts (Arial, Times New Roman, Verdana) manually. After restarting, everything seems to be working fine now.

This strikes me as the most naïve solution but it's also easiest to implement imho.

Thy answered 26/4, 2016 at 17:24 Comment(0)
B
0

I encountered a similar problem using the function:

ggarrange (ggpubr package)    

It was solved by manually deactivating and activating the package (by clicking on the package in "packages"). Maybe this also helps others :)

Bethesda answered 4/4, 2018 at 14:36 Comment(0)
I
0

Bizarre error. But for me, on mac, the solution was simple: simply update Xquartz.

Open spotlight search with cmd + space, search for Xquartz

Once, opened, go to about -> Check for updates -> Update.

Ingaborg answered 24/4, 2021 at 2:31 Comment(0)
C
-1

I understand that both R console jobs and Rstudio started failing out in their graphics plotting duties, and that now when you run trivial plot request, you receive failure error, and no plot.

Have you reset the sessions ? (Ctrl+Shft+F10) Sometimes sessions can get corrupted after all.

Alternatively, if you would like something else to try, before that route, it might be worth halting the graphics device. dev.off() and trying that elementary plot again.

Of course, if your issue is persistent, across to new sessions, then this answer does not apply.

Cranage answered 14/5, 2012 at 10:19 Comment(0)
N
-1

First, as a quick test as to whether this error is the result of a font-related issue, you can try plotting without any text (see code below).

    # test whether error is being generated by a font issue

    library(ggplot2)

    # try removing all fonts to test if issue is font-related
    # by using theme(text = element_blank())
    mtcars %>% 
      ggplot() + 
        aes(x = wt, y = mpg) + 
        geom_point() + 
        theme(text = element_blank())

Second, if the text-free version of your plot works and you're on a Mac, try reinstalling ggplot2. Recently, after trying all the other approaches, I found running install.packages("ggplot2") and restarting RStudio was the only thing that solved the problem.

Third, more than a year ago fixing Arial (as suggested above) was helpful:

  1. Hit Command-Space and type Font Book to open that app
  2. Right-click on Arial and select Disabled Arial
  3. Right-click on Arial and select Enable Arial
  4. When prompted to Resolve Duplicates select Resolve Automatically
  5. Quit out of RStudio and re-open RStudio (I didn't need to reboot my computer)
  6. Re-run plotting code as test (in my case it worked fine without the error)
Narghile answered 27/5, 2021 at 23:2 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.