raw<-read.table("G:\\My Drive\\document for each subject\\senior_project\\67\\ploy_sp.csv", header=TRUE, sep = ",")cluster_Ploy_data_way02
นำเข้าข้อมูล
เปิดใช้งาน package
library(vegan)Warning: package 'vegan' was built under R version 4.4.2
Loading required package: permute
Loading required package: lattice
This is vegan 2.6-8
ดึงเฉพาะข้อมูลที่ไม่เป็น 0 ทั้ง row
sp<-raw[c(1:12, 14:18), 2:ncol(raw)]หาระยะห่างของแต่ละแปลงโดยใช้ข้อมูลชนิดและจำนวนพืชที่พบในแต่ละแปลง
sp_dist<-vegdist(sp)
sp_clus<-hclust(sp_dist)ลอง Plot แบบธรรมดาดูก่อน
plot(sp_clus)เตรียมการแบ่งข้อมูลออกเป็น 3 กลุ่ม
sp_cutree <-cutree(sp_clus, k = 3)Plot แบบแบ่งข้อมูลออกเป็น 3 กลุ่ม
plot (sp_clus, cex = .5)
clus_in_dendro <- unique (sp_cutree[sp_clus$order])
rect.hclust (sp_clus, k = 3, border = c("#A5B68D", "#789DBC", "#BC7C7C"))#legend ('topright', legend = paste ('Cluster', 1:3), col = c("#A5B68D", "#789DBC", "#BC7C7C"), pch = 22, bty = 'n')