#Library

library(ggplot2)            
library(tidyverse) 
## Warning: package 'tidyverse' was built under R version 4.3.2
## Warning: package 'lubridate' was built under R version 4.3.2
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ dplyr     1.1.3     ✔ readr     2.1.4
## ✔ forcats   1.0.0     ✔ stringr   1.5.0
## ✔ lubridate 1.9.3     ✔ tibble    3.2.1
## ✔ purrr     1.0.2     ✔ tidyr     1.3.0
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag()    masks stats::lag()
## ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
library(ggspatial)
## Warning: package 'ggspatial' was built under R version 4.3.3
library(dplyr)
library(reshape2)
## 
## Attaching package: 'reshape2'
## 
## The following object is masked from 'package:tidyr':
## 
##     smiths
library(ggcorrplot)
## Warning: package 'ggcorrplot' was built under R version 4.3.3
library(ggforce)
## Warning: package 'ggforce' was built under R version 4.3.3
library(readxl)
library(gridExtra)
## 
## Attaching package: 'gridExtra'
## 
## The following object is masked from 'package:dplyr':
## 
##     combine
library(plotly)
## Warning: package 'plotly' was built under R version 4.3.2
## 
## Attaching package: 'plotly'
## 
## The following object is masked from 'package:ggplot2':
## 
##     last_plot
## 
## The following object is masked from 'package:stats':
## 
##     filter
## 
## The following object is masked from 'package:graphics':
## 
##     layout
library(rnaturalearth)
## Warning: package 'rnaturalearth' was built under R version 4.3.3
library(rnaturalearthdata)
## Warning: package 'rnaturalearthdata' was built under R version 4.3.3
## 
## Attaching package: 'rnaturalearthdata'
## 
## The following object is masked from 'package:rnaturalearth':
## 
##     countries110
library(sf)
## Warning: package 'sf' was built under R version 4.3.3
## Linking to GEOS 3.11.2, GDAL 3.8.2, PROJ 9.3.1; sf_use_s2() is TRUE

#Data

data <- read_excel("D:/tugas ngampus hampir gila/smt 4/visdut/data anrex.xlsx")
data[] <- lapply(data, as.numeric)
## Warning in lapply(data, as.numeric): NAs introduced by coercion
data <- subset(data, select = -c(Wilayah))
data
## # A tibble: 35 × 13
##       No     Y      X1    X2    X3    X4    X5    X6    X7     X8    X9   X10
##    <dbl> <dbl>   <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>  <dbl> <dbl> <dbl>
##  1     1  60.8 1047226  16.4  84.7  11.8  6.86 10226  69.1 380046 139.  14.9 
##  2     2  52.6 1828573  24.8  90.5  13.3  7.87 12492  73.9 479027 216.  12.5 
##  3     3  49.9  828883  21.3  86.3  12.2  7.07 10470  70.2 378858  70.0  8.92
##  4     4  64.3  901621  21.3  91.2  12.5  7.08 10541  70.6 425135  99.6 11.5 
##  5     5  45.6 1090129  24.2  92.4  12.7  8.09 13716  75.4 420339  97.5  9.81
##  6     6  62.5 2043077  18.0  87.3  12.4  6.4  10993  68.0 513339 286.  15.8 
##  7     7  45.5 2007829  50.7  88.6  12.7  7.39 11432  71.8 419429 191   11.0 
##  8     8  50.8 1240510  16.8  90.7  13.3  8.27 11166  74.1 511145 143.  12.0 
##  9     9  40.5 1492891  15.0  83.4  12.5  7.28 11083  71.5 464614 163.  11.7 
## 10    10  58.8 1221086  20.0  88.9  12.8  8.26 11306  73.8 479131  86.8  6.61
## # ℹ 25 more rows
## # ℹ 1 more variable: X11 <dbl>

#Correlation

##Correlation Scatterplot

plotkesatu <- ggplot(data, aes(x = X1, y = Y)) + 
  geom_point() +
  geom_smooth(method = "lm", se = FALSE) + 
  labs(x = "Jumlah Penduduk", y = "Skor IPLM")

plotkedua <- ggplot(data, aes(x = X2, y = Y)) + 
  geom_point() +
  geom_smooth(method = "lm", se = FALSE) + 
  labs(x = "PRDB Kapita", y = "Skor IPLM")

plotketiga <- ggplot(data, aes(x = X7, y = Y)) + 
  geom_point() +
  geom_smooth(method = "lm", se = FALSE) + 
  labs(x = "IPM", y = "Skor IPLM")

plotkeempat <- ggplot(data, aes(x = X11, y = Y)) + 
  geom_point() +
  geom_smooth(method = "lm", se = FALSE) + 
  labs(x = "Jumlah Perpustakaan", y = "Skor IPLM")

grid.arrange(plotkesatu, plotkedua, plotketiga, plotkeempat, nrow = 2)
## `geom_smooth()` using formula = 'y ~ x'
## `geom_smooth()` using formula = 'y ~ x'
## `geom_smooth()` using formula = 'y ~ x'
## `geom_smooth()` using formula = 'y ~ x'

