unknown
unknown

Reputation: 883

ggplot text rendering not working for some fonts

I have been trying to add a google font to my ggplots, but the text renders with lots of gaps in it. Does anyone know how to fix this?

Seems like it may be an operating system specific problem. I'm using: OS: MacOS Catalina 10.15.7 R version: 4.0.4

Here is an example with massive text to demonstrate the problem:

library(ggplot2)
library(sysfonts)
library(showtext)
font_add_google("Work Sans")
showtext_auto()
ggplot(mtcars, aes(wt, mpg)) +
  geom_point()+
  theme(text = element_text(family = "Work Sans", size =100),
        axis.text = element_blank())

enter image description here

Upvotes: 3

Views: 765

Answers (1)

jared_mamrot
jared_mamrot

Reputation: 26515

Looks like an issue with the variable font file. As a workaround, perhaps you could download the static version of the font from https://github.com/weiweihuanghuang/Work-Sans/tree/master/fonts/static/TTF and use that instead, e.g.

library(ggplot2)
#install.packages("sysfonts")
library(sysfonts)
#install.packages("showtext")
library(showtext)
font_add("Work Sans", regular = "~/Downloads/WorkSans-Regular.ttf")
showtext_auto()
ggplot(mtcars, aes(wt, mpg)) +
  geom_point()+
  theme(text = element_text(family = "Work Sans", size = 100),
        axis.text = element_blank())

example_1.png

Would also be good to open an issue on github and see if the package author can help.

Upvotes: 4

Related Questions