How to increase font size in a plot in R?
Solution 1:
You want something like the cex=1.5
argument to scale fonts 150 percent. But do see help(par)
as there are also cex.lab
, cex.axis
, ...
Solution 2:
Thus, to summarise the existing discussion, adding
cex.lab=1.5, cex.axis=1.5, cex.main=1.5, cex.sub=1.5
to your plot, where 1.5 could be 2, 3, etc. and a value of 1 is the default will increase the font size.
x <- rnorm(100)
cex doesn't change things
hist(x, xlim=range(x),
xlab= "Variable Lable", ylab="density", main="Title of plot", prob=TRUE)
hist(x, xlim=range(x),
xlab= "Variable Lable", ylab="density", main="Title of plot", prob=TRUE,
cex=1.5)
Add cex.lab=1.5, cex.axis=1.5, cex.main=1.5, cex.sub=1.5
hist(x, xlim=range(x),
xlab= "Variable Lable", ylab="density", main="Title of plot", prob=TRUE,
cex.lab=1.5, cex.axis=1.5, cex.main=1.5, cex.sub=1.5)
Solution 3:
By trial and error, I've determined the following is required to set font size:
-
cex
doesn't work inhist()
. Usecex.axis
for the numbers on the axes,cex.lab
for the labels. -
cex
doesn't work inaxis()
either. Usecex.axis
for the numbers on the axes. - In place of setting labels using
hist()
, you can set them usingmtext()
. You can set the font size usingcex
, but using a value of 1 actually sets the font to 1.5 times the default!!! You need to usecex=2/3
to get the default font size. At the very least, this is the case under R 3.0.2 for Mac OS X, using PDF output. - You can change the default font size for PDF output using
pointsize
inpdf()
.
I suppose it would be far too logical to expect R to (a) actually do what its documentation says it should do, (b) behave in an expected fashion.
Solution 4:
Notice that "cex" does change things when the plot is made with text. For example, the plot of an agglomerative hierarchical clustering:
library(cluster)
data(votes.repub)
agn1 <- agnes(votes.repub, metric = "manhattan", stand = TRUE)
plot(agn1, which.plots=2)
will produce a plot with normal sized text:
and plot(agn1, which.plots=2, cex=0.5)
will produce this one: