簡體   English   中英

連接R中2個不同數據集中的點

[英]connecting dots in 2 different data sets in R

我有2個數據集(DSA和DSB)包含x和y坐標

tumor<- data.frame(DSA[,c("X_Parameter","Y_Parameter")])
cells<-data.frame(DSB[,c ("X_Parameter","Y_Parameter")])
plot(cells, xlim=c(1,1300), ylim=c(1,1000), col="red")
par(new=TRUE)
plot(tumor, xlim=c(1,1300), ylim=c(1,1000), col="blue")

情節使這張圖 在此處輸入圖片說明

我希望能夠從每個紅點到每個藍點畫一條連接線。 有誰知道這是否可以做到。 謝謝

樣本DSA =(5,5 6,6 5,6 6,5)DSB =(1,1 10,10 10,1 1,10)圖應該是什么樣 在此處輸入圖片說明

蠻力,也許優雅:

DSA <- data.frame(x = c(5, 6, 5, 6),
                  y = c(5, 6, 6, 5))
DSB <- data.frame(x = c(1, 10, 10, 1),
                  y = c(1, 10, 1, 10))

plot(y ~ x, DSB, col = "red")
points(DSA, col = "blue")
for (r in seq_len(nrow(DSA))) {
  segments(DSA$x[r], DSA$y[r], DSB$x, DSB$y)
}

蠻力段

編輯:更直接地:

nA <- nrow(DSA)
nB <- nrow(DSB)
plot(y ~ x, DSB, col = "red")
points(DSA, col = "blue")
segments(rep(DSA$x, each = nB),  rep(DSA$y, each = nB),
         rep(DSB$x, times = nA), rep(DSB$y, times = nA))

(我仍然不能找出與@ 42的建議,對於一個優雅溶液combnouter )。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM