-
Notifications
You must be signed in to change notification settings - Fork 0
/
clusterviz.R
33 lines (28 loc) · 1.1 KB
/
clusterviz.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
library(ggplot2)
library(sf)
library(dplyr)
library(readxl)
library(RColorBrewer)
library(viridis)
# Read the shapefile
indo_sf <- st_read("E:/GitHub/sherlock-final-project/map_cluster/indo_province_map.shp")
print(head(indo_sf))
print(indo_sf)
# Read the cluster data from the Excel file
cluster_data <- read_excel("E:/GitHub/sherlock-final-project/cluster_summary.xlsx", sheet='Sheet1')
cluster_data$kmedoids <- cluster_data$kmedoids +1
# Merge the shapefile data with the cluster data
merged_data <- indo_sf %>%
left_join(cluster_data, by = c("PROVINSI" = "province"))
# Visualize with ggplot2 using viridis color palette
ggplot(data = merged_data) +
geom_sf(aes(fill = factor(kmeans))) +
scale_fill_viridis_d(option = "viridis", name = "kmeans") +
theme_minimal() +
labs(title = "Klaster Tingkat Kemiskinan Indonesia - K-means")
# Visualize with ggplot2 using viridis color palette
ggplot(data = merged_data) +
geom_sf(aes(fill = factor(kmedoids))) +
scale_fill_viridis_d(option = "viridis", name = "kmedoids") +
theme_minimal() +
labs(title = "Klaster Tingkat Kemiskinan Indonesia - K-medoids")