Boldfacing Plot Legend with words, numbers, and symbols in R



我想知道如何 boldface 整个短语:" 95%CI:[数字1,数字2] " AS我的情节中的传奇?(注意:"编号1" "编号2" 在我的代码中指定)。

这是我的R代码,它需要修复:

plot(1:10,ty="n",bty="n")
legend("topleft", legend=bquote(paste(bold("95% CI: [ ", .(round(.4432, 3)), 
", " , .(round(.0034, 3))," ]"))), 
                 bty="n", inset=c(0,.03))

P.S。如果我从代码中省略了 bold()零件,则整个短语正常显示,但是我松开了 bolding 效果。

两个选项/解决方案:

  1. 您可以单独 bold()每个文字字符串,但是我不知道如何使动态部分(例如.(round(.4432,3)))大胆。这看起来像:

    plot(1:10,ty="n",bty="n")
    legend("topleft", legend=bquote(paste(bold("95% CI: [ "), .(round(.4432, 3)), 
                                          bold(", ") , .(round(.0034, 3)),
                                          bold(" ]"))), 
           bty="n", inset=c(0,.03))
    

    数字不是大胆的。

  2. 使用此标签/图例,您实际上不需要bquote,因此您可以使用text.font选项legend来凸起整个字符串:

    plot(1:10,ty="n",bty="n")
    legend("topleft", legend=paste("95% CI: [ ", round(.4432, 3),
                                   ", " , round(.0034, 3),
                                   " ]"),
           bty="n", inset=c(0,.03), text.font=2)
    

    与此的缺点是您可以使用数学符号。

text.fontfont中更常规CC_9参数的legend - 特定参数:

 'font' An integer which specifies which font to use for text.  If
      possible, device drivers arrange so that 1 corresponds to
      plain text (the default), 2 to bold face, 3 to italic and 4
      to bold italic.  Also, font 5 is expected to be the symbol
      font, in Adobe symbol encoding.  On some devices font
      families can be selected by 'family' to choose different sets
      of 5 fonts.

最新更新