2011-08-21 348 views
11

我有一個圖形使用基本圖形包。對於我使用的特定點上的標籤,我使用了如何更改R圖中圖例的字體系列?

text(i, MSSAcar$summary[i,7]+.7, qld$LGA[i], 
    col='red', cex=.7, family='serif') 

我也在主要標題和軸標籤的繪圖中使用了它。他們都按預期出來了。

當我添加一個圖例我似乎無法設置字體系列。

任何人都可以幫忙。

謝謝。

回答

18

在調用legend()到您想要的值之前,設置family繪圖參數。通過明確致電par()來完成此操作。下面是一個簡單的例子

x <- y <- 1:10 
plot(x, y, type = "n") 
text(x = 5, y = 5, labels = "foo", family = "serif") 

## set the font family to "serif" 
## saving defaults in `op` 
op <- par(family = "serif") 

## plot legend as usual 
legend("topright", legend = "foo legend", pch = 1, bty = "n") 

## reset plotting parameters 
par(op) 

真的,你可以改變你family做第一次調用plot()前,離開了在呼叫中family = "serif"參數text()。通過par()進行設置對於當前設備是全局的,使用函數調用中的參數對於該調用是本地的。

以上代碼生成: use of family with legend

+2

乾杯隊友,你是一個_legend_! – John