如何更改 R 图中图例中的字体系列? [英] How to change font family in a legend in an R-plot?

查看:82
本文介绍了如何更改 R 图中图例中的字体系列?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have a graph use the base graphics package. For the labels on specific points I use

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

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

I have also used this in the plot for main titles and axis labels. They all come out as expected.

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

When I add a legend I cannot seem to be able to set the font family.

有人可以帮忙吗.

谢谢.

推荐答案

在调用 legend() 之前将 family 绘图参数设置为您想要的值.通过显式调用 par() 来完成此操作.这是一个简单的例子

Set the family plotting parameter before calling legend() to the value you want. Do this via an explicit call to par(). Here is a simple example

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)

真的,您可以在第一次调用 plot() 之前更改 family 并省略 family = "serif" 参数在对 text() 的调用中.通过 par() 的设置对于当前设备是全局的,在函数调用中使用参数是该调用的本地参数.

Really, you could change family before you do the first call to plot() and leave out the family = "serif" argument in the call to text(). Setting via par() is global for the current device, using parameters within function calls is local to that call.

上面的代码产生:

这篇关于如何更改 R 图中图例中的字体系列?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