2016-04-22 84 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

正如你所看到的,字體的大小變化大小,而線保持幾乎相同。嘗試與他們一起玩,直到你沒有找到你的情節的正確比例。