[R] using a variable and a superscript in a legend

Peter Dalgaard pd@|gd @end|ng |rom gm@||@com
Sun Oct 20 21:06:44 CEST 2019


You're right. I was worried that c() would create a character vector and deparse the unevaluated call in the process, but apparently it is an implicit as.character _inside_ legend that is doing us in. (I can't offhand see where it is happening, but there might be scope for improvement if legend() would just accept a list object and treat the elements separately).

-pd

> On 20 Oct 2019, at 20:28 , Bert Gunter <bgunter.4567 using gmail.com> wrote:
> 
> However, note that:
> 
> > class(c("Sans renard", bquote(.(densren) (ind./km)^2)))
> [1] "list"  # by coercion
> 
> so it does not seem necessary to explicitly call list(). That is:
> 
>    plot(1:100,1:100,type="n")
>    legend(list(x=0,y=100), legend = as.expression(c("Sans renard", bquote(.(densren) (ind./km)^2))),lty=c(1,2),col=c("black","red"),bty="n")
> 
> appears to suffice. I would appreciate correction if I'm wrong about this.
> 

-- 
Peter Dalgaard, Professor,
Center for Statistics, Copenhagen Business School
Solbjerg Plads 3, 2000 Frederiksberg, Denmark
Phone: (+45)38153501
Office: A 4.23
Email: pd.mes using cbs.dk  Priv: PDalgd using gmail.com



More information about the R-help mailing list