[R] Producing character "given" i.e. "| " with plotmath

Gorjanc Gregor Gregor.Gorjanc at bfro.uni-lj.si
Wed Jun 29 13:29:10 CEST 2005


>> Hello!
>> 
>> Does someone know how to produce
>> 
>>   L(y|mu)
>> 
>> with plotmath?
>> 
>> Some code with unsuccessfull results:
>> 
>> plot(dnorm(x = seq(from = -4, to = 4, by = 0.1)), type = "l")
>> ## Not what I want
>> legend(legend = c(expression(L(y:mu))), x = "topright")
>> 
>> ## Strange, is this a bug?
>> legend(legend = c(expression(L(y|mu))), x = "top")

> No, "|" is a logical Operator that can be rewritten in its original 
> function form as follows:
>
> "|"(FALSE, TRUE)
>
> Hence the result is expected.

Yes, that makes sense. Thanks!

>> ## Group produces an error
>> legend(legend = c(expression(group(L(y, "|", mu)))), x = "topleft")

> You have not specified any delimiter.
Ok, I got this point wrong from ?plotmath .

>> ## Paste keeps commas in expression
>> legend(legend = c(expression(paste(L(y, "|", mu)))), x = "bottomleft")

>correct

>> ## This one is OK, but braces are not as they should be 
>> legend(legend = c(expression(paste("L(y", "|", "mu)"))), x = "bottom")

> What's wrong with the braces?`
They are not the same as in previous cases. They are not "bold".

> What you really want is:
>    legend(legend = c(expression(L(group("", y, "|") * mu))),
>      x = "center")

Yes, that is what I want. Thanks!

I got additionally response from Roger D. Peng, which stated:

> How about
> legend(legend = expression("L(y | " * mu * ")"), x = "topleft")

That's also OK, but note above comment about "bold" braces.

Regards, Gregor




More information about the R-help mailing list