[R] Pasting R code lines into labels

Bert Gunter bgunter@4567 @end|ng |rom gm@||@com
Thu Jun 6 20:11:08 CEST 2019


Yes, plot(z,y,..)

Bert

On Thu, Jun 6, 2019 at 9:21 AM Nick Wray <nicholas.wray using ntlworld.com> wrote:

> Thanks Bert, that is exactly what I wanted.  I think that you meant
> plot(z,y... in the last line?
>
> Nick
>
> On 06 June 2019 at 17:13 Bert Gunter <bgunter.4567 using gmail.com> wrote:
>
> ... and if you wanted too streamline the process, something like the
> following could be encapsulated in a function:
>
> fun <- quote(exp(x))
> z <- 1:9
> y <- eval(fun,list(x = z) )
> plot(x, y, main = paste("Plot of y =", deparse(fun)))
>
> Further details can be found in the "Computing on the Language" section of
> the "R Language Reference" manual or from suitable tutorials on the web.
>
> Bert Gunter
>
> "The trouble with having an open mind is that people keep coming along and
> sticking things into it."
> -- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )
>
>
> On Thu, Jun 6, 2019 at 8:55 AM Nick Wray via R-help < r-help using r-project.org>
> wrote:
>
> Thanks but that's not quite what I meant
> I am trying out different functions and they don't necessarily vary in a
> regular way (like say all being powers of x where it'd be simple to just
> have a vector for the powers you want)
> So I might have
> y<-x^2
> y<-cos(x)
> y<-exp(x+1)
> What I am after is a way of running these functions and then calling each
> one into the labelling for the appropriate graph as I plot it.  So then I
> would have something like
> mainlab<-paste("Plot of ",function in question)
> ...? Thanks Nick
>
> > On 06 June 2019 at 16:40 Marc Schwartz < marc_schwartz using me.com> wrote:
> >
> >
> >
> > > On Jun 6, 2019, at 11:19 AM, Nick Wray via R-help <
> r-help using r-project.org> wrote:
> > >
> > > Is there any way of taking a line of r code (eg y<-x^2) and pasting
> that line of code, as is, into a label, so that for example I could then
> have a plot label "Plot of y<-x^2"?
> > >
> > > Thanks Nick Wray
> >
> >
> > Hi,
> >
> > See ?plotmath
> >
> > An example:
> >
> > x <- 1:10
> > y <- x^2
> >
> > plot(x, y, main = expression(paste("Plot of ", y %<-% x^2)))
> >
> >
> > There are other incantations and examples on the help page above.
> >
> > Regards,
> >
> > Marc Schwartz
> >
>
> ______________________________________________
> R-help using r-project.org mailing list -- To UNSUBSCRIBE and more, see
> 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.
>
>

	[[alternative HTML version deleted]]



More information about the R-help mailing list