在点之间画所有线 [英] Draw All Lines Between Points

查看:37
本文介绍了在点之间画所有线的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下R代码

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)

它将创建以下图形:

我想以可重复的方式在这些点之间绘制所有可能的线,即,点的数量,位置等可能会改变.有谁知道R函数可以做这样的事情.标准的+ geom_point()仅在x轴上的后续点之间绘制线.我的理想输出如下所示.预先感谢.

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.

奖金-有人知道度量标准(最好在R中可用)来估计一组点占用的空间量吗?在这种情况下,外部三角形包含的空间集.

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.

编辑-在另一个SO问题

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

推荐答案

您始终可以进行转换以创建要绘制的所有线段

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

这将导致

这篇关于在点之间画所有线的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