library(tidyverse) #Include beberapa packages termasuk ggplot
## Warning: package 'tidyverse' was built under R version 4.3.2
## Warning: package 'ggplot2' was built under R version 4.3.3
## Warning: package 'tidyr' was built under R version 4.3.3
## Warning: package 'stringr' was built under R version 4.3.3
## 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.1
## ✔ ggplot2   3.5.0     ✔ tibble    3.2.1
## ✔ lubridate 1.9.3     ✔ tidyr     1.3.1
## ✔ purrr     1.0.2     
## ── 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(dplyr)
library(reshape2)
## 
## Attaching package: 'reshape2'
## 
## The following object is masked from 'package:tidyr':
## 
##     smiths
library(ggforce)
## Warning: package 'ggforce' was built under R version 4.3.3
library(readxl)
library(ggplot2)            
library(tidyverse) 
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(ggcorrplot)
## Warning: package 'ggcorrplot' was built under R version 4.3.3
library(gridExtra)
## Warning: package 'gridExtra' was built under R version 4.3.3
## 
## Attaching package: 'gridExtra'
## 
## The following object is masked from 'package:dplyr':
## 
##     combine
install.packages("gridExtra")
## Warning: package 'gridExtra' is in use and will not be installed

#READ DATA

data <- read_excel("C:/Users/bulbu/Documents/Data Praktikum Visdat.xlsx")
data
## # A tibble: 27 × 8
##    Wilayah         Y    IK    IP   AMH PDRB         UHH    TP
##    <chr>       <dbl> <dbl> <dbl> <dbl> <chr>      <dbl> <dbl>
##  1 Bogor        71.8  79.5  62.5  98.4 167 966,18  69.7 12.2 
##  2 Sukabumi     68.5  79.3  57.7  99.5 50 388,72   69.5  9.51
##  3 Cianjur      66.6  77.8  57.4  99.2 34 556,40   68.6  9.32
##  4 Bandung      73.7  83.1  65.6  99.5 88 437,96   72.1  8.32
##  5 Garut        68.1  79.8  59.8  99.6 42 012,96   69.7  8.68
##  6 Tasikmalaya  67.8  76.8  60.7  99.0 26 361,66   68.0  6.16
##  7 Ciamis       72.0  80.5  66.3  98.6 23 918,89   70.4  5.06
##  8 Kuningan     70.7  83.1  60.3  98.0 18 450,34   72.2 11.7 
##  9 Cirebon      71.0  80.7  58.8  94.8 35 523,78   70.5 10.4 
## 10 Majalengka   69.1  78.1  59.0  98.2 24 300,77   68.8  5.71
## # ℹ 17 more rows
str(data)
## tibble [27 × 8] (S3: tbl_df/tbl/data.frame)
##  $ Wilayah: chr [1:27] "Bogor" "Sukabumi" "Cianjur" "Bandung" ...
##  $ Y      : num [1:27] 71.8 68.5 66.5 73.7 68.1 ...
##  $ IK     : num [1:27] 79.5 79.3 77.8 83.1 79.8 ...
##  $ IP     : num [1:27] 62.5 57.7 57.4 65.6 59.9 ...
##  $ AMH    : num [1:27] 98.4 99.5 99.2 99.5 99.6 ...
##  $ PDRB   : chr [1:27] "167 966,18" "50 388,72" "34 556,40" "88 437,96" ...
##  $ UHH    : num [1:27] 69.7 69.5 68.6 72.1 69.7 ...
##  $ TP     : num [1:27] 12.22 9.51 9.32 8.32 8.68 ...

#1. DATA PEUBAH NUMERIK

#Korelasi

plot_X1 <- ggplot(data, aes(x = IK, y = Y)) +
  geom_point() +  
  labs(title = "Scatter Plot", x = "Indeks Kesehatan", y = "IPM") +
  theme_classic()

plot_X2 <-  ggplot(data, aes(x = IP, y = Y)) +
  geom_point() +  
  labs(title = "Scatter Plot", x = "Indeks Pendidikan", y = "IPM") +
  theme_classic()
