[R] Plot, lines and disordered x and y

Todor Kondic dolichenus at gmail.com
Fri Jan 23 17:37:37 CET 2009


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




More information about the R-help mailing list