0

I used plot(x, y, type="p") to draw a scatter plot, and it seems right (Figure 1). However, when using plot(x, y, type="l") to draw a line, there are some mussy lines (Figure 2). Why didn't it a "single" line?

Figure 1 Figure 2

T X
  • 505
  • 1
  • 9
  • 19

1 Answers1

1

Looks like your x vector needs to be sorted, when using line plots, the order in which your points are submitted is very important as the lines are drawn connecting one point to the next one.

y <- y[order(x)]
x <- x[order(x)]
# now you can make your plot
plot(x, y, type="l")
fmarm
  • 4,209
  • 1
  • 17
  • 29