Tuesday, November 18, 2008

Plot symbols in R

In the plot environment, the "pch" parameter decides the symbol of your output. There are about 130 symbols hard coded and passed into "pch."


However, there are still some symbols that are not in these 130 pch's. For instance, there is no checkmark. To plot checkmark or other symbols, we can use symbol() in the expression() or quote() functions. For example:

plot(0, 0, main=bquote(symbol("\326")))

There are over 300 symbols that can be plotted using this way.

5 comments:

Unknown said...

Thanks for the R tips. I particularly appreciated the one pointing out that apply is not faster than a loop. I have however a difficulty with pch and symbol: I cannot find pch and symbol returns an error:

> plot(0, 0, main=bquote(symbol("\326")))
Error in title(...) : invalid multibyte string

Any reason why?

Yu-Sung Su said...

Hi,

I have no problem with that code in your comment. I just copied it and pasted it. It worked. I think this might have something to do with your R. What version of R are you using? And did you install message translation (better not to do this)?

Unknown said...

Hi, my version is R version 2.5.1 (2007-06-27). I do not think I installed translation, but I do get the message "Natural language support but running in an English locale" when launching R...

Yu-Sung Su said...

So first try to install the newes R.

"Natural language support but running in an English locale"

That means you install the message tranlation. R will install it by default. So you have to choose not to install it.

sorrywm said...

This allows non-pch symbols in the margins or title, but it's not clear from this how to get them in the plot itself. How can we do that? Also, where can we find a translation so that we know 326 = checkmark, etc.?