R Base Graphic:使用逻辑符号(和/或)进行批注

时间:2013-08-20 22:42:55

标签: r plot expression symbols plotmath

我想将逻辑符号and(∧)和or(∨)添加到R中的基本图形中。

我认为要走的路可能会使用表达式,但我无法弄清楚如何,因为他们的unicode代码\u2227\u2228不起作用。也许是因为我在Windows上(赢得7,64位)。

我有什么:

plot(1, 1, pch = "")
text(1, 1.2, 
     expression(paste("low ", italic(P), "(", italic(p), " and ", italic(q), 
        "), -1 SD")), cex = 1.2)
text(1, 0.8, 
     expression(paste("low ", italic(P), "(\u00ac", italic(p), " or ", italic(q), 
         "), -1 SD")), cex = 1.2)

enter image description here

我想用符号对应的文字andor替换它。

1 个答案:

答案 0 :(得分:3)

使用符号字体映射的详细信息在:

?plotmath
?points # to which plotmath sends you for mapping of 'symbol' characters

# And I do not like the plotmath-paste function, 
# so translated to 'pure' expressions.
# The number arguments to symbol are numbers in octal.

plot(1, 1, pch = "")
text(1, 1.2, 
       expression(low ~italic(P)*"("*italic(p)~
                                   symbol("\332")~ italic(q)* 
                                  "), -1 SD"), 
       cex = 1.2)
text(1, 0.8, 
   expression(low~italic(P)* 
               "("*symbol("\330")*italic(p)~symbol("\331")~ italic(q)*
               "), -1 SD"),
    cex = 1.2 )

这是请求显示符号字形及其小数索引的代码。 (警告:这是Mac上的Symbol字体。不保证在任何地方都是相同的。)你仍然需要转换为八进制引用以使用上面显示的“\ nnn”形式:

> as.octmode(216)
[1] "330"

TestChars <- function(sign = 1, font = 1, ...)
{
   MB <- l10n_info()$MBCS
   r <- if(font == 5) { sign <- 1; c(32:126, 160:254)
       } else if(MB) 32:126 else 32:255
   if (sign == -1) r <- c(32:126, 160:255)
   par(pty = "s")
   plot(c(-1,16), c(-1,16), type = "n", xlab = "", ylab = "",
        xaxs = "i", yaxs = "i",
        main = "Symbol Font, Decimal Indices")
   grid(17, 17, lty = 1) ; mtext(paste("MBCS:", MB))
   for(i in r) try(points(i%%16, i%/%16, pch = sign*i, font = font,...))

   for(i in r) try(text(x=i%%16, y=(i%/%16)-0.4, i, cex=0.5 , font = font,...))
}

TestChars(font = 5)

enter image description here