Joshua G. answered 09/20/24
PhD in Biostatistics with 11 Years of R Programming Experience
Given that you already ran the code line x <- rnorm(100), the following code allows you to increase the font size of the title, axis labels, and text on the axes in base R:
hist(x, xlim=range(x), xlab= "Variable Label", ylab="density",
main="Title of plot", prob=TRUE, cex.main = 2, cex.lab = 2,cex.axis = 2)
The arguments cex.main, cex.lab, and cex.axis allow you to change the font size for the title, axis labels, and text on the axes respectively. Values greater than 1 increase the font size while values less than 1 decrease the font size.
It is also possible to separate changing the font size from the plotting function that generates the histogram. Given that you have already run the codes line x <- rnorm(100) and x.df <- data.frame(X=x), the following code allows you to increase the font size of the title, axis labels, and text on the axes by using the R library called ggplot2:
library(ggplot2)
ggplot(x.df,aes(X,after_stat(density))) +
geom_histogram() +
xlim(range(x)) +
labs(x= "Variable Label", y= "density") +
ggtitle("Title of plot") +
theme( axis.text=element_text(size=30),
axis.title=element_text(size=30),
plot.title=element_text(size=30))
The code statement element_text(size=30) that is passed to the arguments axis.text, axis.title, and plot.title for the theme function allow you to change the font size for the title, axis labels, and text on the axes respectively. The values passed to the size argument for the element_text function specify the desired text size in points.