If you install new fonts on your computer, you'll have to run fontimport again. Register the fonts with the PDF output device. The next step is to register the fonts in the afm table with R's PDF (or PostScript) output device. This is needed to create PDF files with the fonts. When it comes to making figures in R, you can use any font you like, as long as it's Helvetica, Times, or Courier. Using other fonts that are installed on your computer can seem an impossible task, especially if you want to save the output to PDF. Fortunately, the extrafont package makes this process much easier. With it, you can create. Times New Roman font family.; 2 minutes to read; a; P; W; m; v; In this article Overview. This remarkable typeface first appeared in 1932 in The Times of London newspaper, for which it was designed.
2021-02-18
svglite produces SVG files containing plain text but fonts are still important for plot generation and rendering. Fonts are used during SVG generation to figure out the metrics of graphical elements. The font name is then recorded in the font-family
property of text anchors so that SVG renderers know what fonts to use. svglite does try to ensure a consistent figure rendering even when fonts are not available at the time of rendering (by supplying the textLength SVG text attribute). However, the text may look slightly distorted when a fallback font is used. This means that for optimal display, the font must be available on both the computer used to create the svg, and the computer used to render the svg. The defaults are fonts that are available on almost all systems: there may be small differences between them, but they are unlikely to cause problems in most causes.
R family | Font on Windows | Font on Unix |
---|---|---|
sans | Arial | Arial |
serif | Times New Roman | Times |
mono | Courier | Courier |
symbol | Standard Symbols L | Symbol |
One downside to these default fonts is that they do not have good coverage of characters for non-latin alphabets. This can be fixed by using the arguments system_fonts
and user_fonts
which provide control over which fonts to use during SVG generation and rendering.
One downside to these default fonts is that they do not have good coverage of characters for non-latin alphabets. This can be fixed by using the arguments system_fonts
and user_fonts
which provide control over which fonts to use during SVG generation and rendering.
System font aliases
system_fonts
takes a named list of font families as argument. The names typically correspond to standard R faces but they can also alias non-standard families (though this is less useful):
If you need support for non-latin characters, choose fonts with good Unicode coverage. 'Arial Unicode MS' is a sans serif font with good coverage that is available on macOS and Windows systems (on the latter, only if MS Office is installed). Note that this font does not support kerning and has no bold or italic faces.
The Noto fontset provided by Google as well as the Han Sans family by Adobe have excellent coverage but may not be available at the time of rendering. This can be a concern if you distribute the SVG files on the Internet. Adobe 3d for mac.
User font aliases
In addition to system fonts, you can also provide fonts that are not necessarily installed on the system (i.e., fonts that live in user space). The main reason to do this is to generate reproducible SVG files as different platforms can have different versions of a font and thus produce different text metrics. The user_fonts
arguments takes either paths to font files, fonts from the fontquiver
package, or a list that specifies the alias. Whereas system_fonts
gets a named list of families as argument, user_fonts
takes a named tree of lists of families (sans
, serif
, mono
and symbol
) and faces (plain
, italic
, bold
, bolditalic
, symbol
):
You can also control which font gets written in the font-family
fields of SVGs by supplying a list containing alias
and file
elements:
Change Font To Times New Roman
fontquiver
fonts are particularly useful for creating reproducible SVG files. The vdiffr
package uses svglite with fontquiver fonts to create visual unit tests reliably across platforms. The Liberation fontset is appropriate for this usage because it features all 12 combinations of standard R families and faces. In addition fontquiver provides Symbola for the symbol font. The function fontquiver::font_families()
produces a list with the appropriate structure and can be directly supplied to svglite:
Debugging font matching
R Change Font To Times New Roman
The systemfonts package is used to match font family names to fonts installed on the system. systemfonts will always return a valid font, but if the requested font is badly misspelled or missing, a default will be returned. To test if the expected font is matched you can use the match_font()
and font_info()
functions from systemfonts: