繁体   English   中英

R中带有单词,数字和符号的粗体图图例

[英]Boldfacing Plot Legend with words, numbers, and symbols in R

我想知道如何将整个短语:“ 95%CI:[数字1,数字2]加粗为我下面的情节中的图例? 注意: “数字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))

PS:如果我从代码中省略了bold()部分,则整个短语都可以正常显示,但是我失去了加粗效果。

两种选择/解决方法:

  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.font是更常见的font参数的legend专用参数,可在?par找到:

 '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.

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM