#Merubah tipe data variabel date dan membuat data frame baru berisi time dan closing price
library(lubridate)
## Warning: package 'lubridate' was built under R version 4.4.3
## 
## Attaching package: 'lubridate'
## The following objects are masked from 'package:base':
## 
##     date, intersect, setdiff, union
dataapple <- data.frame(Time = mdy(data1$Date), Price = data1$Price)
str(dataapple)
## 'data.frame':    752 obs. of  2 variables:
##  $ Time : Date, format: "2026-03-13" "2026-03-12" ...
##  $ Price: num  250 256 261 261 260 ...
datausdeur <- data.frame(Time = mdy(data2$Date), Price = data2$Price)
str(datausdeur)
## 'data.frame':    784 obs. of  2 variables:
##  $ Time : Date, format: "2026-03-15" "2026-03-13" ...
##  $ Price: num  0.874 0.876 0.869 0.865 0.861 ...
dataxauusd <- data.frame(Time = mdy(data3$Date), Price = data3$Price)
str(dataxauusd)
## 'data.frame':    779 obs. of  2 variables:
##  $ Time : Date, format: "2026-03-15" "2026-03-13" ...
##  $ Price: num  4998 5019 5080 5177 5193 ...
#Membuat plot time series dengan ggplot2
library(ggplot2)
## Warning: package 'ggplot2' was built under R version 4.4.3
Plot_apple <- ggplot(dataapple, aes(x=Time, y=Price)) + 
  geom_line() +
  xlab("Date") 
Plot_apple

Plot_usdeur <- ggplot(datausdeur, aes(x=Time, y=Price)) + 
  geom_line() +
  xlab("Date") 
Plot_usdeur

Plot_xauusd <- ggplot(dataxauusd, aes(x=Time, y=Price)) + 
  geom_line() +
  xlab("Date") 
Plot_xauusd

#Plot single series dan beri garis putus per tahun
Plot_apple + 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 = 
               as.Date(c("2023-03-15", "2024-03-15", "2025-03-15", "2026-03-15")),
             linetype = 2, color = 2, 
             linewidth = 1) 

Grafik saham Apple 2023-2026 menunjukkan bahwa grafik terus naik tetapi pada bulan Mei 2025 terjadi penurunan yang signifikan namun harga kembali naik hingga tahun 2026.

Plot_usdeur + 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 = 
               as.Date(c("2023-03-15", "2024-03-15", "2025-03-15", "2026-03-15")),
             linetype = 2, color = 2, 
             linewidth = 1)

Grafik USD EUR 2023-2026 menunjukkan bahwa pada tahun 2025 bulan Maret ada terjadi penurunan yang signifikan walaupun pada tahun 2024 terjadi juga kenaikan harga.

Plot_xauusd + 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 = 
               as.Date(c("2023-03-15", "2024-03-15", "2025-03-15", "2026-03-15")),
             linetype = 2, color = 2, 
             linewidth = 1)

Grafik XAU USD tahun 2023-2026 menunjukkan signifikan naik terus menerus. Terlihat pada grafik signifikan naik melonjak mulai pada tahun 2025 bulan September.