Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

specifying font size in R figures

Tags:

r

font-size

Is there a method for specifying the font size in when producing figures in R. This seems like a really basic requirement but I can't seem to find any references to somewhere that specifies the font size. I can save a figure to a pdf as follows:

setwd("C:\\")
pdf(file="Plot.pdf",family="Times")
plot(x,y);
dev.off()

Where R basically generates the figure in the pdf not in the figure window. When I look for ways of altering the font size all I see is people referring to cex=1.5 argument to scale fonts 150 percent, and cex.lab, cex.axis, etc ... Although not being an immediate issue now, I do wonder what will happen when I publish some results and the journal requires font size between 9 and 11. How do I control these in R? Any suggestions would be appreciated.

like image 427
KatyB Avatar asked Dec 12 '12 19:12

KatyB


People also ask

What is default font in R figures?

The default font families are 'sans', 'serif' and 'mono'. The first element of the vector is the normal face, then bold face, then italic face, then bold-italic font face. The bold face is used for the title of the plots, for example.

How do I change the font size of legend in R plot?

To change the legend size of the plot, the user needs to use the cex argument of the legend function and specify its value with the user requirement, the values of cex greater than 1 will increase the legend size in the plot and the value of cex less than 1 will decrease the size of the legend in the plot.

How do I make the font bigger in ggplot2?

How can I change the default font size in ggplot2? Set base_size in the theme you're using, which is theme_gray() by default. The base font size is 11 pts by default. You can change it with the base_size argument in the theme you're using.

How do I change the font size in a Boxplot in R?

The font size of the main title of boxplot can be changed by defining the font size value using par(cex. main=”size”), here size value can be changed based on our requirement. This needs to be done before creating the boxplot, otherwise, there will be no effect on the size of the main title.


1 Answers

You control the font size with the ps (point size) parameter. The default is typically 12 (but can be controlled globally for a PDF file by the pointsize parameter) so if you want, let's say, fonts of the size 10 for a particular text you would use par(ps=10); text(...). Since you mentioned cex: note that cex is relative to the current pointsize and also applies to symbols whereas ps specifically applies to text. Obviously, the size will only match as long as you don't resize the resulting figure.

like image 105
Simon Urbanek Avatar answered Oct 24 '22 00:10

Simon Urbanek