0

Recently I conducted clustering analysis in R and got this table

        label     data     PC1     PC2     PC3
1              1 5240 64.5116 12.9746 20.8370
2              2  878 88.7790 45.3952  5.0866
3              3 3368 74.5229 14.2346 43.8447
4              4 3198 38.3777 71.6273 61.5600
5              5 3960 91.8364 38.5808 90.5126
6              6 3060 81.6686 16.1163 71.7114
7              7 6627 14.1615 72.2929 47.6329
8              8 7154 51.7948  7.2599  5.4532
9              9 5408  5.1925 96.2049 73.5915
10            10 6649 33.8615 33.0504 18.8785
11            11  946 95.4989 87.7632  3.4894
12            12 6648 19.4012 60.3144 38.1420
13            13 4657 57.8675 31.4108 28.7580
14            14 3960 72.7626 36.8543 52.3389
15            15 3811 64.1441 58.1824 61.3217
16            16 3667 93.2833  9.2812 94.4377
17            17 7120 41.8886 19.8525 10.9709
18            18 4008 46.3114 51.1215 43.8303
19            19 6588 26.2215 46.7526 28.4874
20            20 5035 89.7023 90.2512 92.8365
21            21 3199 30.6296 89.1616 76.2088
22            22 4402 78.2135 50.6542 76.3119
23            23 5463 89.9995 67.8642 90.2405
24            24 7251  8.4030 85.1949 60.1072
25            25 5266 66.3528 83.8562 81.1253

In the table, there are information about 25 clusters, containing label of cluster(label), number of data belongs to each cluster(data), cluster centroid coordinates of 1st variable(PC1), cluster centroid coordinates of 2nd variable(PC2), cluster centroid coordinates of 3rd variable(PC3).

I plotted the data on the 3d table, using 'plot3d' and 'scatterplot3d', and now want to plot 'label' and 'data' of each cluster in the table additionally. This is my current code that visualizing data clusters with distinguished by colors.

library(plot3D)
plot3d(data = clustered_results, size = 5, col = kmeans_clustered$cluster) + 
  text3d(x = center_kmeans$PC1, y = center_kmeans$PC2, z = center_kmeans$PC3, 
        family = c('serif'), cex = 2, pos = 7)

But I have no idea how to do that. How can I plot the figures in 'label', 'data' column on the centroid point using coordinates of each axis(PC1, PC2, PC3)?

Isaiah
  • 2,091
  • 3
  • 19
  • 28
hogu
  • 1
  • 3
  • [Impressive package for 3D and 4D graph - R software and data visualization](http://www.sthda.com/english/wiki/impressive-package-for-3d-and-4d-graph-r-software-and-data-visualization) gives an example: `# Create a scatter plot scatter3D(x, y, z, phi = 0, bty = "g", pch = 20, cex = 0.5) # Add text text3D(x, y, z, labels = rownames(iris), add = TRUE, colkey = FALSE, cex = 0.5)` Did you try labels = label? – Isaiah Oct 06 '22 at 07:49

0 Answers0