[R] Substitute in legend
Uwe Ligges
ligges at statistik.uni-dortmund.de
Sat Aug 23 19:11:45 CEST 2003
Peter Dalgaard BSA wrote:
> partha_bagchi at hgsi.com writes:
>
>
>>I tried to use substitute in legend as follows:
>>
>>pval <- 0.04
>>plot(0)
>>legend(1,0.5,substitute(hat(theta) == p, list(p = pval)))
>>
>>For some reason the legend is repeated 3 times.
>>
>>Any suggestions or is this a bug?
>
>
> It's a bug. The code is looking at length(legend), but that is not the
> number of legends when mode "call" objects are concerned. A workaround
> is
>
> legend(1,0.5,as.expression(substitute(hat(theta) == p, list(p = pval))))
Or more general:
do.call("expression",
list(substitute(hat(theta) == p, list(p = pval))))
This way you can include several substitute() calls within that list, to
allow an expression of length > 1 which is frequently required for legends.
I think it is not really a bug, because this is documented,
but inserting
if(is.call(legend))
legend <- as.expression(legend)
would not break anything, AFAICS.
Uwe Ligges
More information about the R-help
mailing list