R 查看群集对象的名称
我有一个城市的数据样本,我正在为一些参数对它们进行聚类。但我在直观地表示它们时遇到了困难,首先使用了clusplot,但我不理解为什么比例会发生变化,因为即使仅使用2个组件和范围为-1到1的数据进行绘制,其范围也在-4到4和-2到2之间,如您在示例中所见 [ 所以我使用了hullplot DBSCAN包,但是这个图在你的输出中没有显示城市的名称,如clusplot,请看。有人能给我一个如何将这些名称添加到图表中的建议吗R 查看群集对象的名称,r,k-means,dbscan,R,K Means,Dbscan,我有一个城市的数据样本,我正在为一些参数对它们进行聚类。但我在直观地表示它们时遇到了困难,首先使用了clusplot,但我不理解为什么比例会发生变化,因为即使仅使用2个组件和范围为-1到1的数据进行绘制,其范围也在-4到4和-2到2之间,如您在示例中所见 [ 所以我使用了hullplot DBSCAN包,但是这个图在你的输出中没有显示城市的名称,如clusplot,请看。有人能给我一个如何将这些名称添加到图表中的建议吗 我会尝试使用ggplot2和ggrepel包来实现这一点。我借用了代码来制作
我会尝试使用ggplot2和ggrepel包来实现这一点。我借用了代码来制作凸面外壳
set.seed(175)
图书馆(GG2)
库(ggrepel)#或首次安装.packages(“ggrepel”)
#制造集群
mtcars$cluster以下是一些使用dbscan执行此操作的示例:
library(dbscan)
set.seed(2)
n <- 400
x <- cbind(
x = runif(4, 0, 1) + rnorm(n, sd=0.1),
y = runif(4, 0, 1) + rnorm(n, sd=0.1),
z = runif(4, 0, 1) + rnorm(n, sd=0.1)
)
cl <- rep(1:4, time = 100)
### show some points (first 10) inside the hulls with text
hullplot(x, cl, main = "True clusters", pch = NA)
points(x[1:10,])
text(x[1:10,], labels = paste("Obs.", 1:10), pos = 3)
### look at dimensions x and z
hullplot(x[, c("x", "z")], cl, main = "True clusters")
### use a PCA projection
hullplot(prcomp(x)$x, cl, main = "True clusters")
库(dbscan)
种子(2)
n请添加创建绘图的代码谢谢,你真的帮了我很大的忙!如果你知道任何解释clusplot如何工作的参考资料,我将非常感激,因为对于我所寻求的,他是唯一一个可以使用两个以上参数绘制聚类的人,或者它只使用两个最重要的参数,运行类似selec的东西变量的分类?PCA?!
library(dbscan)
set.seed(2)
n <- 400
x <- cbind(
x = runif(4, 0, 1) + rnorm(n, sd=0.1),
y = runif(4, 0, 1) + rnorm(n, sd=0.1),
z = runif(4, 0, 1) + rnorm(n, sd=0.1)
)
cl <- rep(1:4, time = 100)
### show some points (first 10) inside the hulls with text
hullplot(x, cl, main = "True clusters", pch = NA)
points(x[1:10,])
text(x[1:10,], labels = paste("Obs.", 1:10), pos = 3)
### look at dimensions x and z
hullplot(x[, c("x", "z")], cl, main = "True clusters")
### use a PCA projection
hullplot(prcomp(x)$x, cl, main = "True clusters")