【问题标题】:How to change font family in this R plot? [duplicate]如何更改此 R 图中的字体系列? [复制]
【发布时间】:2015-04-10 03:21:19
【问题描述】:

我正在尝试将轴和图例的字体更改为衬线,但添加 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")
)

【问题讨论】:

    标签: r fonts plot font-family


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-11-17
      • 2018-01-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-11-21
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多