Reputation: 1529
I am having problems changing font in R. For some reasons, it seems that R can not find the font I am asking (any of them, actually). I double-checked that the fonts are indeed installed on my system (Linux Mint 20.3). It looks like to be related to x11()
, but it appears to be supported on my machine.
Any ideas appreciated.
capabilities()
#> jpeg png tiff tcltk X11 aqua
#> TRUE TRUE TRUE FALSE TRUE FALSE
#> http/ftp sockets libxml fifo cledit iconv
#> TRUE TRUE TRUE TRUE FALSE TRUE
#> NLS Rprof profmem cairo ICU long.double
#> TRUE TRUE FALSE TRUE TRUE TRUE
#> libcurl
#> TRUE
library(ggplot2)
ggplot() +
labs(x = quote(delta)) +
theme(text = element_text(family = "Roboto"))
#> Warning in grid.Call(C_stringMetric, as.graphicsAnnot(x$label)): font family not
#> found in X11 font database
#> Warning in grid.Call(C_stringMetric, as.graphicsAnnot(x$label)): font family not
#> found in X11 font database
#> Warning in grid.Call(C_stringMetric, as.graphicsAnnot(x$label)): font family not
#> found in X11 font database
#> Warning in grid.Call(C_stringMetric, as.graphicsAnnot(x$label)): font family not
#> found in X11 font database
#> Warning in grid.Call(C_stringMetric, as.graphicsAnnot(x$label)): font family not
#> found in X11 font database
#> Warning in grid.Call(C_stringMetric, as.graphicsAnnot(x$label)): font family not
#> found in X11 font database
#> Warning in grid.Call(C_stringMetric, as.graphicsAnnot(x$label)): font family not
#> found in X11 font database
#> Warning in grid.Call(C_stringMetric, as.graphicsAnnot(x$label)): font family not
#> found in X11 font database
#> Warning in grid.Call(C_stringMetric, as.graphicsAnnot(x$label)): font family not
#> found in X11 font database
#> Warning in grid.Call(C_stringMetric, as.graphicsAnnot(x$label)): font family not
#> found in X11 font database
#> Warning in grid.Call(C_stringMetric, as.graphicsAnnot(x$label)): font family not
#> found in X11 font database
#> Warning in grid.Call(C_stringMetric, as.graphicsAnnot(x$label)): font family not
#> found in X11 font database
#> Warning in grid.Call(C_stringMetric, as.graphicsAnnot(x$label)): font family not
#> found in X11 font database
#> Warning in grid.Call(C_stringMetric, as.graphicsAnnot(x$label)): font family not
#> found in X11 font database
#> Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
#> family not found in X11 font database
#> Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
#> family not found in X11 font database
#> Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
#> family not found in X11 font database
#> Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
#> family not found in X11 font database
#> Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
#> family not found in X11 font database
#> Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
#> family not found in X11 font database
#> Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
#> family not found in X11 font database
#> Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
#> family not found in X11 font database
#> Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
#> family not found in X11 font database
#> Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
#> family not found in X11 font database
#> Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
#> family not found in X11 font database
#> Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
#> family not found in X11 font database
#> Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
#> family not found in X11 font database
#> Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
#> family not found in X11 font database
#> Warning in grid.Call.graphics(C_text, as.graphicsAnnot(x$label), x$x, x$y, :
#> font family not found in X11 font database
#> Warning in grid.Call.graphics(C_text, as.graphicsAnnot(x$label), x$x, x$y, :
#> font family not found in X11 font database
#> Warning in grid.Call.graphics(C_text, as.graphicsAnnot(x$label), x$x, x$y, :
#> font family not found in X11 font database
#> Warning in grid.Call.graphics(C_text, as.graphicsAnnot(x$label), x$x, x$y, :
#> font family not found in X11 font database
#> Warning in grid.Call.graphics(C_text, as.graphicsAnnot(x$label), x$x, x$y, :
#> font family not found in X11 font database
Created on 2022-01-18 by the reprex package (v2.0.1)
Upvotes: 1
Views: 1598
Reputation: 263332
Here's what I did after following my own (slightly misspelled) advice:
?X11Fonts
The followed the example and executed its code:
if(capabilities()[["X11"]]) withAutoprint({
X11Fonts()
X11Fonts("mono")
utopia <- X11Font("-*-utopia-*-*-*-*-*-*-*-*-*-*-*-*")
X11Fonts(utopia = utopia)
})
No error and "utopia" was there in the listed fonts the next time I ran X11Fonts()
, so I tried with "Roboto" (in an Ubuntu 18.04 box).
Roboto <- X11Font("-*-roboto-*-*-*-*-*-*-*-*-*-*-*-*")
X11Fonts(Roboto = Roboto)
#-------------------
> X11Fonts()
$serif
[1] "-*-times-%s-%s-*-*-%d-*-*-*-*-*-*-*"
$sans
[1] "-*-helvetica-%s-%s-*-*-%d-*-*-*-*-*-*-*"
#---snipped
$Roboto
[1] "-*-roboto-%s-%s-*-*-%d-*-*-*-*-*-*-*"
Looks like Roboto is now mine. (I have no idea what it looks like.)
After executing:
library(ggplot2)
ggplot() +
labs(x = quote(delta)) +
theme(text = element_text(family = "Roboto"))
.... I now see an unmarkerked plot area with a Greek lowercase delta
as the label in an x11
window, which will disappear after I execute dev.off()
.
Upvotes: 1