To change the font size of text, use cex (character expansion ratio). The default value is 1. To reduce the text size, use a cex value of less than 1; to increase the text size, use a cex value greater than 1.
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.
To change the axis scales on a plot in base R Language, we can use the xlim() and ylim() functions. The xlim() and ylim() functions are convenience functions that set the limit of the x-axis and y-axis respectively.
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
, ...
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)
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)
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)
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:
By trial and error, I've determined the following is required to set font size:
cex
doesn't work in hist()
. Use cex.axis
for the numbers on the axes, cex.lab
for the labels.cex
doesn't work in axis()
either. Use cex.axis
for the numbers on the axes.hist()
, you can set them using mtext()
. You can set the font size using cex
, but using a value of 1 actually sets the font to 1.5 times the default!!! You need to use cex=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.pointsize
in pdf()
.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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With