You'll need to make sure it's installed on your computer (note that GhostScript is not an R package). Ggsave("ggplot_garamond.pdf", p, width=3.5, height=3.5)Įxtrafont uses GhostScript, a free PostScript interpreter, to embed the fonts. Theme(text=element_text(family="Garamond", size=14)) Xlab("Weight (x1000 lb)") + ylab("Miles per Gallon") + P <- ggplot(mtcars, aes(x=wt, y=mpg)) + geom_point() + Here's an example using base graphics: pdf("plot_garamond.pdf", family="Garamond", width=4, height=4.5)Īgain, you may see some warnings, but they shouldn't cause any problems. pdf, use:Īfter the fonts are registered with R's PDF device, you can create figures with them. This must be run once in each R session where you want to use the fonts: library(extrafont) Once you've imported the fonts from your system to the extrafont database, they must be registered with R as being available for the PDF output device. # This will show more detailed information about fonts After the fonts are imported, you can view the available fonts by running fonts() or fonttable(): fonts() You may see some warnings, but you should be able to ignore them. The first step is to install extrafont, and then import the fonts from your system into the extrafont database: Installation install.packages("extrafont") It will substitute some other font in the place of Garamond: Here's an example of what a PDF using Garamond might look like when it's not embedded, and printed or viewed on a device that lacks the font. Next, you must embed the font into the PDF file to make it render properly on another computer or printer that doesn't already have the font. When using fonts in PDF files, there are two challenges: First you must tell R that the font is available to use. With it, you can create beautiful, professional-looking results like this: Using other fonts that are installed on your computer can seem an impossible task, especially if you want to save the output to PDF.įortunately, the extrafont package makes this process much easier. When it comes to making figures in R, you can use any font you like, as long as it's Helvetica, Times, or Courier. Today's guest post comes from Winston Chang, a software developer at RStudio - ed.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. Archives
January 2023
Categories |