简体   繁体   English

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

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

I'm wondering how to boldface the entire phrase: " 95% CI: [number 1 , number 2 ] " as a legend in my plot below? 我想知道如何将整个短语:“ 95%CI:[数字1,数字2]加粗为我下面的情节中的图例? ( Note: "number 1" and "number 2" are specified in my code below). 注意: “数字1”“数字2”在下面的代码中指定)。

Here is my R code which requires a fix: 这是我的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 If I omit the bold() part from the code, the entire phrase shows normally, but I loose the bolding effect. PS:如果我从代码中省略了bold()部分,则整个短语都可以正常显示,但是我失去了加粗效果。

Two options/workarounds: 两种选择/解决方法:

  1. You can bold() each literal string individually, but I don't know how to bold the dynamic portions (eg, .(round(.4432,3)) ). 您可以分别对每个文字字符串执行bold() ,但是我不知道如何对动态部分进行加粗(例如.(round(.4432,3)) )。 This would look like: 看起来像:

     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)) 

    The numbers are not bold. 数字不是粗体。

  2. With this label/legend, you don't actually need bquote , so you can use the text.font option of legend to bold the whole string: 有了这个标签/传说,你实际上并不需要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) 

    The disadvantage with this is that you are you able to use math symbols. 这样做的缺点是您可以使用数学符号。

The text.font is a legend -specific argument for the more-generic font parameter, found in ?par : 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