Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between points and lines

Tags:

plot

r

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?

like image 851
Jessica B Avatar asked Jun 25 '19 09:06

Jessica B


People also ask

How many points is a line?

Therefore, a line contains infinite points.

Do all lines have 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.

What is correct about a line and a point?

A point has no dimension and a line has one dimension.

Are points on the same line?

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.


1 Answers

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?

like image 135
nicola Avatar answered Sep 30 '22 16:09

nicola