plot_X3 <-  ggplot(data, aes(x = AMH, y = Y)) +
  geom_point() +  
  labs(title = "Scatter Plot", x = "Angka Melek Huruf", y = "IPM") +
  theme_classic()

grid.arrange(plot_X1, plot_X2, plot_X3, nrow=1)

Dari hasil perwakilan visualisasi data diatas, terlihat bahwa Indeks Kesehatan, Indeks Pendidikan , dan Angka Melek Huruf menunjukkan hubungan linear positif. Yang menandakan bahwa semakin tinggi Indeks Kesehatan,Indeks Pendidikan dan Angka Melek Huruf. Maka, nilai Indeks Pembangunan Manusia cenderung meningkat.

#Matrix Plot

data_numerik <- select_if(data, is.numeric)
str(data_numerik)
## tibble [27 × 6] (S3: tbl_df/tbl/data.frame)
##  $ Y  : num [1:27] 71.8 68.5 66.5 73.7 68.1 ...
##  $ IK : num [1:27] 79.5 79.3 77.8 83.1 79.8 ...
##  $ IP : num [1:27] 62.5 57.7 57.4 65.6 59.9 ...
##  $ AMH: num [1:27] 98.4 99.5 99.2 99.5 99.6 ...
##  $ UHH: num [1:27] 69.7 69.5 68.6 72.1 69.7 ...
##  $ TP : num [1:27] 12.22 9.51 9.32 8.32 8.68 ...
data_melt <- cor(data_numerik[sapply(data_numerik,is.numeric)])

data_melt <- melt(data_melt) 

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

ggplot(data_melt, aes(Var1, Var2, fill = value)) +
  geom_tile(color = "white") +
  scale_fill_gradient2(low = "blue", mid = "white", high = "red", 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))

data_corrl <- round(cor(data_numerik), 1)
data_corrl <- cor(data_corrl)
library(ggcorrplot)
ggcorrplot(data_corrl)

ggcorrplot(data_corrl, method = "circle")

Piecewise Constant (Fungsi Tangga)

mod = lm(Y  ~ cut(IK,3),data=data)
summary(mod)
## 
## Call:
## lm(formula = Y ~ cut(IK, 3), data = data)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -7.5275 -2.3900 -0.3975  2.4087  4.7925 
## 
## Coefficients:
##                       Estimate Std. Error t value Pr(>|t|)    
## (Intercept)             69.840      1.265  55.230   <2e-16 ***
## cut(IK, 3)(79.7,82.5]    2.062      1.591   1.296    0.207    
## cut(IK, 3)(82.5,85.4]    8.407      1.732   4.856    6e-05 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 3.346 on 24 degrees of freedom
## Multiple R-squared:   0.53,  Adjusted R-squared:  0.4909 
## F-statistic: 13.53 on 2 and 24 DF,  p-value: 0.0001161
ggplot(data,aes(x=IK, y= Y)) +
                 geom_point(alpha=0.55, color="black") +
  stat_smooth(method = "lm", 
               formula = y~cut(x,3), 
               lty = 1, col = "red",se = F)+
  theme_bw()

#2. DATA TIME SERIES

