Anggota
- Adi Pratama M0401241002
- Ni Kadek Arista Mahadewi M0401241031
- Muhammad Athaurahman M0401241082
- Ainur Roudlotul Jannah Firdaus M0401241028
- Desthio Rendiarto Akhmad M0401241080
- Mifta Indira Putri Wardini M0401241090
library(ggplot2)
library(dplyr)
##
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
##
## filter, lag
## The following objects are masked from 'package:base':
##
## intersect, setdiff, setequal, union
##
## Attaching package: 'lubridate'
## The following objects are masked from 'package:base':
##
## date, intersect, setdiff, union
## Warning: package 'readxl' was built under R version 4.5.2
##
## Attaching package: 'zoo'
## The following objects are masked from 'package:base':
##
## as.Date, as.Date.numeric
Data
data <- read_xlsx("C:\\Dokumen\\Kuliah IPB\\Semester 4\\Visualisasi Data\\Tugas Projek\\Data Gabungan.xlsx")
head(data)
## # A tibble: 6 × 14
## Tanggal Terakhir Pembukaan Tertinggi Terendah Vol. `Perubahan%`
## <dttm> <dbl> <dbl> <dbl> <dbl> <chr> <dbl>
## 1 2026-02-20 00:00:00 8272. 8300. 8328. 8237. 40,03B -0.0003
## 2 2026-02-19 00:00:00 8274. 8357. 8376. 8252. 43,54B -0.0043
## 3 2026-02-18 00:00:00 8310. 8236. 8310. 8227. 45,90B 0.0119
## 4 2026-02-13 00:00:00 8212. 8240. 8252. 8171. 43,44B -0.0064
## 5 2026-02-12 00:00:00 8265. 8317. 8334. 8220. 37,94B -0.0031
## 6 2026-02-11 00:00:00 8291. 8153. 8291. 8118. 54,57B 0.0196
## # ℹ 7 more variables: `Data Historis USD_IDR.Tanggal` <dttm>,
## # `Data Historis USD_IDR.Terakhir` <dbl>,
## # `Data Historis USD_IDR.Pembukaan` <dbl>,
## # `Data Historis USD_IDR.Tertinggi` <dbl>,
## # `Data Historis USD_IDR.Terendah` <dbl>, `Data Historis USD_IDR.Vol.` <chr>,
## # `Data Historis USD_IDR.Perubahan%` <dbl>
## tibble [2,451 × 14] (S3: tbl_df/tbl/data.frame)
## $ Tanggal : POSIXct[1:2451], format: "2026-02-20" "2026-02-19" ...
## $ Terakhir : num [1:2451] 8272 8274 8310 8212 8265 ...
## $ Pembukaan : num [1:2451] 8300 8357 8236 8240 8317 ...
## $ Tertinggi : num [1:2451] 8328 8376 8310 8252 8334 ...
## $ Terendah : num [1:2451] 8237 8252 8227 8171 8220 ...
## $ Vol. : chr [1:2451] "40,03B" "43,54B" "45,90B" "43,44B" ...
## $ Perubahan% : num [1:2451] -0.0003 -0.0043 0.0119 -0.0064 -0.0031 0.0196 0.0124 0.0122 -0.0208 -0.0053 ...
## $ Data Historis USD_IDR.Tanggal : POSIXct[1:2451], format: "2026-02-20" "2026-02-19" ...
## $ Data Historis USD_IDR.Terakhir : num [1:2451] 16865 16875 16880 16830 16815 ...
## $ Data Historis USD_IDR.Pembukaan : num [1:2451] 16883 16890 16845 16820 16800 ...
## $ Data Historis USD_IDR.Tertinggi : num [1:2451] 16946 16937 16894 16855 16833 ...
## $ Data Historis USD_IDR.Terendah : num [1:2451] 16855 16875 16838 16818 16800 ...
## $ Data Historis USD_IDR.Vol. : chr [1:2451] NA NA NA NA ...
## $ Data Historis USD_IDR.Perubahan%: num [1:2451] -0.0006 -0.0003 0.003 0.0009 0.0021 -0.0009 -0.0003 -0.0039 0.0021 0.0036 ...
Eksplorasi
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## 3938 5823 6324 6346 6943 9135
summary(data$`Data Historis USD_IDR.Terakhir`)
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## 12948 13920 14410 14651 15480 16950
Time Series Plot
data_filt <- data %>%
filter(Tanggal >= as.Date("2020-01-02"),
Tanggal <= as.Date("2024-12-30"))
ggplot(data_filt, aes(x = Tanggal, y = Terakhir)) +
geom_line(color = "blue") +
labs(
title = "Pergerakan IHSG",
x = "Waktu",
y = "IHSG"
) +
scale_x_date(date_labels = "%b %Y", date_breaks = "1 year") +
theme_minimal()

ggplot(data_filt, aes(x = Tanggal, y = `Data Historis USD_IDR.Terakhir`)) +
geom_line(color = "red") +
labs(
title = "Pergerakan Nilai Tukar USD/IDR",
x = "Waktu",
y = "Kurs (IDR)"
) +
scale_x_date(date_labels = "%b %Y", date_breaks = "1 year") +
theme_minimal()

