Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 341
unknown Avatar asked Apr 08 '26 00:04

unknown


1 Answers

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.

like image 96
jared_mamrot Avatar answered Apr 10 '26 17:04

jared_mamrot



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!