2016-04-22 45 views
2

的字体我用legend()产生如下图所示调整传说中的R

Legend of a plot

传说中的文本范围超出情节框。我试图使用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') 
+1

这取决于您如何创建图形设备。但您可以使用'text.width'参数 – rawr

回答

1

您可以通过应用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) 
0

如果设置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") 
+0

扩展该框,但是它们之间的行间距看起来很窄。我仍然想调整它们,例如使它们之间更小,空间更大。 –

0

尝试将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) 

enter image description here

正如你所看到的,字体的大小变化大小,而线保持几乎相同。尝试与他们一起玩,直到你没有找到你的情节的正确比例。