data2 <- read_excel ("C:/Users/bulbu/Documents/Data2.xlsx")
data2
## # A tibble: 1,259 × 7
##    Date                     Open      High       Low    Close `Adj Close` Volume
##    <dttm>                  <dbl>     <dbl>     <dbl>    <dbl>       <dbl>  <dbl>
##  1 2019-05-14 00:00:00 134210007 135240005 131009995   1.34e8   133580002 1.13e6
##  2 2019-05-15 00:00:00 132149994 136649994 131330002   1.36e8   136429993 9.06e5
##  3 2019-05-16 00:00:00 136429993 138160004 135050003   1.35e8   135429993 1.03e6
##  4 2019-05-17 00:00:00 133729996 135000000 131990005   1.33e8   132759995 9.91e5
##  5 2019-05-20 00:00:00 131500000 133440002 130985001   1.32e8   131520004 1.06e6
##  6 2019-05-21 00:00:00 132750000 134850006 132080002   1.32e8   132240005 9.04e5
##  7 2019-05-22 00:00:00 132050003 132660004 126610001   1.27e8   127089996 2.02e6
##  8 2019-05-23 00:00:00 124550003 124809998 120050003   1.22e8   121580002 2.10e6
##  9 2019-05-24 00:00:00 122900002 125570000 122320000   1.25e8   124650002 1.23e6
## 10 2019-05-28 00:00:00 124339996 125779999 123690002   1.24e8   124360001 6.78e5
## # ℹ 1,249 more rows
str(data2)
## tibble [1,259 × 7] (S3: tbl_df/tbl/data.frame)
##  $ Date     : POSIXct[1:1259], format: "2019-05-14" "2019-05-15" ...
##  $ Open     : num [1:1259] 1.34e+08 1.32e+08 1.36e+08 1.34e+08 1.32e+08 ...
##  $ High     : num [1:1259] 1.35e+08 1.37e+08 1.38e+08 1.35e+08 1.33e+08 ...
##  $ Low      : num [1:1259] 1.31e+08 1.31e+08 1.35e+08 1.32e+08 1.31e+08 ...
##  $ Close    : num [1:1259] 1.34e+08 1.36e+08 1.35e+08 1.33e+08 1.32e+08 ...
##  $ Adj Close: num [1:1259] 1.34e+08 1.36e+08 1.35e+08 1.33e+08 1.32e+08 ...
##  $ Volume   : num [1:1259] 1130600 906100 1032300 991300 1057000 ...
ggplot(data2, aes(x = Date,  y = Close)) +
  geom_point() +  # Add points
  geom_line() +   # Connect points with lines
  labs(title = "Scatter Plot with Connected Lines",
       x = "Date",
       y = "Volume")

#3. VISUALISASI SPASIAL

library("ggplot2")
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
library("ggplot2")
library("sf")
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(dplyr)
library(ggmap)
## Warning: package 'ggmap' was built under R version 4.3.3
## ℹ Google's Terms of Service: <https://mapsplatform.google.com>
##   Stadia Maps' Terms of Service: <https://stadiamaps.com/terms-of-service/>
##   OpenStreetMap's Tile Usage Policy: <https://operations.osmfoundation.org/policies/tiles/>
## ℹ Please cite ggmap if you use it! Use `citation("ggmap")` for details.
## 
## Attaching package: 'ggmap'
## 
## 
## The following object is masked from 'package:plotly':
## 
##     wind
library(tidygeocoder)
## Warning: package 'tidygeocoder' was built under R version 4.3.3
## 
## Attaching package: 'tidygeocoder'
## 
## The following object is masked from 'package:ggmap':
## 
##     geocode

BACA DATA

