Skip to content

geom_textsf randomly throws erros when specification of font family is missing (OpenSUSE Leap 15.5, R 4.3.2) #110

Description

@klausbraun

Allan,

I was really happy when I discovered your library, in my case especially when I saw the examples with geom_textsf and geom_labelsf (https://allancameron.github.io/geomtextpath/). When I try to execute the code:

library(geomtextpath)
library(sf)

df <- data.frame(x = c(-4.2518, -3.1883), 
                 y = c(55.8642, 55.9533),
                 label = c("Glasgow", "Edinburgh"))

p <- ggplot(data = df) +
  geom_textsf(data = waterways,
              aes(label = name), text_smoothing = 65, linecolour = "#8888B3", 
              color = "gray30", vjust = -0.8, fill = "#E6F0B3", 
              alpha = 0.8, fontface = 3, size = 3) + 
  geom_point(aes(x, y), data = df, color = "gray50", size = 3) + 
  geom_textpath(aes(x, y, label = label), color = "gray50",
                hjust = c(-0.2, 1.2)) +
  theme(panel.grid = element_line()) + 
  lims(x = c(-4.7, -3), y = c(55.62, 56.25))

and print p I get the following weird behavior:

> p
Error in `geom_textsf()`:
! Problem while converting geom to grob.
ℹ Error occurred in the 1st layer.
Caused by error in `get_glyph_info_c()`:
! 'Rf_translateCharUTF8' must be called on a CHARSXP, but got 'bytecode'
Run `rlang::last_trace()` to see where the error occurred.
> p
Error in `geom_textsf()`:
! Problem while converting geom to grob.
ℹ Error occurred in the 1st layer.
Caused by error:
! Failed to load `` from font (繀) with freetype error -1
Run `rlang::last_trace()` to see where the error occurred.
> p

where the the plot p is printed after two failed tries. The backtrace gives:

 21. │                     └─geomtextpath (local) draw_panel(...)
 22. │                       └─geomtextpath:::sf_textgrob(...)
 23. │                         ├─grid::addGrob(...)
 24. │                         ├─sf::st_as_grob(...)
 25. │                         └─geomtextpath:::st_as_grob.sfc_labelled(...)
 26. │                           └─geomtextpath::textpathGrob(...)
 27. │                             └─geomtextpath:::measure_label(...)
 28. │                               └─geomtextpath (local) measure(...)
 29. │                                 └─geomtextpath:::translate_glyph(txt$index, txt$substring, gp)
 30. │                                   └─base::lapply(gp$fontfamily %nz% "fallback", glyph_index)
 31. │                                     └─geomtextpath (local) FUN(X[[i]], ...)
 32. │                                       └─systemfonts::glyph_info(idx, family = name)
 33. │                                         └─systemfonts:::get_glyph_info_c(...)

Also the example sometimes fails completely and R is aborted.

The solution I found after a while is to explicitly tell geom_textsf and geom_textpath the font family which should be used, i.e. something like:

   ...
  geom_textsf(data = waterways,
              aes(label = name), text_smoothing = 65, linecolour = "#8888B3", 
              color = "gray30", vjust = -0.8, fill = "#E6F0B3", family = "Times New Roman",
              alpha = 0.8, fontface = 3, size = 3) + 
   ...

I'm working on OpenSUSE Leap 15.5 which actual R 4.3.2 and packages sf_1.0-15, geomtextpath_0.1.1, and ggplot2_3.4.4.

Using the workaround described above I am able to use this great package, but I think it would be good to either solve the problem (when it is a problem of geomtextpath), or to give some hints according to the workaround - unless I am the only one facing this behavior.

Best

Klaus

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions