k means - Get clusters from PCA r -


i have pca shows 2 big clusters , dont know how figure out of samples in each cluster.

enter image description here

if helps, im using prcomp generate pca:

pca1 <- autoplot(prcomp(df), label = true, label.size = 2) 

my approach has been attempt cluster pca output using kmeans 2 groups clusters:

pca   <- prcomp(df, scale.=true) clust <- kmeans(pca$x[,1:2], centers=2)$cluster 

i can make beautiful plot, still lost samples in each cluster. reference, here plot generate if graph kmeans output:

enter image description here

as can see in first pca plot, labels literally sample each dot is. ideal output 2 column txt file sample name in 1 column, , group belongs in other column.

all aside, if there better way, please let me know.

thanks in advance.

here chunk of data:

                     b       c       b      e sample_1013 312011  624559  625898  534309  220415  sample_1046 474774  949458  951145  843049  366136  sample_104  645363  1290450 1292520 919474  272200  sample_1057 267319  534685  535294  690574  422645  sample_106  414065  830571  834527  657354  234130  sample_107  299289  602483  603756  566256  262153 

in question, clust name of output kmeans:

clust <- kmeans(pca$x[,1:2], centers=2)$cluster 

i typed clust terminal , got samples belong each group:

> clust sample_1013     sample_1046      sample_104     sample_1057      sample_106      sample_107            1               1               1               1               1               1  sample_1098      sample_109     sample_1109     sample_1129     sample_1130     sample_1140            1               1               1               1               1               1  sample_1149      sample_115      sample_118     sample_1220     sample_1223     sample_1225            1               1               1               1               1               1  

hopefully helps someone.


Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -