An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20121114/964e9f6f/attachment.pl>
vectorized plotmath expressions via substitute()
5 messages · Murat Tasan, William Dunlap, Gabor Grothendieck +1 more
I recommend using bquote(), with its .() substitution operator, instead of substitute any time you use plotmath. To make a vector of plotmath expressions use the following sort of as.expression(lapply(... bquote ...)) idiom: plot(1:10, axes=FALSE) at <- axTicks(1) lab <- as.expression(lapply(at, function(a)bquote(10^.(a)))) axis(1, at=at, lab=lab) Bill Dunlap Spotfire, TIBCO Software wdunlap tibco.com
-----Original Message----- From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] On Behalf Of Murat Tasan Sent: Wednesday, November 14, 2012 9:06 AM To: r-help at r-project.org Subject: [R] vectorized plotmath expressions via substitute() 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 :-/ cheers and thanks for any pointers! -murat [[alternative HTML version deleted]]
______________________________________________ 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.
An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20121114/b1586657/attachment.pl>
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 -- Statistics & Software Consulting GKX Group, GKX Associates Inc. tel: 1-877-GKX-GROUP email: ggrothendieck at gmail.com
3 days later
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.