[R] legend with math (greek letters) symbols

Julio Sergio Santana juliosergio at gmail.com
Sun Sep 14 02:55:00 CEST 2014


I need to add a legend with three entries that should
contain a greek letter (lambda). I learnt that it is
possible using the function expression. So I need to
build the expressions from the lambdas vector, and I
simply cannot do it. This is the uggly result I got:


   x <- 0:20
   cc <- c("yellow", "springgreen", "navyblue")
   lambdas <- c(6, 10, 13)
   ds <- as.data.frame(lapply(lambdas, function(ll) dpois(x, ll)))
   names(ds) <- lambdas
   funcs <- list(plot, lines)

   for (i in 1:3) {
       ff <- funcs[[1+(i!=1)]]
       ff(x,ds[[i]], type="o", pch=21,bg=cc[i])
   }
   
   # I can't build the expressions:
   q <- list(expression(lambda==6), expression(lambda==10),   
             expression(lambda==13))
  
   legend("topright", 
          legend=q,
          lty=1, pch=21, pt.bg=cc)

legend() doesn't interpret the expressions and then it doesn't show
the lambda symbol.

Do you have any comments on this?

Thanks,

  -Sergio.



More information about the R-help mailing list