如何更改R图中图例中的字体系列?

Joh*_*ohn 14 plot r legend

我有一个图使用基础图形包.对于我使用的特定点上的标签

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

我也在主题和轴标签的图中使用了它.他们都按预期出来了.

当我添加一个图例时,我似乎无法设置字体系列.

任何人都可以帮忙.

谢谢.

Rei*_*son 24

family在调用legend()所需的值之前设置绘图参数.通过显式调用来执行此操作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)
Run Code Online (Sandbox Code Playgroud)

真的,你可以family在第一次打电话之前改变,并在通话中plot()省略family = "serif"参数text().设置via par()是当前设备的全局,使用函数调用中的参数是该调用的本地参数.

上面的代码产生: 使用传说中的家庭

  • 干杯交配,你是_legend_! (4认同)