简体   繁体   English

用R中的线连接一组点

[英]connecting a set of points with lines in R

At present, I generate a figure using the following script 目前,我使用以下脚本生成一个数字

 dat <- matrix(runif(1000*99),99,1000)
 dat <- rbind(rep(0.1,1000),dat)
 out <- cmdscale(dist(dat),k = 2)
 plot(out)
 points(out[1,1],out[1,2],col = "red")

在此输入图像描述

Based on the above figure, I want to connect that red point with other points, how to do that? 基于上图,我想将红点与其他点联系起来,怎么做?

If you want to connect all the points to that red point, you could try... 如果你想将所有点连接到那个红点,你可以尝试......

segments(out[1,1],out[1,2],out[,1],out[,2])

在此输入图像描述

Adjusting the order of the printing and the graphical characteristics could make it a little easier to look at too: 调整打印顺序和图形特征也可以使其更容易查看:

dat <- matrix(runif(1000*99),99,1000)
dat <- rbind(rep(0.1,1000),dat)
out <- cmdscale(dist(dat),k = 2)
plot(out,type="n")
segments(out[1,1],out[1,2],out[,1],out[,2],col="#cccccc")
points(out,col="black",pch=20)
points(out[1,1],out[1,2],col = "red",pch=20)

在此输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM