data1=read.csv("C:/Users/PUDJA/Documents/college/academic/sem 6/Business Intelligence/Data Historis MTWI.csv",sep=,)
str(data1)
## 'data.frame':    722 obs. of  7 variables:
##  $ Tanggal   : chr  "30/12/2024" "27/12/2024" "24/12/2024" "23/12/2024" ...
##  $ Terakhir  : int  159 159 158 158 158 159 159 160 162 160 ...
##  $ Pembukaan : int  156 159 158 157 159 158 160 160 160 164 ...
##  $ Tertinggi : int  159 160 159 158 160 159 160 162 163 164 ...
##  $ Terendah  : int  155 158 158 157 157 157 158 160 160 157 ...
##  $ Vol.      : chr  "2,60K" "67,40K" "18,00K" "16,60K" ...
##  $ Perubahan.: chr  "0,00%" "0,63%" "0,00%" "0,00%" ...
#merubah tipe variabel data dan data frame baru untuk tanggal dan close
mtwi=data.frame(Time=as.Date(data1$Tanggal,format='%d/%m/%Y'),Price=data1$Terakhir)
str(mtwi)
## 'data.frame':    722 obs. of  2 variables:
##  $ Time : Date, format: "2024-12-30" "2024-12-27" ...
##  $ Price: int  159 159 158 158 158 159 159 160 162 160 ...
#membuat plot time series dengan ggplot2
library(ggplot2)
## Warning: package 'ggplot2' was built under R version 4.3.3
p1=ggplot(mtwi,aes(x=Time,y=Price))+
  geom_line()+
  xlab("Date")
p1

#modification untuk penamaan sumbu x dan tema plot
p1+scale_x_date(date_labels="%b %Y", date_breaks="2 months")+
  theme_update()+
  theme(axis.text.x = element_text(angle=50,hjust=1))+
  #modification untuk menambah garis pembatas
  geom_vline(xintercept=as.Date("2023-01-01"),linetype=2,color=2,linewidth=1)+
  geom_vline(xintercept=as.Date("2024-01-01"),linetype=2,color=2,linewidth=1)

data2=read.csv("C:/Users/PUDJA/Documents/college/academic/sem 6/Business Intelligence/Data Historis AMAG.csv",sep=,)
str(data2)
## 'data.frame':    722 obs. of  7 variables:
##  $ Tanggal   : chr  "30/12/2024" "27/12/2024" "24/12/2024" "23/12/2024" ...
##  $ Terakhir  : int  330 328 328 328 328 328 334 332 332 336 ...
##  $ Pembukaan : int  330 328 328 328 330 332 334 332 334 334 ...
##  $ Tertinggi : int  332 330 330 330 330 334 334 336 338 338 ...
##  $ Terendah  : int  330 326 326 326 320 322 332 328 322 334 ...
##  $ Vol.      : chr  "7,60K" "17,60K" "10,60K" "35,80K" ...
##  $ Perubahan.: chr  "0,61%" "0,00%" "0,00%" "0,00%" ...
#merubah tipe variabel data dan data frame baru untuk tanggal dan close
amag=data.frame(Time=as.Date(data2$Tanggal,format='%d/%m/%Y'),Price=data2$Terakhir)
str(amag)
## 'data.frame':    722 obs. of  2 variables:
##  $ Time : Date, format: "2024-12-30" "2024-12-27" ...
##  $ Price: int  330 328 328 328 328 328 334 332 332 336 ...
#membuat plot time series dengan ggplot2
library(ggplot2)
p2=ggplot(amag,aes(x=Time,y=Price))+
  geom_line()+
  xlab("Date")
p2

#modification untuk penamaan sumbu x dan tema plot
p2+scale_x_date(date_labels="%b %Y", date_breaks="2 months")+
  theme_update()+
  theme(axis.text.x = element_text(angle=50,hjust=1))+
  #modification untuk menambah garis pembatas
  geom_vline(xintercept=as.Date("2023-01-01"),linetype=2,color=3,linewidth=1)+
  geom_vline(xintercept=as.Date("2024-01-01"),linetype=2,color=3,linewidth=1)

