library(e1071)
data<-read.csv("E:/Data1.csv")
data
##    Jumlah.Pesantren Penduduk.Muslim Penduduk.NonMuslim Jumlah.Masjid.Mushola
## 1                 4           66660               7056                   122
## 2                 0           57273              11234                    90
## 3                 1           50239               9352                    60
## 4                 0           67930              11455                   148
## 5                 0           52517              19916                    76
## 6                 2          109467              20967                   197
## 7                 0           41074              21780                   102
## 8                 1               0              26328                   193
## 9                 1          110334               4724                    80
## 10               20          164106              28318                   336
## 11                9           32381                927                    66
## 12                2           91102               3245                   364
## 13               17          162656              17844                   165
## 14                0           70484               4212                   219
## 15                3          120447              19972                   241
## 16               11          128846               6140                   153
##    Kepadatan.Penduduk
## 1               13443
## 2               11896
## 3                6690
## 4               11752
## 5                9839
## 6               10907
## 7                9951
## 8                7592
## 9                4345
## 10              10361
## 11               1049
## 12               2195
## 13               4740
## 14               1321
## 15               6421
## 16               4348
cm <- cmeans(data, 2)
cm
## Fuzzy c-means clustering with 2 clusters
## 
## Cluster centers:
##   Jumlah.Pesantren Penduduk.Muslim Penduduk.NonMuslim Jumlah.Masjid.Mushola
## 1         8.691445       130038.46           15603.43              204.1465
## 2         1.693615        50957.68           12177.98              122.5267
##   Kepadatan.Penduduk
## 1           6535.675
## 2           8110.609
## 
## Memberships:
##                 1          2
##  [1,] 0.067862783 0.93213722
##  [2,] 0.010208799 0.98979120
##  [3,] 0.001639974 0.99836003
##  [4,] 0.071803598 0.92819640
##  [5,] 0.010696862 0.98930314
##  [6,] 0.881627193 0.11837281
##  [7,] 0.023691929 0.97630807
##  [8,] 0.141105662 0.85889434
##  [9,] 0.875462447 0.12453755
## [10,] 0.907191793 0.09280821
## [11,] 0.050615756 0.94938424
## [12,] 0.505678143 0.49432186
## [13,] 0.921119813 0.07888019
## [14,] 0.117019450 0.88298055
## [15,] 0.977796420 0.02220358
## [16,] 0.984585945 0.01541405
## 
## Closest hard clustering:
##  [1] 2 2 2 2 2 1 2 2 1 1 2 1 1 2 1 1
## 
## Available components:
## [1] "centers"     "size"        "cluster"     "membership"  "iter"       
## [6] "withinerror" "call"
head(cm$membership)
##                1         2
## [1,] 0.067862783 0.9321372
## [2,] 0.010208799 0.9897912
## [3,] 0.001639974 0.9983600
## [4,] 0.071803598 0.9281964
## [5,] 0.010696862 0.9893031
## [6,] 0.881627193 0.1183728
# Visualize using corrplot
library(corrplot)
## corrplot 0.84 loaded
corrplot(cm$membership, is.corr = FALSE)
library(factoextra)
## Loading required package: ggplot2
## Welcome! Want to learn more? See two factoextra-related books at https://goo.gl/ve3WBa

fviz_cluster(list(data = data, cluster=cm$cluster), 
             ellipse.type = "norm",
             ellipse.level = 0.68,
             palette = "jco",
             ggtheme = theme_minimal())