Question: I use `legend()` to produce a legend shown below

[![Legend of a plot](https://i.stack.imgur.com/3nUuy.png)](https://i.stack.imgur.com/3nUuy.png)

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')

```

Answer: 
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)

```
Try to hold the `pt.cex` parameter to 1, while trying different values for `cex` inside the legend call. `pt.cex` control the size of points and lines of the legend.

```
x <- rnorm(100, 10, 4)
y <- rnorm(100, 10, 4)
plot(x, y, type = "n")

## I tried to feed cex with 1.1 and 0.4. The font size changes while the lines remain unchanged.

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', pt.cex = 1, cex = 0.4) 

```

[![enter image description here](https://i.stack.imgur.com/Cjus7.png)](https://i.stack.imgur.com/Cjus7.png)

As you can see, the size size of the font change while the lines remain almost the same. Try play with them until you do not find the correct proportions for your plot.