data_filt <- data %>%
filter(Tanggal >= as.Date("2020-01-02"),
Tanggal <= as.Date("2024-12-30"))
ggplot(data_filt, aes(x = Tanggal, y = `Perubahan%`)) +
geom_line(color = "blue") +
labs(
title = "Pergerakan IHSG",
x = "Waktu",
y = "IHSG"
) +
scale_x_date(date_labels = "%b %Y", date_breaks = "1 year") +
theme_minimal()

ggplot(data_filt, aes(x = Tanggal, y = `Data Historis USD_IDR.Perubahan%`)) +
geom_line(color = "red") +
labs(
title = "Pergerakan Nilai Tukar USD/IDR",
x = "Waktu",
y = "Kurs (IDR)"
) +
scale_x_date(date_labels = "%b %Y", date_breaks = "1 year") +
theme_minimal()

Time Series Gabungan
data_filt <- data %>%
filter(Tanggal >= as.Date("2020-01-02"),
Tanggal <= as.Date("2024-12-30"))
ggplot(data_filt, aes(x = Tanggal)) +
geom_line(aes(y = `Perubahan%`, color = "Harga IHSG")) +
geom_line(aes(y = `Data Historis USD_IDR.Perubahan%` , color = "`Data Historis USD_IDR.Terakhir`")) +
labs(
title = "Time Series Plot",
x = "Tanggal",
y = "Harga",
color = "Variable"
) +
theme_minimal()

ggplot(data_filt, aes(x = Tanggal)) +
geom_line(aes(y = Terakhir, color = "Harga IHSG")) +
geom_line(aes(y = `Data Historis USD_IDR.Terakhir` , color = "`Data Historis USD_IDR.Terakhir`")) +
labs(
title = "Time Series Plot",
x = "Tanggal",
y = "Harga",
color = "Variable"
) +
theme_minimal()

#Skala Disamakan
data_filt <- data %>%
filter(Tanggal >= as.Date("2020-01-02"),
Tanggal <= as.Date("2024-12-30"))
data_plot <- data_filt %>%
mutate(
IHSG_z = scale(Terakhir),
USDIDR_z = scale(`Data Historis USD_IDR.Terakhir`)
)
ggplot(data_plot, aes(x = Tanggal)) +
geom_line(aes(y = IHSG_z, color = "IHSG")) +
geom_line(aes(y = USDIDR_z, color = "USD/IDR")) +
scale_x_date(date_labels = "%b %Y", date_breaks = "1 year") +
theme_minimal() +
theme(
axis.text.y = element_blank(),
axis.title.y = element_blank()
)

Scatter Plot
# Scatter plot dasar
ggplot(data, aes(x = `Perubahan%`, y = `Data Historis USD_IDR.Perubahan%`)) +
geom_point(alpha = 0.5, # transparansi titik
color = "blue") + # warna titik
labs(title = "Hubungan Perubahan IHSG dan Nilai Tukar Rupiah",
x = "Perubahan IHSG",
y = "Perubahan Nilai Tukar") +
theme_minimal() +
geom_smooth(method = "lm", # menambahkan garis regresi linear
se = TRUE, # confidence interval
color = "red")
## `geom_smooth()` using formula = 'y ~ x'

#Perhitungan Korelasi dan Koefisien Determinasi
x <- data$`Perubahan%`
y <- data$`Data Historis USD_IDR.Perubahan%`
r<-cor(x, y)
r2 <- r*r
r
## [1] -0.3670275
## [1] 0.1347092
Perhitungan Volatisitas
data_vol <- data_filt %>%
arrange(Tanggal) %>%
mutate(
vol_IHSG = rollapply(
`Perubahan%`,
width = 20,
FUN = sd,
fill = NA,
align = "right"
)
)
data_vol <- data_vol %>%
mutate(
vol_USDIDR = rollapply(
`Data Historis USD_IDR.Perubahan%`,
width = 20,
FUN = sd,
fill = NA,
align = "right"
)
)
ggplot(data_vol, aes(x = Tanggal, y = vol_IHSG)) +
geom_line(color = "darkred") +
labs(
title = "Volatilitas IHSG (Rolling 20 Hari)",
y = "Volatilitas (%)"
) +
theme_minimal()
## Warning: Removed 19 rows containing missing values or values outside the scale range
## (`geom_line()`).

ggplot(data_vol, aes(x = Tanggal)) +
geom_line(aes(y = vol_IHSG, color = "Vol IHSG")) +
geom_line(aes(y = vol_USDIDR, color = "Vol USD/IDR")) +
scale_x_date(date_labels = "%b %Y", date_breaks = "1 year") +
theme_minimal()
## Warning: Removed 19 rows containing missing values or values outside the scale range
## (`geom_line()`).
## Removed 19 rows containing missing values or values outside the scale range
## (`geom_line()`).

# Korelasi Volativitas IHSG dan Nilai Tukar Rupiah
cor(data_vol$vol_IHSG,
data_vol$vol_USDIDR,
use = "complete.obs")
## [1] 0.7720222