5

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)

It creates the following graph:

RPoints

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

RPoints with lines

BONUS - Does anyone know of a metric (preferably available in R) to estimate the volume of space a set of points takes up? In this case the set of space contained by the outer triangle.

EDIT - Bonus has already been answered in a different SO question here

Community
  • 1
  • 1
JHowIX
  • 1,683
  • 1
  • 20
  • 38
  • @JHowlX The bonus is really a separate question. It's interesting in its own right. Could you delete as a bonus and re-ask as a new question where it's less likely to be missed and conforms to the help center guidelines. – Tyler Rinker Oct 27 '14 at 22:49
  • 1
    @Tyler Rinker Great suggestion, I was worried the bonus was not really a SO programming question but more of a math problem BUT as I was taking you advice and writing it up in SO, I found the answer [here](http://stackoverflow.com/questions/3672260/area-covered-by-a-point-cloud-with-r). I haven't verified it works yet but certainly looks promising! – JHowIX Oct 27 '14 at 23:58

1 Answers1

9

You could always do a transformation to create all the segments you want to plot yourself

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))

which results in

enter image description here

MrFlick
  • 195,160
  • 17
  • 277
  • 295