How to type Greek letters on the diagonal of a pair plot in R?

I want to create a paired section in R that has labels on the diagonal written in Greek letters. I tried to create a custom text.panel function that wraps the labels in the expression() call, but this does not work.

Here is a simple test case:

 pairs.greek <- function(x, ...) { panel.txt <- function(x, y, labels, cex, font, ...) { lab <- labels text(0.5, 0.5, expression(lab), cex=cex, font=font) } pairs(x, text.panel=panel.txt) } dat <- data.frame(alpha=runif(10), beta=runif(10), gamma=runif(10)) pairs.greek(dat) 
+6
symbols r
source share
1 answer

expression(lab) does not actually evaluate lab , so you get all lab tags. Instead, you can change this line to:

 text(0.5, 0.5, parse(text=lab), cex=cex, font=font) 

which will do what you want. Note that the pairs function also takes a label argument, so this will work too:

 pairs(dat, labels=c(expression(alpha), expression(beta), expression(gamma))) 
+5
source share

All Articles