我正在尝试从如下数据创建结构图:
mydf <- data.frame ( group = rep (1:5, each = 20), z = rnorm (20, 10, 1),
x = c(rnorm (20, 2, 0.5), rnorm (20, 2, 0.5),
rnorm (20, 9, 0.5), rnorm (20, 9, 0.5),rnorm (20, 5, 0.5)),
y = c(rnorm (20, 2, 0.5), rnorm (20, 9, 0.5), rnorm (20, 2, 0.5),
rnorm (20, 9, 0.5), rnorm (20, 2, 0.5)))
means <- aggregate(. ~ group, data = mydf, mean)
gmx <-mean (mydf$x)
gmy <- mean (mydf$y)
library(ggplot2)
ggplot(mydf, aes(x, y)) +
geom_point(aes(colour= factor (group), size=z)) + theme_bw()
我想让每个集群中的每个点连接到它的中心,然后将集群中心连接到梯度平均值。这将产生如下图(只是两个集群连接到中心的粗略草图,实际上所有集群都具有相同的):............
(如果可能的话,我想使用与集群相同颜色的线段)