Data diambil dari website http://finance.yahoo.com, kemudian disimpan dalam format csv
ASII <- read.csv("D:/Matkul/Semester 6/BINTEL/5. Plot Time Series/Data Saham/Data Historis ASII.csv")
UNVR <- read.csv("D:/Matkul/Semester 6/BINTEL/5. Plot Time Series/Data Saham/Data Historis UNVR.csv")
KLBF <- read.csv("D:/Matkul/Semester 6/BINTEL/5. Plot Time Series/Data Saham/Data Historis KLBF.csv")
data_ASII <- data.frame(Time=as.Date(ASII$Tanggal, format = '%d/%m/%Y'),
Price = ASII$Terakhir)
data_UNVR <- data.frame(Time=as.Date(UNVR$Tanggal, format = '%d/%m/%Y'),
Price = UNVR$Terakhir)
data_KLBF <- data.frame(Time=as.Date(KLBF$Tanggal, format = '%d/%m/%Y'),
Price = KLBF$Terakhir)
str(data_ASII)
## 'data.frame': 470 obs. of 2 variables:
## $ Time : Date, format: "2025-04-09" "2025-04-08" ...
## $ Price: num 4.62 4.48 4.92 4.8 4.65 4.69 4.84 4.71 4.69 4.65 ...
str(data_UNVR)
## 'data.frame': 470 obs. of 2 variables:
## $ Time : Date, format: "2025-04-09" "2025-04-08" ...
## $ Price: num 1.16 1.18 1.26 1.24 1.25 ...
str(data_KLBF)
## 'data.frame': 470 obs. of 2 variables:
## $ Time : Date, format: "2025-04-09" "2025-04-08" ...
## $ Price: num 1.1 1.05 1.14 1.1 1.14 ...
library(ggplot2)
# Titik maksimum & minimum
max_point <- data_ASII[which.max(data_ASII$Price), ]
min_point <- data_ASII[which.min(data_ASII$Price), ]
ggplot(data_ASII, aes(x = Time, y = Price)) +
geom_line(color = "#E63946", linetype = 1, size = 1.3) +
geom_point(data = max_point, aes(x = Time, y = Price), color = "darkgreen", size = 3) +
geom_point(data = min_point, aes(x = Time, y = Price), color = "darkblue", size = 3) +
geom_text(data = max_point, aes(label = paste("Max:", format(Price, big.mark = "."))),
vjust = 1, fontface = "italic", size = 2.5) +
geom_text(data = min_point, aes(label = paste("Min:", format(Price, big.mark = "."))),
vjust = -0.5,fontface = "italic", size = 2.5) +
# Informasi tambahan
labs(
title = "Time Series Saham ASII",
subtitle = "Pergerakan harga saham sejak April 2023 - April 2025",
x = "Tanggal", y = "Harga Saham (Dalam Ribu Rp)",
caption = "Sumber: id.investing.com"
) +
# Menambah garis vertikal
geom_vline(xintercept = as.Date(c("2024-01-01", "2025-01-01")),
linetype = 2, color = 1, size = 0.5
) +
# Skala tanggal & harga
scale_x_date(
date_breaks = "1 months",
date_labels = "%b %Y",
expand = c(0.1, 0.01)
) +
scale_y_continuous(
labels = scales::label_number(big.mark = ".", decimal.mark = ","),
breaks = scales::pretty_breaks(n = 10)
) +
# Tema dan gaya
theme_minimal(base_family = "Arial") +
theme(
plot.title = element_text(face = "bold", size = 16),
plot.subtitle = element_text(size = 12, color = "gray40"),
axis.title = element_text(size = 12, face = "bold"),
axis.text = element_text(size = 10),
axis.text.x = element_text(angle = 50, hjust = 1),
plot.caption = element_text(size = 9, face = "italic", hjust = 1),
panel.grid.major = element_line(color = "gray85", linetype = "dotted"),
panel.grid.minor = element_blank()
)
# Titik maksimum & minimum
max_point_unvr <- data_UNVR[which.max(data_UNVR$Price), ]
min_point_unvr <- data_UNVR[which.min(data_UNVR$Price), ]
ggplot(data_UNVR, aes(x = Time, y = Price)) +
geom_line(color = "#1D3557", linetype = 1, size = 1.3) +
geom_point(data = max_point_unvr, aes(x = Time, y = Price), color = "#FFB703", size = 3) +
geom_point(data = min_point_unvr, aes(x = Time, y = Price), color = "#FB5607", size = 3) +
geom_text(data = max_point_unvr, aes(label = paste("Max:", format(Price, big.mark = "."))),
vjust = 1, fontface = "italic", size = 3.5) +
geom_text(data = min_point_unvr, aes(label = paste("Min:", format(Price, big.mark = "."))),
vjust = -0.5,fontface = "italic", size = 3.5) +
labs(
title = "Time Series Saham UNVR",
subtitle = "Pergerakan harga saham sejak April 2023 - April 2025",
x = "Tanggal", y = "Harga Saham (Dalam Ribuan Rp)",
caption = "Sumber: id.investing.com"
) +
geom_vline(xintercept = as.Date(c("2024-01-01", "2025-01-01")),
linetype = 3, color = "#6A4C93", size = 0.5
) +
scale_x_date(
date_breaks = "1 months",
date_labels = "%b %Y",
expand = c(0.05, 0.01)
) +
scale_y_continuous(
labels = scales::label_comma(big.mark = ".", decimal.mark = ",", scale_cut = scales::cut_short_scale()),
breaks = scales::pretty_breaks(n = 10)
) +
theme_minimal(base_family = "Arial") +
theme(
plot.title = element_text(face = "bold", size = 16),
plot.subtitle = element_text(size = 12, color = "gray40"),
axis.title = element_text(size = 11, face = "bold"),
axis.text = element_text(size = 10),
axis.text.x = element_text(angle = 50, hjust = 1),
plot.caption = element_text(size = 9, face = "italic", hjust = 1),
panel.grid.minor = element_blank()
)
## KLBF
# Titik maksimum & minimum
max_point_klbf <- data_KLBF[which.max(data_KLBF$Price), ]
min_point_klbf <- data_KLBF[which.min(data_KLBF$Price), ]
ggplot(data_KLBF, aes(x = Time, y = Price)) +
geom_line(color = "#2A9D8F", linetype = 1, size = 1.3) +
geom_point(data = max_point_klbf, aes(x = Time, y = Price), color = "#E76F51", size = 3) +
geom_point(data = min_point_klbf, aes(x = Time, y = Price), color = "#264653", size = 3) +
geom_text(data = max_point_klbf, aes(label = paste("Max:", format(Price, big.mark = "."))),
vjust = 1, fontface = "italic", size = 3.5) +
geom_text(data = min_point_klbf, aes(label = paste("Min:", format(Price, big.mark = "."))),
vjust = -0.5, fontface = "italic", size = 3.5) +
labs(
title = "Time Series Saham KLBF",
subtitle = "Pergerakan harga saham sejak April 2023 - April 2025",
x = "Tanggal", y = "Harga Saham (Dalam Ribuan Rp)",
caption = "Sumber: id.investing.com"
) +
geom_vline(xintercept = as.Date(c("2024-01-01", "2025-01-01")),
linetype = "longdash", color = "#1B9CFC", size = 0.5
) +
scale_x_date(
date_breaks = "1 months",
date_labels = "%b %Y",
expand = c(0.05, 0.01)
) +
scale_y_continuous(
labels = scales::label_number(big.mark = ".", decimal.mark = ","),
breaks = scales::pretty_breaks(n = 10)
) +
theme_minimal(base_family = "Arial") +
theme(
plot.title = element_text(face = "bold", size = 16),
plot.subtitle = element_text(size = 11, color = "gray40"),
axis.title = element_text(size = 12, face = "bold"),
axis.text = element_text(size = 10),
axis.text.x = element_text(angle = 50, hjust = 1),
plot.caption = element_text(size = 9, face = "italic", hjust = 1),
panel.grid.minor = element_blank()
)
library(ggplot2)
library(scales)
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
# Gabungkan semua data ke long format
data_ASII$Saham <- "ASII"
data_UNVR$Saham <- "UNVR"
data_KLBF$Saham <- "KLBF"
data_all <- bind_rows(data_ASII, data_UNVR, data_KLBF)
# Plot
ggplot(data_all, aes(x = Time, y = Price, color = Saham)) +
geom_line(size = 1.2, linetype = "solid") +
geom_vline(
xintercept = as.Date(c("2024-01-01", "2025-01-01")), # contoh titik penting
linetype = "dashed", color = "gray30", size = 0.6
) +
labs(
title = "Pergerakan Harga Saham: ASII, UNVR, KLBF",
subtitle = "Time series sejak April 2023 - April 2025",
x = "Tanggal",
y = "Harga Saham (Dalam Ribuan Rp)",
caption = "Sumber: id.investing.com",
color = "Kode Saham"
) +
scale_x_date(
date_breaks = "2 months",
date_labels = "%b %Y",
expand = c(0.01, 0.01)
) +
scale_y_continuous(
labels = label_comma(big.mark = ".", decimal.mark = ","),
breaks = pretty_breaks(n = 10)
) +
theme_minimal(base_family = "Arial") +
theme(
plot.title = element_text(face = "bold", size = 16),
plot.subtitle = element_text(size = 12, color = "gray40"),
axis.title = element_text(size = 11, face = "bold"),
axis.title.y = element_text(size = 10),
axis.text = element_text(size = 9),
axis.text.x = element_text(angle = 50, hjust = 1),
plot.caption = element_text(size = 9, face = "italic", hjust = 1),
legend.position = "top",
legend.title = element_text(size = 10, face = "bold"),
legend.text = element_text(size = 9)
)
# Eksplorasi Data
# Atur panel menjadi 1 baris 3 kolom
par(mfrow = c(1, 3), mar = c(4, 4, 3, 1))
# Boxplot untuk ASII
boxplot(data_ASII$Price,
main = "ASII", col = "#E63946", ylab = "Harga (Rp)", border = "black")
# Boxplot untuk UNVR
boxplot(data_UNVR$Price,
main = "UNVR", col = "#457B9D", ylab = "Harga (Rp)", border = "black")
# Boxplot untuk KLBF
boxplot(data_KLBF$Price,
main = "KLBF", col = "#2A9D8F", ylab = "Harga (Rp)", border = "black")
# Judul utama di atas semua panel
mtext("Boxplot Distribusi Harga Saham: ASII, UNVR, KLBF",
side = 1, line = 4, outer = TRUE,
font = 2, cex = 1.5, col = "darkblue")