bind_cols(
Data,
dist(Data %>% select(-Group)) %>% # Get x/y coordinates from Data
as.matrix() %>% # Convert to full matrix
as.data.frame() %>% # Convert to data.frame
select(1:3) %>% # We're only interested in dist to 1,2,3
rowid_to_column("pt") %>%
gather(k, v, -pt) %>%
group_by(pt) %>%
summarise(k = k[which.min(v)])) %>% # Select label with min dist
mutate(Group = factor(Group, levels = unique(Data$Group))) %>%
ggplot(aes(x, y, colour = k, shape = Group)) +
geom_point(size = 3)
dist
之间
One
,
Two
,
Three
Scatter
分散
指向标签
k
(
k = 1
),
两个
(
k = 2
),
三
(
k = 3
分散
两个
(
k=2个
); 您可以通过添加
coord_fixed()
在
ggplot
情节链。