Pendahuluan

Analisis ini dilakukan untuk melihat pergerakan harga saham dari tiga bank besar di Indonesia yaitu Bank Central Asia (BCA), Bank Mandiri, dan Bank Rakyat Indonesia (BRI). Visualisasi dilakukan menggunakan grafik time series dan boxplot untuk membandingkan pola pergerakan serta distribusi harga saham masing-masing bank.

Import Data

#Import Data
bca <- read.csv("C:/Semester 6/Bintel/Tugas/Data/Bank Central Asia Stock Price History.csv",
                stringsAsFactors = FALSE)

mandiri <- read.csv("C:/Semester 6/Bintel/Tugas/Data/Bank Mandiri Persero Stock Price History.csv",
                    stringsAsFactors = FALSE)

bri <- read.csv("C:/Semester 6/Bintel/Tugas/Data/Bank Rakyat Persero Stock Price History.csv",
                stringsAsFactors = FALSE)

Library

#Library
library(lubridate)
library(ggplot2)
library(dplyr)

Mengubah Variabel Price Menjadi Numeric

#Mengubah ke Numeric
bca$Price <- as.numeric(gsub(",", "", bca$Price))
mandiri$Price <- as.numeric(gsub(",", "", mandiri$Price))
bri$Price <- as.numeric(gsub(",", "", bri$Price))

Struktur Data

Berikut merupakan struktur data dari masing-masing dataset saham bank.

#Melihat Struktur Data
str(bca)
## 'data.frame':    709 obs. of  7 variables:
##  $ Date    : chr  "03/16/2026" "03/13/2026" "03/12/2026" "03/11/2026" ...
##  $ Price   : num  6800 6875 6900 6825 6975 ...
##  $ Open    : chr  "6,875" "6,850" "6,825" "6,975" ...
##  $ High    : chr  "6,875" "7,025" "7,025" "7,000" ...
##  $ Low     : chr  "6,700" "6,850" "6,825" "6,825" ...
##  $ Vol.    : chr  "77.64M" "107.94M" "98.79M" "91.92M" ...
##  $ Change..: chr  "-1.09%" "-0.36%" "1.10%" "-2.15%" ...
str(mandiri)
## 'data.frame':    709 obs. of  7 variables:
##  $ Date    : chr  "03/16/2026" "03/13/2026" "03/12/2026" "03/11/2026" ...
##  $ Price   : num  4720 4750 4960 4880 4910 ...
##  $ Open    : chr  "4,730" "4,900" "4,870" "4,930" ...
##  $ High    : chr  "4,740" "4,920" "4,980" "4,970" ...
##  $ Low     : chr  "4,640" "4,750" "4,870" "4,880" ...
##  $ Vol.    : chr  "87.05M" "187.46M" "85.99M" "86.76M" ...
##  $ Change..: chr  "-0.63%" "-4.23%" "1.64%" "-0.61%" ...
str(bri)
## 'data.frame':    709 obs. of  7 variables:
##  $ Date    : chr  "03/16/2026" "03/13/2026" "03/12/2026" "03/11/2026" ...
##  $ Price   : num  3500 3510 3570 3580 3560 3570 3670 3750 3690 3770 ...
##  $ Open    : chr  "3,490" "3,560" "3,580" "3,580" ...
##  $ High    : chr  "3,510" "3,590" "3,610" "3,600" ...
##  $ Low     : chr  "3,430" "3,510" "3,570" "3,560" ...
##  $ Vol.    : chr  "110.74M" "159.39M" "141.37M" "101.70M" ...
##  $ Change..: chr  "-0.28%" "-1.68%" "-0.28%" "0.56%" ...

Membuat Data Frame

Data kemudian diubah menjadi format time series dengan mengonversi variabel tanggal menjadi format date.

#Membuat Data Frame
databca <- data.frame(
  Time = mdy(bca$Date),
  Price = bca$Price
)

datamandiri <- data.frame(
  Time = mdy(mandiri$Date),
  Price = mandiri$Price
)

databri <- data.frame(
  Time = mdy(bri$Date),
  Price = bri$Price
)

Visualisasi Single Time Series

Grafik Harga Saham BCA

#Single Time Series Plot - BBCA
p_bca <- ggplot(databca, aes(x = Time, y = Price)) +
  geom_line() +
  xlab("Date") +
  ylab("Price")

p_bca +
  scale_x_date(date_labels = "%b %Y",
               date_breaks = "2 months") +
  theme_minimal() +
  theme(axis.text.x = element_text(angle = 50,
                                   hjust = 1))

