Draw all the lines between the points

I have the following R code

x <- c(0.01848598, 0.08052353, 0.06741172, 0.11652034) y <- c(0.4177541, 0.4042247, 0.3964025, 0.4074685) d <- data.frame(x,y) ggplot(d, aes(x=x, y=y)) + geom_point(size=4) 

Creates the following graph:

Rpoints

I would like to draw all possible lines between these points in a repeatable way, i.e. number, location, etc. points may change. Does anyone know about the function R to do something like this. The standard + geom_point () only draws lines between subsequent points on the x axis. My perfect way out is shown below. Thanks in advance.

RPoints with lines

BONUS . Does anyone know a metric (preferably in R) to estimate the amount of space that spans multiple points? In this case, the set of space contained in the outer triangle.

EDIT - Bonus already answered in another SO question here

+5
source share
1 answer

You can always do the conversion to create all the segments you want to create.

 x <- c(0.01848598, 0.08052353, 0.06741172, 0.11652034) y <- c(0.4177541, 0.4042247, 0.3964025, 0.4074685) d <- data.frame(x,y) idx <- combn(1:length(x), 2) dd <- data.frame(x=x[idx[1,]],y=y[idx[1,]], xend=x[idx[2,]], yend=y[idx[2,]]) ggplot(d,aes(x,y)) + geom_point(data=d) + geom_segment(data=dd, aes(xend=xend, yend=yend)) 

that leads to

enter image description here

+8
source

Source: https://habr.com/ru/post/1205640/


All Articles