[R] legend with math (greek letters) symbols

William Dunlap wdunlap at tibco.com
Sun Sep 14 16:49:21 CEST 2014


'q' should be an expression object, not a list of expression objects.
Try defining 'q' as
    q <- as.expression(lapply(lambdas, function(l)bquote(lambda==.(l))))

Bill Dunlap
TIBCO Software
wdunlap tibco.com


On Sat, Sep 13, 2014 at 5:55 PM, Julio Sergio Santana
<juliosergio at gmail.com> wrote:
> 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.
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.



More information about the R-help mailing list