In ggplot you can use geom_segmentto draw connecting lines.
But first you need to build a data frame with the coordinates of each trunk. Use combn()to find all combinations:
comb <- combn(nrow(myd), 2)
connections <- data.frame(
from = myd[comb[1, ], 1:2],
to = myd[comb[2, ], 1:3]
)
names(connections) <- c("x1", "y1", "x2", "y2", "label")
Then the plot:
library(ggplot2)
ggplot(myd, aes(PC1, PC2)) +
geom_point(col="red", size=5) +
geom_segment(data=connections, aes(x=x1, y=y1, xend=x2, yend=y2), col="blue")

source
share