Dari 4 scatter plot di atas, kita mendapatkan informasi bahwa jumlah penduduk miskin, PRDB kapita, dan jumlah perpustakaan menunjukkan hubungan linear positif yang menandakan bahwa semakin tinggi angka jumlah penduduk miskin, PRDB kapita, dan jumlah perpustakaan, maka nilai IPLM cenderung meningkat. Sebaliknya, jumlah penduduk menunjukkan hubungan linear negatif yang menandakan bahwa semakin sedikit jumlah penduduk , maka nilai IPLM menurun.

##Correlation HeatMap

datacorr <- select_if(data, is.numeric)
str(datacorr)
## tibble [35 × 13] (S3: tbl_df/tbl/data.frame)
##  $ No : num [1:35] 1 2 3 4 5 6 7 8 9 10 ...
##  $ Y  : num [1:35] 60.8 52.6 49.9 64.3 45.6 ...
##  $ X1 : num [1:35] 1047226 1828573 828883 901621 1090129 ...
##  $ X2 : num [1:35] 16.4 24.8 21.3 21.3 24.2 ...
##  $ X3 : num [1:35] 84.7 90.5 86.3 91.2 92.4 ...
##  $ X4 : num [1:35] 11.8 13.3 12.2 12.5 12.7 ...
##  $ X5 : num [1:35] 6.86 7.87 7.07 7.08 8.09 6.4 7.39 8.27 7.28 8.26 ...
##  $ X6 : num [1:35] 10226 12492 10470 10541 13716 ...
##  $ X7 : num [1:35] 69.1 73.9 70.2 70.6 75.4 ...
##  $ X8 : num [1:35] 380046 479027 378858 425135 420339 ...
##  $ X9 : num [1:35] 139 216.5 70 99.6 97.5 ...
##  $ X10: num [1:35] 14.9 12.53 8.92 11.49 9.81 ...
##  $ X11: num [1:35] 50 48 9 8 73 22 67 22 27 20 ...
data_melt <- cor(datacorr[sapply(datacorr,is.numeric)])

data_melt <- melt(data_melt) 

ggplot(data_melt, aes(x = Var1, y = Var2, fill = value)) +
  geom_tile() +
  labs(title = "Correlation Heatmap",
       x = " ",
       y = " ")

##Corellogram

ggplot(data_melt, aes(Var1, Var2, fill = value)) +
  geom_tile(color = "white") +
  scale_fill_gradient2(low = "cyan", mid = "green", high = "darkblue", midpoint = 0, limits = c(-1,1), name="Korelasi") +
  labs(title = "Corellogram") +
  theme_minimal() +
  theme(axis.text.x = element_text(angle = 45, vjust = 1, hjust=1))

datacorr1 <- round(cor(datacorr), 1)

datacorr1 <- cor(datacorr)
ggcorrplot(datacorr1, method = "circle")

Dari gambar-gambar di atas, dapat disimpulkan bahwa terdapat indikasi multikolinieritas antara beberapa variabel X, seperti antara harapan lama sekolah dan rata-rata lama sekolah. Korelasi yang cukup besar antara kedua variabel ini, yang ditunjukkan dengan warna yang lebih gelap atau lebih terang dalam plot, menandakan adanya hubungan yang signifikan di antara keduanya. Oleh karena itu, dapat disimpulkan bahwa harapan lama sekolah dan rata-rata lama sekolah saling mempengaruhi karena adanya korelasi yang signifikan.

#Time Series

