How to change the font size of legend in base R plot?

R ProgrammingServer Side ProgrammingProgramming

In base R, we can use legend function to add a legend to the plot. For example, if we want to create a histogram with legend on top-right position then we can use legend("topright",legend="Normal Distribution") and if we want to change the font size then we need to as cex argument as shown below:

legend("topright",legend="Normal Distribution",cex=2)

Example

Live Demo

Consider the below histogram −

x<−rnorm(5000)
hist(x)

Output

Adding legend of different sizes −

legend("topright",legend="Normal Distribution",cex=1)


Output

legend("topleft",legend="Histogram of",cex=1.5)

Output

Published on 07-Nov-2020 15:33:26