3

I would like to add the logical symbols and (∧) and or (∨) to a base graph in R.

I figured that the way to go will probably be using an expression, but I can't figure out how, as their unicode codes \u2227 and \u2228 are not working. Perhaps because I am on windows (win 7, 64 bit).

What I have:

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

I would like to replace the literal and and or with their symbol counterpart.

plannapus
  • 18,529
  • 4
  • 72
  • 94
Henrik
  • 14,202
  • 10
  • 68
  • 91
  • If you work your way through `example(points)` you'll see some logical operators in there displayed. (I think it's the `TestChars(font = 5)` line.) – joran Aug 20 '13 at 22:51
  • @joran - that code hurts my head. I'm bamboozled how that could be worked into a `text(..)` call. – thelatemail Aug 21 '13 at 00:21

1 Answers1

3

The details for the use of the Symbol font mappings are on:

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

This is the code requested to display the Symbol glyphs and their decimal indices. (Caveat: This is the Symbol font on a Mac. No guarantees this will be the same everywhere.) You still need to convert to octal to reference to use the form "\nnn" seen above:

> 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

IRTFM
  • 258,963
  • 21
  • 364
  • 487
  • 2
    I used the code in TextChars to print out a decimal coded table of plotmath "symbol"-characters and then converted the decimal coding to octal because I couldn't figure the right way to address it in decimal. I probably spent almost an hour and a half. Not the first time I have gone down this rabbit hole, either. So where's my checkmark, anyway? – IRTFM Aug 21 '13 at 07:30
  • There you go. If you still have the code for getting the decimals that would be awesome, because that thing sucked. Thanks a lot and I hope you get more upvotes. – Henrik Aug 21 '13 at 09:56
  • 2
    OK. The decimal indices are printed below the glyphs. – IRTFM Aug 21 '13 at 10:35