datalagi <- read_csv("D:/tugas ngampus hampir gila/smt 4/visdut/BBNII.csv")
## Rows: 235 Columns: 8
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## dbl  (2): % Change, % Change vs Average
## num  (5): Open, High, Low, Close, Volume
## dttm (1): Date
## 
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
str(datalagi)
## spc_tbl_ [235 × 8] (S3: spec_tbl_df/tbl_df/tbl/data.frame)
##  $ Date               : POSIXct[1:235], format: "2023-05-14 17:00:00" "2023-05-15 17:00:00" ...
##  $ Open               : num [1:235] 4500 4475 4362 4400 4412 ...
##  $ High               : num [1:235] 4512 4488 4412 4450 4438 ...
##  $ Low                : num [1:235] 4425 4350 4325 4375 4388 ...
##  $ Close              : num [1:235] 4450 4375 4375 4412 4425 ...
##  $ % Change           : num [1:235] -1.11 -1.69 0 0.86 0.28 1.13 -1.4 1.98 -0.56 1.12 ...
##  $ % Change vs Average: num [1:235] -1.16 -1.74 -0.05 0.81 0.23 1.08 -1.45 1.93 -0.61 1.07 ...
##  $ Volume             : num [1:235] 7.82e+07 1.02e+08 1.02e+08 9.64e+07 8.85e+07 ...
##  - attr(*, "spec")=
##   .. cols(
##   ..   Date = col_datetime(format = ""),
##   ..   Open = col_number(),
##   ..   High = col_number(),
##   ..   Low = col_number(),
##   ..   Close = col_number(),
##   ..   `% Change` = col_double(),
##   ..   `% Change vs Average` = col_double(),
##   ..   Volume = col_number()
##   .. )
##  - attr(*, "problems")=<externalptr>
datalagi
## # A tibble: 235 × 8
##    Date                 Open  High   Low Close `% Change` `% Change vs Average`
##    <dttm>              <dbl> <dbl> <dbl> <dbl>      <dbl>                 <dbl>
##  1 2023-05-14 17:00:00 4500  4512. 4425  4450       -1.11                 -1.16
##  2 2023-05-15 17:00:00 4475  4488. 4350  4375       -1.69                 -1.74
##  3 2023-05-16 17:00:00 4362. 4412. 4325  4375        0                    -0.05
##  4 2023-05-18 17:00:00 4400  4450  4375  4412.       0.86                  0.81
##  5 2023-05-21 17:00:00 4412. 4438. 4388. 4425        0.28                  0.23
##  6 2023-05-22 17:00:00 4412. 4500  4412. 4475        1.13                  1.08
##  7 2023-05-23 17:00:00 4450  4475  4400  4412.      -1.4                  -1.45
##  8 2023-05-24 17:00:00 4412. 4512. 4400  4500        1.98                  1.93
##  9 2023-05-25 17:00:00 4500  4538. 4475  4475       -0.56                 -0.61
## 10 2023-05-28 17:00:00 4500  4525  4475  4525        1.12                  1.07
## # ℹ 225 more rows
## # ℹ 1 more variable: Volume <dbl>

##Point

datalagi <- head(datalagi, -1)
ggplot(datalagi, aes(x =Date, y = Open)) +
  geom_point() +
  labs(title = "Time series of BBNI in almost a year",
       x = "Date",
       y = "Open")

##Line

ggplot(datalagi, aes(x =Date, y = Open)) +
  geom_line() +
  labs(title = "Time series of BBNI in almost a year",
       x = "Date",
       y = "Value (open)")

calculate_moving_average <- function(datalagi, window_size) {
  ma_values <- zoo::rollmean(datalagi$Open, k = window_size, align = "right", fill = NA)
  ma_values_padded <- c(rep(NA, window_size - 1), ma_values)
  datalagi$ma <- ma_values_padded[1:nrow(datalagi)]
  return(datalagi)
}

window_size <- 3
datalagi <- calculate_moving_average(datalagi, window_size)

ggplot(datalagi, aes(x = Date)) +
  geom_line(aes(y = Open), color = "white", size = 1) +  
  geom_line(aes(y = ma), color = "red", linetype = "dashed", size = 1) +
  geom_ribbon(aes(ymin = -Inf, ymax = ma), fill = "red", alpha = 0.2) + 
  labs(title = paste("BBNI data with Moving Average (Window Size:", window_size, ")"),
       x = "Date",
       y = "Value (open)") +
  theme_minimal()
## Warning: Using `size` aesthetic for lines was deprecated in ggplot2 3.4.0.
## ℹ Please use `linewidth` instead.
## This warning is displayed once every 8 hours.
## Call `lifecycle::last_lifecycle_warnings()` to see where this warning was
## generated.
## Warning: Removed 4 rows containing missing values (`geom_line()`).

##Perbandingan Time Series

