# Install and load required packages
library(readxl)
## Warning: package 'readxl' was built under R version 4.3.3
library(ggplot2)
library(scales)
# Membaca data dari file Excel
data <- read_xlsx("C:/Users/delia/Downloads/bahan visdat.xlsx")
data
## # A tibble: 1,232 × 3
## Date Apple Xiaomi
## <dttm> <dbl> <dbl>
## 1 2019-04-25 00:00:00 51320000 11980000
## 2 2019-04-26 00:00:00 51075001 12020000
## 3 2019-04-29 00:00:00 51152500 11980000
## 4 2019-04-30 00:00:00 50167500 12020000
## 5 2019-05-01 00:00:00 52630001 11620000
## 6 2019-05-02 00:00:00 52287498 11800000
## 7 2019-05-03 00:00:00 52937500 11000000
## 8 2019-05-06 00:00:00 52119999 10840000
## 9 2019-05-07 00:00:00 50715000 10580000
## 10 2019-05-08 00:00:00 50724998 10460000
## # ℹ 1,222 more rows
ggplot(data, aes(x = Date)) +
geom_line(aes(y = Apple/1000000, color = "Apple"), size = 1) +
geom_line(aes(y = Xiaomi/1000000, color = "Xiaomi"), size = 1) +
labs(x = "Tahun", y = "Penutupan Saham (Jutaan)", color = "Perusahaan") +
scale_y_continuous(labels = scales::comma) + # Ubah skala y menjadi format angka dengan koma
scale_color_manual(values = c("Apple" = "blue", "Xiaomi" = "red")) + # Warna garis sesuai perusahaan
theme_minimal()
## 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.
