如何在R中更改绘图的字体族?

3

我试图将坐标轴和图例的字体更改为衬线字体,但添加family='serif'无法在图例中生效。应该怎么做?

plot(sort(n.cdf),pch=3,cex = 0.5,xlab="Order",ylab="Cn",family="serif")
par(new=TRUE)
plot(sort(emp.c),col="red",pch=1,cex = 0.5,ann=FALSE, axes=FALSE)
par(new=TRUE)
legend( "topleft"
         , inset = c(0,0.1) 
         , cex = 1
         , bty = "n"
         , legend = c("Simulated", "Empirical")
         , text.col = c("black", "red")
         , pt.bg = c("black", "red")
         , pch = c(3,1)
       , family=c("serif")
)
1个回答

4

在调用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( ... )

## reset plotting parameters
par(op)

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接