data3=read.csv("C:/Users/PUDJA/Documents/college/academic/sem 6/Business Intelligence/Data Historis ASBI.csv",sep=,)
str(data3)
## 'data.frame':    644 obs. of  7 variables:
##  $ Tanggal   : chr  "30/12/2024" "27/12/2024" "24/12/2024" "23/12/2024" ...
##  $ Terakhir  : int  462 464 472 466 510 510 515 520 520 545 ...
##  $ Pembukaan : int  466 472 466 480 520 505 540 520 520 545 ...
##  $ Tertinggi : int  490 472 490 488 560 510 540 520 520 545 ...
##  $ Terendah  : int  460 450 450 460 476 505 496 520 510 545 ...
##  $ Vol.      : chr  "12,30K" "4,10K" "13,40K" "50,80K" ...
##  $ Perubahan.: chr  "-0,43%" "-1,69%" "1,29%" "-8,63%" ...
#merubah tipe variabel data dan data frame baru untuk tanggal dan close
asbi=data.frame(Time=as.Date(data3$Tanggal,format='%d/%m/%Y'),Price=data3$Terakhir)
str(asbi)
## 'data.frame':    644 obs. of  2 variables:
##  $ Time : Date, format: "2024-12-30" "2024-12-27" ...
##  $ Price: int  462 464 472 466 510 510 515 520 520 545 ...
#membuat plot time series dengan ggplot2
library(ggplot2)
p3=ggplot(asbi,aes(x=Time,y=Price))+
  geom_line()+
  xlab("Date")
p3

#modification untuk penamaan sumbu x dan tema plot
p3+scale_x_date(date_labels="%b %Y", date_breaks="2 months")+
  theme_update()+
  theme(axis.text.x = element_text(angle=50,hjust=1))+
  #modification untuk menambah garis pembatas
  geom_vline(xintercept=as.Date("2023-01-01"),linetype=2,color=4,linewidth=1)+
  geom_vline(xintercept=as.Date("2024-01-01"),linetype=2,color=4,linewidth=1)

library(ggplot2)
library(dplyr)
## Warning: package 'dplyr' was built under R version 4.3.3
## 
## 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
#menggabungkan data
data=mtwi %>%
  left_join(amag, by = "Time") %>%
  left_join(asbi, by = "Time")
names(data)
## [1] "Time"    "Price.x" "Price.y" "Price"
#mengubah nama kolom agar lebih jelas
data=data %>%
  rename(
    mtwi = Price.x,
    amag = Price.y,
    asbi = Price
  )
#mengubah format data
library(tidyr)
## Warning: package 'tidyr' was built under R version 4.3.3
data_long=data %>%
  pivot_longer(cols = c("mtwi","amag","asbi"), 
               names_to = "Saham", 
               values_to = "Price")

#membuat plot time series dengan ggplot2
p=ggplot(data_long,aes(x=Time,y=Price,color=Saham))+
  geom_line(size=1)+
  theme(legend.position="bottom")
## 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.
p

#modification untuk penamaan sumbu x dan tema plot
p+scale_x_date(date_labels="%b %Y", date_breaks="2 months")+
  theme_update()+
  theme(axis.text.x = element_text(angle=50,hjust=1))+
  #modification untuk menambah garis pembatas
  geom_vline(xintercept=as.Date("2023-01-01"),linetype=2,color=6,linewidth=1)+
  geom_vline(xintercept=as.Date("2024-01-01"),linetype=2,color=6,linewidth=1)

Dapat dilihat perbandingan ketiga stock price dalam rentang 3 tahun. Diketahui bahwa saham Asuransi Bintang memiliki kenaikan yang paling signifikan disbanding saham Malacca Trust Wuwungan Insurance dan Asuransi Multi Artha Guna. Pada multiple data series plot terlihat bahwa garis terputus sekitar periode juli 2024 hingga nov 2024 untuk saham Asuransi Bintang, hal ini disebebkan oleh tidak terdaftarnya data saham pada periode tersebut.

ggplot(data = data_long, mapping = aes(x = Time, y = Price, color=Saham)) +
  geom_boxplot()
## Warning: Removed 78 rows containing non-finite outside the scale range
## (`stat_boxplot()`).

Dapat dilihat perbandingan dilihat sebaran data untuk masing-masing saham dan juga outlier pada masing-masing data yang ditanai dengan titik-titik di luar box pada plot. Terlihat bahwa saham Malacca Trust Wuwungan Insurance memiliki outlier, sedangkan dua saham lainnya tidak memiliki outlier.