Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Fonts in R plots

Tags:

r

fonts

graphics

What graphics devices let me use system fonts for text within charts? The base graphics system only has a small amount of documentation around the par(family=...) options.

Ideally I'd like to be able to use any font I can browse through a tool like xfontsel on Linux or the equivalent utilities on other platforms.

My current solution is to plot out as PDF and then use a 3rd party program to replace the fonts from within the PDF. This is not ideal.

like image 388
Josh Reich Avatar asked Sep 08 '09 17:09

Josh Reich


People also ask

What font is used in R plots?

You'll see the default font device "Helvetica".

What fonts are available in R?

The integrated fonts in R are sans (Arial), serif (Times New Roman), mono (Courier) and symbol (Standard Symbols L). However, it is possible to add custom fonts in R with the extrafont or the showtext packages.


1 Answers

A list of fonts is available to the pdf() command, like this:

> names(pdfFonts())  [1] "serif"                "sans"                 "mono"                  [4] "AvantGarde"           "Bookman"              "Courier"               [7] "Helvetica"            "Helvetica-Narrow"     "NewCenturySchoolbook" [10] "Palatino"             "Times"                "URWGothic"            ... etc ... 

To use when creating a PDF, for example:

> pdf(file="plot.pdf",family="Palatino", pointsize=16, width=16,height=10) 
like image 78
ariddell Avatar answered Oct 03 '22 23:10

ariddell