[R] curve

Greg Snow Greg.Snow at imail.org
Thu Apr 15 22:08:12 CEST 2010


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.



More information about the R-help mailing list