datatsp1 <- read_csv("D:/tugas ngampus hampir gila/smt 4/visdut/BBSAHAM.csv")
## Rows: 61 Columns: 8
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## dbl  (6): Open, High, Low, Close, % Change, % Change vs Average
## num  (1): Volume
## dttm (1): Date
## 
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
datatsp2 <- read_csv("D:/tugas ngampus hampir gila/smt 4/visdut/BABASAHAM.csv")
## Rows: 61 Columns: 8
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## dbl  (6): Open, High, Low, Close, % Change, % Change vs Average
## num  (1): Volume
## dttm (1): Date
## 
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
datatsp1
## # A tibble: 61 × 8
##    Date                 Open  High   Low Close `% Change` `% Change vs Average`
##    <dttm>              <dbl> <dbl> <dbl> <dbl>      <dbl>                 <dbl>
##  1 2023-03-19 17:00:00  80.7  3.9   3.59  3.84       3.23                  3.15
##  2 2023-03-26 17:00:00  85.4  4.7   3.8   4.56      18.8                  18.7 
##  3 2023-04-02 17:00:00 102.   4.69  4.45  4.55      -0.22                 -0.29
##  4 2023-04-09 17:00:00  98.3  4.64  4.38  4.51      -0.88                 -0.95
##  5 2023-04-16 17:00:00  98.8  4.54  4.18  4.23      -6.21                 -6.28
##  6 2023-04-23 17:00:00  92.2  4.22  3.83  3.91      -7.57                 -7.64
##  7 2023-04-30 17:00:00  85.6  4.75  3.85  4.69      20.0                  19.9 
##  8 2023-05-07 17:00:00 104.   5.37  4.73  5.01       6.82                  6.75
##  9 2023-05-14 17:00:00 110    5.51  4.97  5.38       7.39                  7.31
## 10 2023-05-21 17:00:00 118.   5.49  5.14  5.23      -2.79                 -2.86
## # ℹ 51 more rows
## # ℹ 1 more variable: Volume <dbl>
datatsp2
## # A tibble: 61 × 8
##    Date                 Open  High   Low Close `% Change` `% Change vs Average`
##    <dttm>              <dbl> <dbl> <dbl> <dbl>      <dbl>                 <dbl>
##  1 2023-03-19 17:00:00  80.2  88.4  79.5  86.9       6.4                   6.23
##  2 2023-03-26 17:00:00  87.1 105.   85.5 102.       17.6                  17.4 
##  3 2023-04-02 17:00:00 101.  103.   97.3 103.        0.55                  0.37
##  4 2023-04-09 17:00:00 101.  103.   93.6  94.6      -7.97                 -8.15
##  5 2023-04-16 17:00:00  96.7  99.2  88.3  89.1      -5.73                 -5.91
##  6 2023-04-23 17:00:00  88.4  88.5  82.2  84.7      -4.98                 -5.16
##  7 2023-04-30 17:00:00  84.2  85.3  80.5  83.2      -1.74                 -1.91
##  8 2023-05-07 17:00:00  83.6  88.5  80.2  85.3       2.55                  2.37
##  9 2023-05-14 17:00:00  87.1  91.4  83.5  84.0      -1.59                 -1.77
## 10 2023-05-21 17:00:00  85.7  87.5  78.1  81.0      -3.58                 -3.76
## # ℹ 51 more rows
## # ℹ 1 more variable: Volume <dbl>
datatsp1 <- head(datatsp1)
datatsp2 <- head(datatsp2)
# Memplot kedua seri waktu
ggplot() +
  geom_line(data = datatsp1, aes(x = Date, y = Open, color = "BB")) +
  geom_line(data = datatsp2, aes(x = Date, y = Open, color = "BABA")) +
  labs(title = "BB vs. BABA",
       x = "Date",
       y = "Value",
       color = "Series") +
  scale_color_manual(values = c("BB" = "darkblue", "BABA" = "red")) +
  theme_minimal()

Grafik-grafik tersebut menggambarkan pola kenaikan dan penurunan harga saham BB seiring waktu. Terlihat bahwa saham BB mengalami tren kenaikan dan mulai menurun di bulan Maret, sedangkan saham BABA mengalami tren kenaikan dan mulai menurun di bulan April. Di sisi lain, terlihat bahwa saham BB dan BABA mengalami peningkatan yang cukup konsisten pada awal tahun.

#Geospasial

world <- ne_countries(scale = "medium", returnclass = "sf")
ggplot(data = world) +
    geom_sf()

ggplot(data = world) +
    geom_sf(aes(fill = pop_est)) +
    scale_fill_viridis_c(option = "volcano")
## Warning in viridisLite::viridis(n, alpha, begin, end, direction, option):
## Option 'volcano' does not exist. Defaulting to 'viridis'.

