当前位置:网站首页>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)
边栏推荐
- How to Create a Nice Box and Whisker Plot in R
- Some suggestions for young people who are about to enter the workplace in the graduation season
- 文件操作(详解!)
- ESP32音频框架 ESP-ADF 添加按键外设流程代码跟踪
- Power Spectral Density Estimates Using FFT---MATLAB
- MySQL linked list data storage query sorting problem
- [multithreading] the main thread waits for the sub thread to finish executing, and records the way to execute and obtain the execution result (with annotated code and no pit)
- Thesis translation: 2022_ PACDNN: A phase-aware composite deep neural network for speech enhancement
- php 根据经纬度查询距离
- HOW TO ADD P-VALUES TO GGPLOT FACETS
猜你喜欢
MySQL比较运算符IN问题求解
vant tabs组件选中第一个下划线位置异常
Data analysis - Matplotlib sample code
GGPLOT: HOW TO DISPLAY THE LAST VALUE OF EACH LINE AS LABEL
PYQT5+openCV项目实战:微循环仪图片、视频记录和人工对比软件(附源码)
YYGH-BUG-05
TDSQL|就业难?腾讯云数据库微认证来帮你
pgsql 字符串转数组关联其他表,匹配 拼接后原顺序展示
HOW TO ADD P-VALUES ONTO A GROUPED GGPLOT USING THE GGPUBR R PACKAGE
Never forget, there will be echoes | hanging mirror sincerely invites you to participate in the opensca user award research
随机推荐
flutter 问题总结
由粒子加速器产生的反中子形成的白洞
ROS lacks catkin_ pkg
ESP32音频框架 ESP-ADF 添加按键外设流程代码跟踪
Basic usage of MySQL in centos8
easyExcel和lombok注解以及swagger常用注解
可昇級合約的原理-DelegateCall
Homer预测motif
C#基于当前时间,获取唯一识别号(ID)的方法
念念不忘,必有回响 | 悬镜诚邀您参与OpenSCA用户有奖调研
Digital transformation takes the lead to resume production and work, and online and offline full integration rebuilds business logic
Cluster Analysis in R Simplified and Enhanced
基于Hardhat和Openzeppelin开发可升级合约(二)
deepTools对ChIP-seq数据可视化
Precautions for scalable contract solution based on openzeppelin
A sharp tool for exposing data inconsistencies -- a real-time verification system
HOW TO EASILY CREATE BARPLOTS WITH ERROR BARS IN R
亚马逊云科技 Community Builder 申请窗口开启
Native method merge word
Flesh-dect (media 2021) -- a viewpoint of material decomposition