2011-08-21 219 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

相关问题