[R] setting font in plots

Marc Schwartz marc_schwartz at comcast.net
Thu Mar 1 18:55:26 CET 2007


On Thu, 2007-03-01 at 23:48 +1000, Mark Allen wrote:
> Dear Reader
> 
> I am trying to change the font in a plot and after several trials finally 
> came up with the following code.
> 
> plot(var_a, var_b, pch = 16, font.lab = 10, font = 10)
> points(var_a, var_c, pch = 3, font = 10)
> legend(0.1, 0.8, legend = c(var_b, var_c), pch = c(16,3))
> 
> It does change the font in the plot (Courier), but not in the legend that 
> does not accept the "font = ..." argument. I could also not find a list with 
> font names and corresponding numbers.
> 
> Surely there must be a better way to do this that I cannot seem to find. 
> Looking at the R website I came across e.g. gpar() and par(), but 
> unfortunately could not make it work... Is there perhaps anyone that could 
> help me out here?
> 
> Thanks very much
> Mark Allen


Mark,

In ?par, note 'family', which can take on the values:

"serif", "sans", "mono", and "symbol", as well as supporting the Hershey
fonts.

So, if you want a mono font in the legend, use:

  par(family = "mono")

before your legend() call:

  plot(1:10)
  par(family = "mono")
  legend("topleft", legend = "This is a test")


HTH,

Marc Schwartz



More information about the R-help mailing list