[R] vectorized plotmath expressions via substitute()

Uwe Ligges ligges at statistik.tu-dortmund.de
Sun Nov 18 19:34:37 CET 2012



On 15.11.2012 10:52, Gabor Grothendieck wrote:
> On Wed, Nov 14, 2012 at 12:05 PM, Murat Tasan <mmuurr at gmail.com> wrote:
>> hi all - i've seen versions of this question before, but none seem to get
>> directly at my solving my (probably very simple) issue:
>>
>> i simply want to annotate the tick marks on an axis with (superscripted)
>> 10^x notation, and tried this:
>>
>> axis(1, at = axTicks(1), as.expression(substitute(10^foo, list(foo =
>> axTicks(1))))
>>
>> thinking the as.expression/substitute would create the appropriate
>> expression vector from the expansion of the foo vector.
>> i'm continually stuck in the error process, however, with axis() where R
>> complains that i've only provided a single label.
>> i must be missing a function that explicitly "unfolds"(?) the result of the
>> substitute() call, without actually evaluating the contents of that call?
>>
>> sorry in advance if this is clear in the docs somewhere, though i just
>> can't seem to locate it :-/
>>
>
>
> See
>
> library(sfsmisc)
> ?eaxis


Or to answer the original question, without an extra package we could 
simply:

plot(1, xaxt="n")
axis(1, at=axTicks(1), as.expression(lapply(axTicks(1), function(x) 
substitute(10^foo, list(foo=x)))))

Uwe Ligges

> --
> Statistics & Software Consulting
> GKX Group, GKX Associates Inc.
> tel: 1-877-GKX-GROUP
> email: ggrothendieck at gmail.com
>
> ______________________________________________
> 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