Recently all my ggplot2 code has stopped working on my MacOS Monterrey v12.6.3. For example, creating a very simple plot:
library(ggplot2)
x = 1:10
y = 1:10
df = data.frame(x, y)
ggplot(df, aes(x = x, y = y)) +
geom_point()
I get the following error message:
Error in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, :
polygon edge not found
In addition: There were 50 or more warnings (use warnings() to see the first 50)
And the following warnings:
> warnings()
Warning messages:
1: In grid.Call(C_stringMetric, as.graphicsAnnot(x$label)) :
no font could be found for family "Arial"
It seems like something is messing with the search for fonts, but I don't understand what has happened. Re-installations of ggplot2 have not resolved the problem.
This post appears to have the same problem: Error in grid.Call(L_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : Polygon edge not found
But I don't have the directories involved in the highest-voted solution, so the answer did not help me.
What is the cause of this issue? And how can I fix it?
EDIT
Additional information was requested in the comments:
> ggplot2::theme_get()$text
List of 11
$ family : chr ""
$ face : chr "plain"
$ colour : chr "black"
$ size : num 11
$ hjust : num 0.5
$ vjust : num 0.5
$ angle : num 0
$ lineheight : num 0.9
$ margin : 'margin' num [1:4] 0points 0points 0points 0points
..- attr(*, "unit")= int 8
$ debug : logi FALSE
$ inherit.blank: logi TRUE
- attr(*, "class")= chr [1:2] "element_text" "element"
> X11Fonts()
$serif
[1] "-*-times-%s-%s-*-*-%d-*-*-*-*-*-*-*"
$sans
[1] "-*-helvetica-%s-%s-*-*-%d-*-*-*-*-*-*-*"
$mono
[1] "-*-courier-%s-%s-*-*-%d-*-*-*-*-*-*-*"
$Times
[1] "-adobe-times-%s-%s-*-*-%d-*-*-*-*-*-*-*"
$Helvetica
[1] "-adobe-helvetica-%s-%s-*-*-%d-*-*-*-*-*-*-*"
$CyrTimes
[1] "-cronyx-times-%s-%s-*-*-%d-*-*-*-*-*-*-*"
$CyrHelvetica
[1] "-cronyx-helvetica-%s-%s-*-*-%d-*-*-*-*-*-*-*"
$Arial
[1] "-monotype-arial-%s-%s-*-*-%d-*-*-*-*-*-*-*"
$Mincho
[1] "-*-mincho-%s-%s-*-*-%d-*-*-*-*-*-*-*"
> systemfonts::font_info()
# A tibble: 1 × 24
path index family style italic bold monos…¹ weight width kerning color scala…² verti…³ n_gly…⁴ n_sizes n_cha…⁵ bbox
<chr> <int> <chr> <chr> <lgl> <lgl> <lgl> <ord> <ord> <lgl> <lgl> <lgl> <lgl> <int> <int> <int> <lis>
1 /Syste… 0 Helve… Regu… FALSE FALSE FALSE normal norm… FALSE FALSE TRUE FALSE 2252 0 10 <dbl>
# … with 7 more variables: max_ascend <dbl>, max_descend <dbl>, max_advance_width <dbl>, max_advance_height <dbl>,
# lineheight <dbl>, underline_pos <dbl>, underline_size <dbl>, and abbreviated variable names ¹monospace, ²scalable,
# ³vertical, ⁴n_glyphs, ⁵n_charmaps
# ℹ Use `colnames()` to see all variable names