[英]Adding points to Scatter plot Matrix
I want to add points to my Scatter plot matrix. 我想在散点图矩阵中添加点。
head(pca)
pc1 pc2 pc3 pc4
[1,] 0.72859559 -2.2864943 -0.5408501 0.1564730
[2,] 0.34852943 0.3100891 0.6007349 -0.5985266
[3,] -0.04605026 0.5067896 -0.2911211 -1.1617171
[4,] -1.88358617 1.3739440 -0.5655383 0.9518367
[5,] 0.35528650 -1.7482304 -0.3871520 -0.7837712
I ran kmeans to my PCA data and I can plot a scatter plot matrix by using the following: 我对我的PCA数据进行了kmeans运算,可以使用以下命令绘制散点图矩阵:
k <- kmeans(pca,3)
plot(pca, col=k$clust, pch=16)
Next I want to add X's to show the centers by adding 接下来,我想添加X以通过添加来显示中心
+ points(k$centers, col=1:3 ,pch="X", cex=3)
but its doesn't work. 但它不起作用。 If I reduce to only 2 PCs then the following plots the centers but only for 2 pcs:
如果我减少到只有2台PC,则以下将绘制中心,但仅绘制2台:
plot(pca[,c(1,2)], col=k$clust, pch=16) + points(k$centers, col=1:10 ,pch="X", cex=3)
side note when I enter the code above R returns "numeric(0)". 旁注,当我输入上面的代码时,R返回“数字(0)”。 What does that mean?
这意味着什么?
> plot(pca[,c(1,2)], col=k$clust, pch=16) + points(k$centers, col=1:10 ,pch="X", cex=3)
> numeric(0)
the following has been helpful to some degree. 以下内容在一定程度上有所帮助。 Kmeans clustering identifying knowledge in R
Kmeans聚类识别R中的知识
I'm not sure what you mean by "It's not working". 我不确定“不起作用”是什么意思。 This works fine for me:
这对我来说很好:
# parameters
rows <- 100
cols <- 4
groups <- 3
# create a matrix of uniforms
pca <- matrix(runif(rows*cols),ncol = cols,byrow=TRUE)
colnames(pca) <- paste0('pc',seq(cols))
# calculate the kmeans
(k <- kmeans(pca,groups))
# plot the data and the means
plot(pca, col=k$clust, pch=15)
points(k$centers, col=seq(groups),pch="X", cex=3)
note that you're only going to get a voronoi tessellation in a 2-d plot when the number of columns ( cols
) in your matrix is 2. 请注意,当矩阵中的列数(
cols
)为2时,只会在二维绘图中获得voronoi镶嵌。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.