[R] : bquote inside legend()

Prof Brian Ripley ripley at stats.ox.ac.uk
Mon Aug 11 19:08:02 CEST 2008


Perhaps you want

val <- substitute("value" == a, list(a = a))
legend(6, 5, do.call("expression", list("Legend", val)), bty = 'n')

?

Your first attempt is a character vector and your second fixed up quote 
and substitute.  But more likely would be

legend(6, 20, val, bty="n", title="Legend")


On Mon, 11 Aug 2008, Monica Pisica wrote:

>
> Hi,
>
> I have a graph and I would like to write some values inside the legend 
> that were saved in a variable. Please revise the code below in which 
> I've wrote 2 different legends, but I am not happy with either of them. 
> What I want is a legend with tile "Legend" and underneath a line with a 
> name and a value like that: value = 2.
>
> #Code begin:
> # -------------------
> a = 2	# result of a function for example
> plot(1:10, a*(1:10))
>
> legend(1, 20, c("Legend", bquote(value ==.(a))), bty = 'n')
>
> val <- substitute("value" ==.(a), list(a = a))
> legend(6, 5, do.call("expression",list("Legend", val)), bty = 'n')
>
> # -------------------
> # Code end
>
> In the first legend I don't like that value == 2 instead of value = 2, in the second legend, obviously I don't like the period and the brackets around the value of a.
>
> Thanks for any help,
>
> Monica
>
>
> _________________________________________________________________
>
>
> LM_WLYIA_whichathlete_us
> ______________________________________________
> 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.
>

-- 
Brian D. Ripley,                  ripley at stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595



More information about the R-help mailing list