library ("sf")
library("readxl")
my_sf <- read_sf("C:/Users/bulbu/Downloads/BATAS PROVINSI DESEMBER 2019 DUKCAPIL/BATAS PROVINSI DESEMBER 2019 DUKCAPIL/BATAS_PROVINSI_DESEMBER_2019_DUKCAPIL.shp")
data3 <- read_excel("C:/Users/bulbu/Downloads/Tingkat Pengangguran Terbuka Menurut Provinsi, 2024.xlsx")
data3
## # A tibble: 39 × 2
##    Provinsi             Persentase
##    <chr>                     <dbl>
##  1 ACEH                       5.56
##  2 SUMATERA UTARA             5.1 
##  3 SUMATERA BARAT             5.79
##  4 RIAU                       3.85
##  5 JAMBI                      4.45
##  6 SUMATERA SELATAN           3.97
##  7 BENGKULU                   3.17
##  8 LAMPUNG                    4.12
##  9 KEP. BANGKA BELITUNG       3.85
## 10 KEP. RIAU                  6.94
## # ℹ 29 more rows
my_sf
## Simple feature collection with 34 features and 4 fields
## Geometry type: MULTIPOLYGON
## Dimension:     XYZ
## Bounding box:  xmin: 95.01079 ymin: -11.00762 xmax: 141.0194 ymax: 6.07693
## z_range:       zmin: 2.65e-05 zmax: 2.65e-05
## Geodetic CRS:  WGS 84
## # A tibble: 34 × 5
##    OBJECTID PROVINSI             Shape_Leng Shape_Area                  geometry
##       <dbl> <chr>                     <dbl>      <dbl>        <MULTIPOLYGON [°]>
##  1        1 ACEH                      27.5      4.63   Z (((97.39178 2.037481 2…
##  2        2 BALI                       6.03     0.459  Z (((115.1251 -8.847606 …
##  3        3 BANTEN                     9.28     0.765  Z (((105.5498 -6.995661 …
##  4        4 BENGKULU                  11.7      1.63   Z (((102.3862 -5.471439 …
##  5        5 DAERAH ISTIMEWA YOG…       3.34     0.260  Z (((110.8198 -8.203577 …
##  6        6 DKI JAKARTA                3.12     0.0534 Z (((106.8768 -6.1003 2.…
##  7        7 GORONTALO                 11.0      0.978  Z (((121.4254 0.4124347 …
##  8        8 JAMBI                     11.8      3.98   Z (((104.4071 -0.863707 …
##  9        9 JAWA BARAT                11.6      3.03   Z (((108.685 -6.769898 2…
## 10       10 JAWA TENGAH               15.5      2.82   Z (((108.8835 -7.748463 …
## # ℹ 24 more rows
library(ggforce)
library(quantmod)
## Warning: package 'quantmod' was built under R version 4.3.3
## Loading required package: xts
## Warning: package 'xts' was built under R version 4.3.3
## Loading required package: zoo
## Warning: package 'zoo' was built under R version 4.3.3
## 
## Attaching package: 'zoo'
## The following objects are masked from 'package:base':
## 
##     as.Date, as.Date.numeric
## 
## ######################### Warning from 'xts' package ##########################
## #                                                                             #
## # The dplyr lag() function breaks how base R's lag() function is supposed to  #
## # work, which breaks lag(my_xts). Calls to lag(my_xts) that you type or       #
## # source() into this session won't work correctly.                            #
## #                                                                             #
## # Use stats::lag() to make sure you're not using dplyr::lag(), or you can add #
## # conflictRules('dplyr', exclude = 'lag') to your .Rprofile to stop           #
## # dplyr from breaking base R's lag() function.                                #
## #                                                                             #
## # Code in packages is not affected. It's protected by R's namespace mechanism #
## # Set `options(xts.warn_dplyr_breaks_lag = FALSE)` to suppress this warning.  #
## #                                                                             #
## ###############################################################################
## 
## Attaching package: 'xts'
## The following objects are masked from 'package:dplyr':
## 
##     first, last
## Loading required package: TTR
## Warning: package 'TTR' was built under R version 4.3.3
## Registered S3 method overwritten by 'quantmod':
##   method            from
##   as.zoo.data.frame zoo
library(maps)
## Warning: package 'maps' was built under R version 4.3.3
## 
## Attaching package: 'maps'
## The following object is masked from 'package:purrr':
## 
##     map
library(ggmap)
library(ggthemes)
## Warning: package 'ggthemes' was built under R version 4.3.3
library(sf)
library(ggrepel)
## Warning: package 'ggrepel' was built under R version 4.3.3
data3$PROVINSI <- toupper(data3$Provinsi)
Persen.Geo <- merge(x=my_sf, y=data3, by="PROVINSI",all.x = TRUE, all.y=TRUE)
ggplot(Persen.Geo) +
  geom_sf(aes(fill= Persentase)
          , color = "#69b3a2") +
  scale_fill_gradient(low="green", high="red") +
  theme_void()

Hasil Visualisasi dari Visualisasi Spasial diatas adalah, diberikan data persebaran dengan tingkat pengangguran tertinggi di indonesia. Dapat dilihat dari Persentase bahwa tingkat pengangguran tertinggi di berikan dengan level tinggi warna merah sampai tingkat pengangguran terendah dengan warna hijau