On the face of it, points
should add points to an existing R plot, while lines
should add a line. But reading the documentation and experimenting tell me that you can use any of the plot type
options with either. As a result, you can easily add points using lines
and lines using points
.
Is there actually a difference between these two commands, apart from the default value of type
?
Therefore, a line contains infinite points.
A line (straight line) can be thought of as a connected set of infinitely many points. It extends infinitely far in two opposite directions. A line has infinite length, zero width, and zero height.
A point has no dimension and a line has one dimension.
If three or more points lie on the same line, they are called collinear points. If three or more points lie on the same line, they are called collinear points.
No, there isn't any difference other than the default type
between points
and lines
. They are just wrappers of plot.xy
, as one can easily verify from the source code:
graphics:::points.default
#function (x, y = NULL, type = "p", ...)
#plot.xy(xy.coords(x, y), type = type, ...)
#<bytecode: 0x1ecccb8>
#<environment: namespace:graphics>
graphics:::lines.default
#function (x, y = NULL, type = "l", ...)
#plot.xy(xy.coords(x, y), type = type, ...)
#<bytecode: 0x1ec7938>
#<environment: namespace:graphics>
Just an addendum: this isn't uncommon in R. For instance the read.csv
, read.table
and family are basically the same function which just differ for the default value of some arguments. These wrappers are quite handy and often add readability to your code.
Second addendum: How I found the source code of these functions? Both points
and lines
are generic functions, with methods that apply depending on the class of the object argument. You might want to read this famous question:
How can I view the source code for a function?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With