Dear Todor,

How about this?
x<-c(1,-1,2,-2,3,-3,4,-4,5,-5)
y<-c(1,0,2,0,3,0,4,0,5,0)
DF<-data.frame(x,y)
plot(with(DF,DF[order(x),]),type='o')

HTH,

Jorge


On Fri, Jan 23, 2009 at 1:41 PM, Todor Kondic <dolichenus@gmail.com> wrote:

> Ok, here is a bit more information:
>
> R is version 2.7.1 (2008-06-23)
>
> A constructed example:
> ....
> > x<-c(1,-1,2,-2,3,-3,4,-4,5,-5)
> > y<-c(1,0,2,0,3,0,4,0,5,0)
> > plot(x,y,type='l')   #bad
> > plot(x,y) # this is how it should look like
> ....
>
> So what we should see here is a flat y=0 for x<0 and identity for x>0.
> Instead, we have a saw-like shape where e.g y(x=-1) is connected to
> y(x=1) .
>
> This is of course minor  (actually asymptotically, no annoyance at
> all). I am just mentioning it for 'completness' sake and because a
> divinely ideal plotting function should cope with data given in any
> order.
>
> Cheers!
>
> TK
>
> Cheers,
>
> TK
>
>
>
> 2009/1/23 jim holtman <jholtman@gmail.com>:
> > PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> > and provide commented, minimal, self-contained, reproducible code.
> >
> > A sample of data causing the problem would help.  It is most likely
> > the way you have it specified.
> >
> > On Fri, Jan 23, 2009 at 11:37 AM, Todor Kondic <dolichenus@gmail.com>
> wrote:
> >> Hello,
> >>
> >> I have 2d data where x coordinate is not given in usual ascending
> >> order (x1,...,x1+l; l>0), and instead in another, regular, but not
> >> ascending or descending order (for illustration:
> >> x1,-x1,x1+dx1,-x1-dx1,....).y is an array which corresponds to the way
> >> x is ordered. I have noticed that giving 'plot(x,y,type='l') produces
> >> a plot where the points are connected in a completely wrong way. It is
> >> as the plot/lines assumes an ascending order between the succesive y
> >> points ignoring the fact that they are not (it connects y(x1) with
> >> y(-x1), for x1+dx). I don't know whether this could be a bug, because
> >> maybe sorting the y coordinates appropriately and then interpolating
> >> lines plotting is too much to ask of the plot function. But, I've felt
> >> like sharing :-)
> >>
> >> Additionally, 'points' function will plot the data properly.
> >>
> >> Cheers,
> >>
> >> TK
> >>
> >> ______________________________________________
> >> R-help@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.
> >>
> >
> >
> >
> > --
> > Jim Holtman
> > Cincinnati, OH
> > +1 513 646 9390
> >
> > What is the problem that you are trying to solve?
> >
>
> ______________________________________________
> R-help@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.
>

	[[alternative HTML version deleted]]


