[R] plot numerous functions in one figure with different values of x per function

Gloria_M g-l-o-r-y at hotmail.com
Mon Feb 21 19:01:13 CET 2011


To the more experienced R users,

I am not a professional programmer so please excuse me if my questions seem
naive. 
I have only begun using R to solve some problems and I'm already regretting
it

1.
I am trying to plot different functions in the same figure. The first
function 
f(x)= sin(x)+(pi/4) , -2pi<=x<=2pi
the second function
g(x) = {sin(x), 0 <= x <= pi or −2pi <= x <= -pi
         {-pi/4, elsewhere 

my code is:
> x<-seq(from=-2*pi,to=2*pi,length=1000)
> fx<- (sin(x)+(pi/4))
> plot(x,fx,type="l",lty=1)
> x2<- seq(from=0,to=pi)
> x3<- seq(from=-2*pi,to=-pi)
> gx<-(sin(x2 | x3) + (-pi/4))
> lines(x,gx,lty=2)
Error in xy.coords(x, y) : 'x' and 'y' lengths differ


it plots the first function but when I try to plot the second function it
displays the error x,y coordinates differ. I assume this is because I am
using different values for x in the first and second functions?
any ideas will be appreciated.
-- 
View this message in context: http://r.789695.n4.nabble.com/plot-numerous-functions-in-one-figure-with-different-values-of-x-per-function-tp3317784p3317784.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list