2017-02-27 172 views
0

我想知道如何粗体整个短语:“95%CI:[数字1,号2]”如在下面我的情节的图例? (注:“编号1”“编号2”在我的代码中指定)。加粗图例与文字,数字,和中的R符号

这是我的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()部分,整个短语显示正常,但是我忽略了粗体的影响。

回答

1

两个选项/解决方法:

  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,所以你可以使用的legendtext.font选项大胆整个字符串:

    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.font是用于更通用的font参数,在?par发现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. 
+0

高度赞赏。 – rnorouzian