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

查看:873
本文介绍了如何在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,并在对text()的调用中省略family = "serif"自变量.通过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天全站免登陆