Interpretasi: Berdasarkan grafik time series saham BCA, terlihat bahwa harga saham mengalami fluktuasi sepanjang periode pengamatan. Pergerakan harga cenderung stabil dengan beberapa kenaikan dan penurunan pada waktu tertentu.

Grafik Harga Saham Mandiri

#Single Time Series Plot - BMRI
p_mandiri <- ggplot(datamandiri, aes(x = Time, y = Price)) +
  geom_line() +
  xlab("Date") +
  ylab("Price")

p_mandiri +
  scale_x_date(date_labels = "%b %Y",
               date_breaks = "2 months") +
  theme_minimal() +
  theme(axis.text.x = element_text(angle = 50,
                                   hjust = 1))

Interpretasi: Grafik saham Bank Mandiri menunjukkan pola fluktuasi harga yang cukup dinamis. Terdapat beberapa periode kenaikan harga saham yang diikuti dengan penurunan pada periode tertentu.

Grafik Harga Saham BRI

#Single Time Series Plot - BBRI
p_bri <- ggplot(databri, aes(x = Time, y = Price)) +
  geom_line() +
  xlab("Date") +
  ylab("Price")

p_bri +
  scale_x_date(date_labels = "%b %Y",
               date_breaks = "2 months") +
  theme_minimal() +
  theme(axis.text.x = element_text(angle = 50,
                                   hjust = 1))

Interpretasi: Berdasarkan grafik saham BRI, terlihat adanya perubahan harga saham yang berfluktuasi selama periode pengamatan. Perubahan tersebut menunjukkan dinamika pasar saham yang cukup aktif.

Visualisasi Single Time Series dengan Garis Pemisah Tahun

BCA

#Single Time Series Plot - BBCA (+garis pemisah)
databca <- databca[order(databca$Time), ]

years <- seq(as.Date("2023-01-01"),
             as.Date("2026-01-01"),
             by = "1 year")

p_bca <- ggplot(databca, aes(x = Time, y = Price)) +
  geom_line() +
  scale_x_date(date_labels = "%b %Y",
               date_breaks = "2 months") +
  theme_minimal() +
  theme(axis.text.x = element_text(angle = 50,
                                   hjust = 1)) +
  geom_vline(xintercept = years,
             linetype = "dashed",
             color = "red",
             linewidth = 1) +
  labs(title = "BCA Stock Price Time Series",
       x = "Date",
       y = "Price")

p_bca

Interpretasi: Penambahan garis pemisah tahun mempermudah identifikasi perubahan harga saham BCA setiap tahunnya. Terlihat bahwa pergerakan saham memiliki pola yang berbeda pada masing-masing periode tahun.

Mandiri

#Single Time Series Plot - BMRI (+garis pemisah)
datamandiri <- datamandiri[order(datamandiri$Time), ]

years <- seq(as.Date("2023-01-01"),
             as.Date("2026-01-01"),
             by = "1 year")

p_mandiri <- ggplot(datamandiri, aes(x = Time, y = Price)) +
  geom_line() +
  scale_x_date(date_labels = "%b %Y",
               date_breaks = "2 months") +
  theme_minimal() +
  theme(axis.text.x = element_text(angle = 50,
                                   hjust = 1)) +
  geom_vline(xintercept = years,
             linetype = "dashed",
             color = "red",
             linewidth = 1) +
  labs(title = "Bank Mandiri Stock Price Time Series",
       x = "Date",
       y = "Price")

p_mandiri

Interpretasi: Grafik dengan garis pemisah menunjukkan bahwa saham Bank Mandiri mengalami perubahan harga yang cukup konsisten antar tahun, meskipun tetap terdapat fluktuasi pada beberapa periode tertentu.

BRI

#Single Time Series Plot - BBRI (+garis pemisah)
databri <- databri[order(databri$Time), ]

years <- seq(as.Date("2023-01-01"),
             as.Date("2026-01-01"),
             by = "1 year")

p_bri <- ggplot(databri, aes(x = Time, y = Price)) +
  geom_line() +
  scale_x_date(date_labels = "%b %Y",
               date_breaks = "2 months") +
  theme_minimal() +
  theme(axis.text.x = element_text(angle = 50,
                                   hjust = 1)) +
  geom_vline(xintercept = years,
             linetype = "dashed",
             color = "red",
             linewidth = 1) +
  labs(title = "BRI Stock Price Time Series",
       x = "Date",
       y = "Price")

