调整R中图例的字体

调整R中图例的字体,r,plot,legend,R,Plot,Legend,我使用legend()生成如下所示的图例 文本位于打印框之外。我尝试使用cex=来调整框,但是,它只能调整整个框的大小,而与文本字体无关 有没有办法让文字字体变小 以下是我的示例代码: legend("bottomleft", legend = c("Simulated", "Estimated/Predicted Median", "95% Credit Intervals"), col = c("gray35", "red", "red"), lty =

我使用
legend()
生成如下所示的图例

文本位于打印框之外。我尝试使用
cex=
来调整框,但是,它只能调整整个框的大小,而与文本字体无关

有没有办法让文字字体变小

以下是我的示例代码:

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')
如果设置
bty=“n”
它将不会绘制框

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',bty="n")

尝试将
pt.cex
参数保持为1,同时在图例调用中尝试
cex
的不同值
pt.cex
控制图例点和线的大小

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) 

x您可以通过应用
par()
来设置图形参数。例如:

plot(c(1:4), c(1:4), type  = 'l')    
par(cex = 1) #set legend font to 1
legend("topleft", legend="a line", lty = 1)

这取决于您如何创建图形设备。但是您可以使用
text.width
arguments扩展框是的,但是它们之间的行距看起来很窄。我仍然想调整它们,例如,使它们之间的空间变大。