当前位置:网站首页>K-Means Clustering Visualization in R: Step By Step Guide
K-Means Clustering Visualization in R: Step By Step Guide
2022-07-02 11:49:00 【Xiaoyu 2022】
library(ggpubr)
library(factoextra)
data("iris")
df <- iris
head(df, 3)
# Compute k-means with k = 3
set.seed(123)
res.km <- kmeans(scale(df[, -5]), 3, nstart = 25)
# K-means clusters showing the group of each individuals
res.km$cluster
fviz_cluster(res.km, data = df[, -5],
palette = c("#2E9FDF", "#00AFBB", "#E7B800"),
geom = "point",
ellipse.type = "convex",
ggtheme = theme_bw()
)

library(ggpubr)
library(factoextra)
data("iris")
df <- iris
head(df, 3)
# Compute k-means with k = 3
set.seed(123)
# Dimension reduction using PCA
res.pca <- prcomp(df[, -5], scale = TRUE)
# Coordinates of individuals
ind.coord <- as.data.frame(get_pca_ind(res.pca)$coord)
# Add clusters obtained using the K-means algorithm
ind.coord$cluster <- factor(res.km$cluster)
# Add Species groups from the original data sett
ind.coord$Species <- df$Species
# Data inspection
head(ind.coord)
# Percentage of variance explained by dimensions
eigenvalue <- round(get_eigenvalue(res.pca), 1)
variance.percent <- eigenvalue$variance.percent
head(eigenvalue)
ggscatter(
ind.coord, x = "Dim.1", y = "Dim.2",
color = "cluster", palette = "npg", ellipse = TRUE, ellipse.type = "convex",
shape = "Species", size = 1.5, legend = "right", ggtheme = theme_bw(),
xlab = paste0("Dim 1 (", variance.percent[1], "% )" ),
ylab = paste0("Dim 2 (", variance.percent[2], "% )" )
) +
stat_mean(aes(color = cluster), size = 4)
边栏推荐
- Cluster Analysis in R Simplified and Enhanced
- php 二维、多维 数组打乱顺序,PHP_php打乱数组二维数组多维数组的简单实例,php中的shuffle函数只能打乱一维
- Develop scalable contracts based on hardhat and openzeppelin (I)
- File operation (detailed!)
- 【2022 ACTF-wp】
- Seriation in R: How to Optimally Order Objects in a Data Matrice
- mysql链表数据存储查询排序问题
- vant tabs组件选中第一个下划线位置异常
- liftOver进行基因组坐标转换
- php 根据经纬度查询距离
猜你喜欢

PYQT5+openCV项目实战:微循环仪图片、视频记录和人工对比软件(附源码)

Attribute acquisition method and operation notes of C # multidimensional array

What is the relationship between digital transformation of manufacturing industry and lean production

Always report errors when connecting to MySQL database

How to Create a Nice Box and Whisker Plot in R

可昇級合約的原理-DelegateCall

BEAUTIFUL GGPLOT VENN DIAGRAM WITH R

Tiktok overseas tiktok: finalizing the final data security agreement with Biden government

GGPUBR: HOW TO ADD ADJUSTED P-VALUES TO A MULTI-PANEL GGPLOT

HOW TO ADD P-VALUES TO GGPLOT FACETS
随机推荐
数据分析 - matplotlib示例代码
Programmer growth Chapter 6: how to choose a company?
[idea] use the plug-in to reverse generate code with one click
Liftover for genome coordinate conversion
Flesh-dect (media 2021) -- a viewpoint of material decomposition
Tidb DM alarm DM_ sync_ process_ exists_ with_ Error troubleshooting
STM32 single chip microcomputer programming learning
揭露数据不一致的利器 —— 实时核对系统
[visual studio 2019] create MFC desktop program (install MFC development components | create MFC application | edit MFC application window | add click event for button | Modify button text | open appl
Precautions for scalable contract solution based on openzeppelin
Cluster Analysis in R Simplified and Enhanced
文件操作(详解!)
to_bytes与from_bytes简单示例
How to Create a Nice Box and Whisker Plot in R
A white hole formed by antineutrons produced by particle accelerators
MySQL linked list data storage query sorting problem
抖音海外版TikTok:正与拜登政府敲定最终数据安全协议
QT获取某个日期是第几周
动态内存(进阶四)
GGPUBR: HOW TO ADD ADJUSTED P-VALUES TO A MULTI-PANEL GGPLOT