spasial <- read.csv("C:/Users/Asus/Downloads/2019.csv")
spasial
##     Overall.rank        Country.or.region Score GDP.per.capita Social.support
## 1              1                  Finland 7.769          1.340          1.587
## 2              2                  Denmark 7.600          1.383          1.573
## 3              3                   Norway 7.554          1.488          1.582
## 4              4                  Iceland 7.494          1.380          1.624
## 5              5              Netherlands 7.488          1.396          1.522
## 6              6              Switzerland 7.480          1.452          1.526
## 7              7                   Sweden 7.343          1.387          1.487
## 8              8              New Zealand 7.307          1.303          1.557
## 9              9                   Canada 7.278          1.365          1.505
## 10            10                  Austria 7.246          1.376          1.475
## 11            11                Australia 7.228          1.372          1.548
## 12            12               Costa Rica 7.167          1.034          1.441
## 13            13                   Israel 7.139          1.276          1.455
## 14            14               Luxembourg 7.090          1.609          1.479
## 15            15           United Kingdom 7.054          1.333          1.538
## 16            16                  Ireland 7.021          1.499          1.553
## 17            17                  Germany 6.985          1.373          1.454
## 18            18                  Belgium 6.923          1.356          1.504
## 19            19            United States 6.892          1.433          1.457
## 20            20           Czech Republic 6.852          1.269          1.487
## 21            21     United Arab Emirates 6.825          1.503          1.310
## 22            22                    Malta 6.726          1.300          1.520
## 23            23                   Mexico 6.595          1.070          1.323
## 24            24                   France 6.592          1.324          1.472
## 25            25                   Taiwan 6.446          1.368          1.430
## 26            26                    Chile 6.444          1.159          1.369
## 27            27                Guatemala 6.436          0.800          1.269
## 28            28             Saudi Arabia 6.375          1.403          1.357
## 29            29                    Qatar 6.374          1.684          1.313
## 30            30                    Spain 6.354          1.286          1.484
## 31            31                   Panama 6.321          1.149          1.442
## 32            32                   Brazil 6.300          1.004          1.439
## 33            33                  Uruguay 6.293          1.124          1.465
## 34            34                Singapore 6.262          1.572          1.463
## 35            35              El Salvador 6.253          0.794          1.242
## 36            36                    Italy 6.223          1.294          1.488
## 37            37                  Bahrain 6.199          1.362          1.368
## 38            38                 Slovakia 6.198          1.246          1.504
## 39            39        Trinidad & Tobago 6.192          1.231          1.477
## 40            40                   Poland 6.182          1.206          1.438
## 41            41               Uzbekistan 6.174          0.745          1.529
## 42            42                Lithuania 6.149          1.238          1.515
## 43            43                 Colombia 6.125          0.985          1.410
## 44            44                 Slovenia 6.118          1.258          1.523
## 45            45                Nicaragua 6.105          0.694          1.325
## 46            46                   Kosovo 6.100          0.882          1.232
## 47            47                Argentina 6.086          1.092          1.432
## 48            48                  Romania 6.070          1.162          1.232
## 49            49                   Cyprus 6.046          1.263          1.223
## 50            50                  Ecuador 6.028          0.912          1.312
## 51            51                   Kuwait 6.021          1.500          1.319
## 52            52                 Thailand 6.008          1.050          1.409
## 53            53                   Latvia 5.940          1.187          1.465
## 54            54              South Korea 5.895          1.301          1.219
## 55            55                  Estonia 5.893          1.237          1.528
## 56            56                  Jamaica 5.890          0.831          1.478
## 57            57                Mauritius 5.888          1.120          1.402
## 58            58                    Japan 5.886          1.327          1.419
## 59            59                 Honduras 5.860          0.642          1.236
## 60            60               Kazakhstan 5.809          1.173          1.508
## 61            61                  Bolivia 5.779          0.776          1.209
## 62            62                  Hungary 5.758          1.201          1.410
## 63            63                 Paraguay 5.743          0.855          1.475
## 64            64          Northern Cyprus 5.718          1.263          1.252
## 65            65                     Peru 5.697          0.960          1.274
## 66            66                 Portugal 5.693          1.221          1.431
## 67            67                 Pakistan 5.653          0.677          0.886
## 68            68                   Russia 5.648          1.183          1.452
## 69            69              Philippines 5.631          0.807          1.293
## 70            70                   Serbia 5.603          1.004          1.383
## 71            71                  Moldova 5.529          0.685          1.328
## 72            72                    Libya 5.525          1.044          1.303
## 73            73               Montenegro 5.523          1.051          1.361
## 74            74               Tajikistan 5.467          0.493          1.098
## 75            75                  Croatia 5.432          1.155          1.266
## 76            76                Hong Kong 5.430          1.438          1.277
## 77            77       Dominican Republic 5.425          1.015          1.401
## 78            78   Bosnia and Herzegovina 5.386          0.945          1.212
## 79            79                   Turkey 5.373          1.183          1.360
## 80            80                 Malaysia 5.339          1.221          1.171
## 81            81                  Belarus 5.323          1.067          1.465
## 82            82                   Greece 5.287          1.181          1.156
## 83            83                 Mongolia 5.285          0.948          1.531
## 84            84          North Macedonia 5.274          0.983          1.294
## 85            85                  Nigeria 5.265          0.696          1.111
## 86            86               Kyrgyzstan 5.261          0.551          1.438
## 87            87             Turkmenistan 5.247          1.052          1.538
## 88            88                  Algeria 5.211          1.002          1.160
## 89            89                  Morocco 5.208          0.801          0.782
## 90            90               Azerbaijan 5.208          1.043          1.147
## 91            91                  Lebanon 5.197          0.987          1.224
## 92            92                Indonesia 5.192          0.931          1.203
## 93            93                    China 5.191          1.029          1.125
## 94            94                  Vietnam 5.175          0.741          1.346
## 95            95                   Bhutan 5.082          0.813          1.321
## 96            96                 Cameroon 5.044          0.549          0.910
## 97            97                 Bulgaria 5.011          1.092          1.513
## 98            98                    Ghana 4.996          0.611          0.868
## 99            99              Ivory Coast 4.944          0.569          0.808
## 100          100                    Nepal 4.913          0.446          1.226
## 101          101                   Jordan 4.906          0.837          1.225
## 102          102                    Benin 4.883          0.393          0.437
## 103          103      Congo (Brazzaville) 4.812          0.673          0.799
## 104          104                    Gabon 4.799          1.057          1.183
## 105          105                     Laos 4.796          0.764          1.030
## 106          106             South Africa 4.722          0.960          1.351
## 107          107                  Albania 4.719          0.947          0.848
## 108          108                Venezuela 4.707          0.960          1.427
## 109          109                 Cambodia 4.700          0.574          1.122
## 110          110  Palestinian Territories 4.696          0.657          1.247
## 111          111                  Senegal 4.681          0.450          1.134
## 112          112                  Somalia 4.668          0.000          0.698
## 113          113                  Namibia 4.639          0.879          1.313
## 114          114                    Niger 4.628          0.138          0.774
## 115          115             Burkina Faso 4.587          0.331          1.056
## 116          116                  Armenia 4.559          0.850          1.055
## 117          117                     Iran 4.548          1.100          0.842
## 118          118                   Guinea 4.534          0.380          0.829
## 119          119                  Georgia 4.519          0.886          0.666
## 120          120                   Gambia 4.516          0.308          0.939
## 121          121                    Kenya 4.509          0.512          0.983
## 122          122               Mauritania 4.490          0.570          1.167
## 123          123               Mozambique 4.466          0.204          0.986
## 124          124                  Tunisia 4.461          0.921          1.000
## 125          125               Bangladesh 4.456          0.562          0.928
## 126          126                     Iraq 4.437          1.043          0.980
## 127          127         Congo (Kinshasa) 4.418          0.094          1.125
## 128          128                     Mali 4.390          0.385          1.105
## 129          129             Sierra Leone 4.374          0.268          0.841
## 130          130                Sri Lanka 4.366          0.949          1.265
## 131          131                  Myanmar 4.360          0.710          1.181
## 132          132                     Chad 4.350          0.350          0.766
## 133          133                  Ukraine 4.332          0.820          1.390
## 134          134                 Ethiopia 4.286          0.336          1.033
## 135          135                Swaziland 4.212          0.811          1.149
## 136          136                   Uganda 4.189          0.332          1.069
## 137          137                    Egypt 4.166          0.913          1.039
## 138          138                   Zambia 4.107          0.578          1.058
## 139          139                     Togo 4.085          0.275          0.572
## 140          140                    India 4.015          0.755          0.765
## 141          141                  Liberia 3.975          0.073          0.922
## 142          142                  Comoros 3.973          0.274          0.757
## 143          143               Madagascar 3.933          0.274          0.916
## 144          144                  Lesotho 3.802          0.489          1.169
## 145          145                  Burundi 3.775          0.046          0.447
## 146          146                 Zimbabwe 3.663          0.366          1.114
## 147          147                    Haiti 3.597          0.323          0.688
## 148          148                 Botswana 3.488          1.041          1.145
## 149          149                    Syria 3.462          0.619          0.378
## 150          150                   Malawi 3.410          0.191          0.560
## 151          151                    Yemen 3.380          0.287          1.163
## 152          152                   Rwanda 3.334          0.359          0.711
## 153          153                 Tanzania 3.231          0.476          0.885
## 154          154              Afghanistan 3.203          0.350          0.517
## 155          155 Central African Republic 3.083          0.026          0.000
## 156          156              South Sudan 2.853          0.306          0.575
##     Healthy.life.expectancy Freedom.to.make.life.choices Generosity
## 1                     0.986                        0.596      0.153
## 2                     0.996                        0.592      0.252
## 3                     1.028                        0.603      0.271
## 4                     1.026                        0.591      0.354
## 5                     0.999                        0.557      0.322
## 6                     1.052                        0.572      0.263
## 7                     1.009                        0.574      0.267
## 8                     1.026                        0.585      0.330
## 9                     1.039                        0.584      0.285
## 10                    1.016                        0.532      0.244
## 11                    1.036                        0.557      0.332
## 12                    0.963                        0.558      0.144
## 13                    1.029                        0.371      0.261
## 14                    1.012                        0.526      0.194
## 15                    0.996                        0.450      0.348
## 16                    0.999                        0.516      0.298
## 17                    0.987                        0.495      0.261
## 18                    0.986                        0.473      0.160
## 19                    0.874                        0.454      0.280
## 20                    0.920                        0.457      0.046
## 21                    0.825                        0.598      0.262
## 22                    0.999                        0.564      0.375
## 23                    0.861                        0.433      0.074
## 24                    1.045                        0.436      0.111
## 25                    0.914                        0.351      0.242
## 26                    0.920                        0.357      0.187
## 27                    0.746                        0.535      0.175
## 28                    0.795                        0.439      0.080
## 29                    0.871                        0.555      0.220
## 30                    1.062                        0.362      0.153
## 31                    0.910                        0.516      0.109
## 32                    0.802                        0.390      0.099
## 33                    0.891                        0.523      0.127
## 34                    1.141                        0.556      0.271
## 35                    0.789                        0.430      0.093
## 36                    1.039                        0.231      0.158
## 37                    0.871                        0.536      0.255
## 38                    0.881                        0.334      0.121
## 39                    0.713                        0.489      0.185
## 40                    0.884                        0.483      0.117
## 41                    0.756                        0.631      0.322
## 42                    0.818                        0.291      0.043
## 43                    0.841                        0.470      0.099
## 44                    0.953                        0.564      0.144
## 45                    0.835                        0.435      0.200
## 46                    0.758                        0.489      0.262
## 47                    0.881                        0.471      0.066
## 48                    0.825                        0.462      0.083
## 49                    1.042                        0.406      0.190
## 50                    0.868                        0.498      0.126
## 51                    0.808                        0.493      0.142
## 52                    0.828                        0.557      0.359
## 53                    0.812                        0.264      0.075
## 54                    1.036                        0.159      0.175
## 55                    0.874                        0.495      0.103
## 56                    0.831                        0.490      0.107
## 57                    0.798                        0.498      0.215
## 58                    1.088                        0.445      0.069
## 59                    0.828                        0.507      0.246
## 60                    0.729                        0.410      0.146
## 61                    0.706                        0.511      0.137
## 62                    0.828                        0.199      0.081
## 63                    0.777                        0.514      0.184
## 64                    1.042                        0.417      0.191
## 65                    0.854                        0.455      0.083
## 66                    0.999                        0.508      0.047
## 67                    0.535                        0.313      0.220
## 68                    0.726                        0.334      0.082
## 69                    0.657                        0.558      0.117
## 70                    0.854                        0.282      0.137
## 71                    0.739                        0.245      0.181
## 72                    0.673                        0.416      0.133
## 73                    0.871                        0.197      0.142
## 74                    0.718                        0.389      0.230
## 75                    0.914                        0.296      0.119
## 76                    1.122                        0.440      0.258
## 77                    0.779                        0.497      0.113
## 78                    0.845                        0.212      0.263
## 79                    0.808                        0.195      0.083
## 80                    0.828                        0.508      0.260
## 81                    0.789                        0.235      0.094
## 82                    0.999                        0.067      0.000
## 83                    0.667                        0.317      0.235
## 84                    0.838                        0.345      0.185
## 85                    0.245                        0.426      0.215
## 86                    0.723                        0.508      0.300
## 87                    0.657                        0.394      0.244
## 88                    0.785                        0.086      0.073
## 89                    0.782                        0.418      0.036
## 90                    0.769                        0.351      0.035
## 91                    0.815                        0.216      0.166
## 92                    0.660                        0.491      0.498
## 93                    0.893                        0.521      0.058
## 94                    0.851                        0.543      0.147
## 95                    0.604                        0.457      0.370
## 96                    0.331                        0.381      0.187
## 97                    0.815                        0.311      0.081
## 98                    0.486                        0.381      0.245
## 99                    0.232                        0.352      0.154
## 100                   0.677                        0.439      0.285
## 101                   0.815                        0.383      0.110
## 102                   0.397                        0.349      0.175
## 103                   0.508                        0.372      0.105
## 104                   0.571                        0.295      0.043
## 105                   0.551                        0.547      0.266
## 106                   0.469                        0.389      0.130
## 107                   0.874                        0.383      0.178
## 108                   0.805                        0.154      0.064
## 109                   0.637                        0.609      0.232
## 110                   0.672                        0.225      0.103
## 111                   0.571                        0.292      0.153
## 112                   0.268                        0.559      0.243
## 113                   0.477                        0.401      0.070
## 114                   0.366                        0.318      0.188
## 115                   0.380                        0.255      0.177
## 116                   0.815                        0.283      0.095
## 117                   0.785                        0.305      0.270
## 118                   0.375                        0.332      0.207
## 119                   0.752                        0.346      0.043
## 120                   0.428                        0.382      0.269
## 121                   0.581                        0.431      0.372
## 122                   0.489                        0.066      0.106
## 123                   0.390                        0.494      0.197
## 124                   0.815                        0.167      0.059
## 125                   0.723                        0.527      0.166
## 126                   0.574                        0.241      0.148
## 127                   0.357                        0.269      0.212
## 128                   0.308                        0.327      0.153
## 129                   0.242                        0.309      0.252
## 130                   0.831                        0.470      0.244
## 131                   0.555                        0.525      0.566
## 132                   0.192                        0.174      0.198
## 133                   0.739                        0.178      0.187
## 134                   0.532                        0.344      0.209
## 135                   0.000                        0.313      0.074
## 136                   0.443                        0.356      0.252
## 137                   0.644                        0.241      0.076
## 138                   0.426                        0.431      0.247
## 139                   0.410                        0.293      0.177
## 140                   0.588                        0.498      0.200
## 141                   0.443                        0.370      0.233
## 142                   0.505                        0.142      0.275
## 143                   0.555                        0.148      0.169
## 144                   0.168                        0.359      0.107
## 145                   0.380                        0.220      0.176
## 146                   0.433                        0.361      0.151
## 147                   0.449                        0.026      0.419
## 148                   0.538                        0.455      0.025
## 149                   0.440                        0.013      0.331
## 150                   0.495                        0.443      0.218
## 151                   0.463                        0.143      0.108
## 152                   0.614                        0.555      0.217
## 153                   0.499                        0.417      0.276
## 154                   0.361                        0.000      0.158
## 155                   0.105                        0.225      0.235
## 156                   0.295                        0.010      0.202
##     Perceptions.of.corruption
## 1                       0.393
## 2                       0.410
## 3                       0.341
## 4                       0.118
## 5                       0.298
## 6                       0.343
## 7                       0.373
## 8                       0.380
## 9                       0.308
## 10                      0.226
## 11                      0.290
## 12                      0.093
## 13                      0.082
## 14                      0.316
## 15                      0.278
## 16                      0.310
## 17                      0.265
## 18                      0.210
## 19                      0.128
## 20                      0.036
## 21                      0.182
## 22                      0.151
## 23                      0.073
## 24                      0.183
## 25                      0.097
## 26                      0.056
## 27                      0.078
## 28                      0.132
## 29                      0.167
## 30                      0.079
## 31                      0.054
## 32                      0.086
## 33                      0.150
## 34                      0.453
## 35                      0.074
## 36                      0.030
## 37                      0.110
## 38                      0.014
## 39                      0.016
## 40                      0.050
## 41                      0.240
## 42                      0.042
## 43                      0.034
## 44                      0.057
## 45                      0.127
## 46                      0.006
## 47                      0.050
## 48                      0.005
## 49                      0.041
## 50                      0.087
## 51                      0.097
## 52                      0.028
## 53                      0.064
## 54                      0.056
## 55                      0.161
## 56                      0.028
## 57                      0.060
## 58                      0.140
## 59                      0.078
## 60                      0.096
## 61                      0.064
## 62                      0.020
## 63                      0.080
## 64                      0.162
## 65                      0.027
## 66                      0.025
## 67                      0.098
## 68                      0.031
## 69                      0.107
## 70                      0.039
## 71                      0.000
## 72                      0.152
## 73                      0.080
## 74                      0.144
## 75                      0.022
## 76                      0.287
## 77                      0.101
## 78                      0.006
## 79                      0.106
## 80                      0.024
## 81                      0.142
## 82                      0.034
## 83                      0.038
## 84                      0.034
## 85                      0.041
## 86                      0.023
## 87                      0.028
## 88                      0.114
## 89                      0.076
## 90                      0.182
## 91                      0.027
## 92                      0.028
## 93                      0.100
## 94                      0.073
## 95                      0.167
## 96                      0.037
## 97                      0.004
## 98                      0.040
## 99                      0.090
## 100                     0.089
## 101                     0.130
## 102                     0.082
## 103                     0.093
## 104                     0.055
## 105                     0.164
## 106                     0.055
## 107                     0.027
## 108                     0.047
## 109                     0.062
## 110                     0.066
## 111                     0.072
## 112                     0.270
## 113                     0.056
## 114                     0.102
## 115                     0.113
## 116                     0.064
## 117                     0.125
## 118                     0.086
## 119                     0.164
## 120                     0.167
## 121                     0.053
## 122                     0.088
## 123                     0.138
## 124                     0.055
## 125                     0.143
## 126                     0.089
## 127                     0.053
## 128                     0.052
## 129                     0.045
## 130                     0.047
## 131                     0.172
## 132                     0.078
## 133                     0.010
## 134                     0.100
## 135                     0.135
## 136                     0.060
## 137                     0.067
## 138                     0.087
## 139                     0.085
## 140                     0.085
## 141                     0.033
## 142                     0.078
## 143                     0.041
## 144                     0.093
## 145                     0.180
## 146                     0.089
## 147                     0.110
## 148                     0.100
## 149                     0.141
## 150                     0.089
## 151                     0.077
## 152                     0.411
## 153                     0.147
## 154                     0.025
## 155                     0.035
## 156                     0.091
world_map <- map_data("world")
colnames(spasial)[colnames(spasial) == "Country.Territory"] <- "region"
merged_data <- left_join(world_map, spasial, by = c("region" = "Country.or.region"))
ggplot(merged_data, aes(x = long, y = lat, group = group, fill = Healthy.life.expectancy)) +
  geom_polygon(color = "darkgreen") +
  scale_fill_gradient(name = "Population (2019)", low = "blue", high = "black", guide = "legend") +
  theme_void() +
  labs(title = "Social.support 2019")

Kumpulan map chart yang disajikan di atas, terlihat distribusi populasi global pada tahun 2022. Warna biru kehitaman menunjukkan negara-negara dengan populasi yang tinggi, sementara warna biru muda menandakan populasi yang lebih rendah. Dari peta tersebut, terlihat dengan jelas bahwa China dan India memiliki populasi yang sangat besar.