Re: [R] curve

From: Greg Snow <Greg.Snow_at_imail.org>
Date: Thu, 15 Apr 2010 14:08:12 -0600

Or here is a way to plot against one of the variables while interactively changing the other one:

library(TeachingDemos)

myfun <- function(x,y) sin(x^2) * cos(y^2)

myfun2 <- function(y) curve( myfun(x,y), from=-pi, to=pi, ylim=c(-1,1) )

tkexamp( myfun2,

        list( y=list('slider', from=-pi, to=pi, resolution=2*pi/50, init=0) ) )

-- 
Gregory (Greg) L. Snow Ph.D.
Statistical Data Center
Intermountain Healthcare
greg.snow_at_imail.org
801.408.8111



> -----Original Message-----
> From: r-help-bounces_at_r-project.org [mailto:r-help-bounces_at_r-
> project.org] On Behalf Of Duncan Murdoch
> Sent: Thursday, April 15, 2010 7:29 AM
> To: Dwayne Blind
> Cc: r-help_at_r-project.org
> Subject: Re: [R] curve
>
> On 14/04/2010 4:59 PM, Dwayne Blind wrote:
> > Dear R users,
> >
> > How can I use "curve" with a function of two variables ?
> >
>
> See Ben Bolker's reply if you want to plot a surface. If you want to
> plot a curve by holding one of the two variables fixed, just set it to
> a
> constant value, and use "x" as the other variable, e.g.
>
> f <- function(x, y) { x^2 + y^2 }
>
> curve(f(x, 2), from= .... )
>
> curve(f(3, x), from= .... )
>
> or wrap the function in a one variable function if you want to follow
> some complicated path, e.g.
>
> curve(function(t) f(t, t^2), from=....)
>
> Duncan Murdoch
>
> ______________________________________________
> 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.
______________________________________________ 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.
Received on Thu 15 Apr 2010 - 20:11:15 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Fri 16 Apr 2010 - 22:00:11 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive