Based on the advice in this post I am trying to get the serif font (or 'family' of fonts) installed into R so that I can save ggplots as .eps files. Though the suggestion provided worked I would like to try to resolve the issue for future use.
Here's code to generate the issue.
library(bayesplot)
df <- data.frame(xVar = rnorm(1e4,0,1), yVar = rnorm(1e4,2,1), zVar = rnorm(1e4,4,1))
t <- bayesplot::mcmc_trace(df)
t
Now when I go to save the figure...
ggplot2::ggsave(filename = "tPlot.eps",
plot = t,
device = "eps",
dpi = 1200,
width = 15,
height = 10,
units = "cm")
...it throws the error
Error in grid.Call(C_stringMetric, as.graphicsAnnot(x$label)) :
family 'serif' not included in postscript() device
In the previous post the answerer suggested I download the extrafont
package.
I ran
View(fonttable())
But the serif font did not appear to be installed.
Then I tried
font_addpackage(pkg = "serif")
But I got the error
Error in font_addpackage(pkg = "serif") :
Unknown font package type: not type1 or ttf.
Does anyone know how to install the serif font so R can recognise/use it?
"serif"
is not recognized as a font type. But there are 458 serif fonts in packageextrafont
, tryfnt <- fonts();i <- grep("serif", fnt, ignore.case = TRUE);fnt[i]
to have a vector of their names. – Irrigate[1] "Microsoft Sans Serif" "MS Reference Sans Serif"
which I gather are not serif fonts. Times New Roman is a serif font though, and when I doView(fonttable())
Times New Roman is there, but I still get that error message. AlsoView(fonttable())
only returns 81 font names. I am very confused about the difference between loading, embedding, and installing fonts. How do I install the 458 fonts you mention so that R can recognise them? – Garzonfont_import()
? It's needed to install the fonts. After running it yourggsave
code is not giving me errors. – Irrigate