p_bri

Interpretasi: Visualisasi saham BRI dengan garis pemisah tahun memperlihatkan pola perubahan harga saham yang cukup fluktuatif dari tahun ke tahun.

Multiple Time Series

#Multiple Time Series
data_all <- rbind(
  data.frame(Time = databca$Time,
             Price = databca$Price,
             Bank = "BCA"),

  data.frame(Time = datamandiri$Time,
             Price = datamandiri$Price,
             Bank = "Mandiri"),

  data.frame(Time = databri$Time,
             Price = databri$Price,
             Bank = "BRI")
)

ggplot(data_all,
       aes(x = Time,
           y = Price,
           color = Bank)) +

  geom_line(size = 1.1) +

  scale_x_date(
    date_labels = "%b %Y",
    date_breaks = "4 months"
  ) +

  labs(
    title = "Perbandingan Harga Saham Bank BCA, Mandiri, dan BRI",
    subtitle = "Data harian 2023–2026",
    x = "Tanggal",
    y = "Harga Saham (IDR)",
    color = "Bank"
  ) +

  theme_minimal() +

  theme(
    plot.title = element_text(size = 16,
                              face = "bold"),
    plot.subtitle = element_text(size = 12),
    axis.text.x = element_text(angle = 45,
                               hjust = 1),
    legend.position = "bottom",
    legend.title = element_text(face = "bold")
  )
## Warning: Using `size` aesthetic for lines was deprecated in ggplot2 3.4.0.
## ℹ Please use `linewidth` instead.
## This warning is displayed once per session.
## Call `lifecycle::last_lifecycle_warnings()` to see where this warning was
## generated.

Interpretasi: Grafik multiple time series menunjukkan perbandingan harga saham antara BCA, Mandiri, dan BRI. Saham BCA terlihat memiliki nilai harga paling tinggi dibandingkan dua bank lainnya selama periode pengamatan.

Multiple Time Series dengan Garis Pemisah Tahun

#Multiple Time Series (+garis pemisah)
years <- seq(as.Date("2023-01-01"),
             as.Date("2026-01-01"),
             by = "1 year")

ggplot(data_all,
       aes(x = Time,
           y = Price,
           color = Bank)) +

  geom_line(size = 1.1) +

  geom_vline(xintercept = years,
             linetype = "dashed",
             color = "gray40",
             linewidth = 0.8) +

  scale_x_date(
    date_labels = "%b %Y",
    date_breaks = "4 months"
  ) +

  labs(
    title = "Perbandingan Harga Saham Bank BCA, Mandiri, dan BRI",
    subtitle = "Data harian 2023–2026 dengan pemisah tahun",
    x = "Tanggal",
    y = "Harga Saham (IDR)",
    color = "Bank"
  ) +

  theme_minimal() +

  theme(
    plot.title = element_text(size = 16,
                              face = "bold"),
    plot.subtitle = element_text(size = 12),
    axis.text.x = element_text(angle = 45,
                               hjust = 1),
    legend.position = "bottom",
    legend.title = element_text(face = "bold")
  )

Interpretasi: Dengan adanya garis pemisah tahun, perubahan tren harga saham antar bank menjadi lebih mudah diamati pada setiap periode tahunan.

Boxplot

#Boxplot
ggplot(data_all,
       aes(x = Bank,
           y = Price,
           fill = Bank)) +

  geom_boxplot() +

  labs(
    title = "Perbandingan Distribusi Harga Saham",
    subtitle = "BCA vs Mandiri vs BRI",
    x = "Bank",
    y = "Harga Saham (IDR)"
  ) +

  theme_minimal() +

  theme(
    plot.title = element_text(size = 14,
                              face = "bold"),
    legend.position = "none"
  )

Interpretasi: Boxplot menunjukkan distribusi harga saham dari masing-masing bank. Saham BCA memiliki median harga yang lebih tinggi dibandingkan saham Mandiri dan BRI. Selain itu, terlihat juga adanya variasi distribusi harga pada masing-masing bank.

Kesimpulan

Berdasarkan hasil visualisasi, masing-masing saham bank memiliki pola pergerakan yang berbeda. Saham BCA cenderung memiliki harga paling tinggi, sedangkan saham Mandiri dan BRI menunjukkan pola fluktuasi yang relatif lebih rendah. Visualisasi time series dan boxplot membantu dalam memahami tren dan distribusi harga saham selama periode pengamatan.