Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adjust the font of legend in R

Tags:

plot

r

legend

I use legend() to produce a legend shown below

Legend of a plot

The text lies beyond the plot box. I tried to use cex = to adjust the box, however, it can only adjust the size of the whole box, but have nothing to do with the text font.

Is there anyway to make the text font smaller?

Here is my sample code:

legend("bottomleft", legend = c("Simulated", "Estimated/Predicted    
       Median", "95% Credit Intervals"),
       col = c("gray35", "red", "red"), lty = c(1, 1, 2), 
               lwd = c(3, 2, 1),
       text.font = 3, inset=.02, bg='gray90')
like image 254
Paul Avatar asked Dec 29 '25 08:12

Paul


1 Answers

You can set graphical parameters by applying par(). For example:

plot(c(1:4), c(1:4), type  = 'l')    
par(cex = 1) #set legend font to 1
legend("topleft", legend="a line", lty = 1)
like image 117
Summer Jinyu Xia Avatar answered Jan 02 '26 06:01

Summer Jinyu Xia



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!