tinytex::is_tinytex()
## [1] FALSE
#Input Data
data <- read.csv("C:/Users/Fathoni Sabri/Downloads/AED/Clean_Dataset.csv")
#Data Melihat isi data dan struktur data
head(data)
## X airline flight source_city departure_time stops arrival_time
## 1 0 SpiceJet SG-8709 Delhi Evening zero Night
## 2 1 SpiceJet SG-8157 Delhi Early_Morning zero Morning
## 3 2 AirAsia I5-764 Delhi Early_Morning zero Early_Morning
## 4 3 Vistara UK-995 Delhi Morning zero Afternoon
## 5 4 Vistara UK-963 Delhi Morning zero Morning
## 6 5 Vistara UK-945 Delhi Morning zero Afternoon
## destination_city class duration days_left price
## 1 Mumbai Economy 2.17 1 5953
## 2 Mumbai Economy 2.33 1 5953
## 3 Mumbai Economy 2.17 1 5956
## 4 Mumbai Economy 2.25 1 5955
## 5 Mumbai Economy 2.33 1 5955
## 6 Mumbai Economy 2.33 1 5955
str(data)
## 'data.frame': 300153 obs. of 12 variables:
## $ X : int 0 1 2 3 4 5 6 7 8 9 ...
## $ airline : chr "SpiceJet" "SpiceJet" "AirAsia" "Vistara" ...
## $ flight : chr "SG-8709" "SG-8157" "I5-764" "UK-995" ...
## $ source_city : chr "Delhi" "Delhi" "Delhi" "Delhi" ...
## $ departure_time : chr "Evening" "Early_Morning" "Early_Morning" "Morning" ...
## $ stops : chr "zero" "zero" "zero" "zero" ...
## $ arrival_time : chr "Night" "Morning" "Early_Morning" "Afternoon" ...
## $ destination_city: chr "Mumbai" "Mumbai" "Mumbai" "Mumbai" ...
## $ class : chr "Economy" "Economy" "Economy" "Economy" ...
## $ duration : num 2.17 2.33 2.17 2.25 2.33 2.33 2.08 2.17 2.17 2.25 ...
## $ days_left : int 1 1 1 1 1 1 1 1 1 1 ...
## $ price : int 5953 5953 5956 5955 5955 5955 6060 6060 5954 5954 ...
#Eksplorisasi Data
#melihat informasi singkat dari data
summary(data)
## X airline flight source_city
## Min. : 0 Length:300153 Length:300153 Length:300153
## 1st Qu.: 75038 Class :character Class :character Class :character
## Median :150076 Mode :character Mode :character Mode :character
## Mean :150076
## 3rd Qu.:225114
## Max. :300152
## departure_time stops arrival_time destination_city
## Length:300153 Length:300153 Length:300153 Length:300153
## Class :character Class :character Class :character Class :character
## Mode :character Mode :character Mode :character Mode :character
##
##
##
## class duration days_left price
## Length:300153 Min. : 0.83 Min. : 1 Min. : 1105
## Class :character 1st Qu.: 6.83 1st Qu.:15 1st Qu.: 4783
## Mode :character Median :11.25 Median :26 Median : 7425
## Mean :12.22 Mean :26 Mean : 20890
## 3rd Qu.:16.17 3rd Qu.:38 3rd Qu.: 42521
## Max. :49.83 Max. :49 Max. :123071
##1. Bar Chart Melakukan eksplorasi data dengan menggunakan visualisasi data, bar chart.
install.packages("ggplot2")
## Warning: package 'ggplot2' is in use and will not be installed
library(ggplot2)
###1. data airline dari eksplorasi yang dilakukan, didapati bahwa maskapai Vistara memiliki jumlah penerbangan terbanyak diikuti Air india dan AirAsia, sementara Spicejet menjadi maskapai dengan jumlah penerbangan terendah
ggplot(data, aes(x = airline, fill = airline)) +
geom_bar() +
labs(title = "Jumlah Penerbangan per Maskapai",
x = "Maskapai",
y = "Jumlah Penerbangan") +
theme_minimal() +
theme(
plot.title = element_text(hjust = 0.5, size = 14, face = "bold"), # Judul ke tengah
axis.text.x = element_text(angle = 45, hjust = 1) # Memiringkan label
) +
scale_y_continuous(labels = function(x) format(x, big.mark = ".", scientific = FALSE))
## Warning in prettyNum(.Internal(format(x, trim, digits, nsmall, width, 3L, :
## 'big.mark' and 'decimal.mark' are both '.', which could be confusing
###2. data kota keberangkatan dari eksplorasi yang dilakukan menggunakan
data source_city, kota Mumbai memiliki jumlah keberangkatan terbanyak
disusul Delhi dan Banglore, sementara chennai memiliki jumlah
keberangkatan terendah.
ggplot(data, aes(x = source_city, fill = source_city)) +
geom_bar() +
labs(title = "Jumlah Keberangkatan per Kota Asal",
x = "Kota",
y = "Jumlah Keberangkatan") +
theme_minimal() +
theme(
plot.title = element_text(hjust = 0.5, size = 14, face = "bold"), # Judul ke tengah
axis.text.x = element_text(angle = 45, hjust = 1) # Memiringkan label
) +
scale_y_continuous(labels = function(x) format(x, big.mark = ".", scientific = FALSE))
## Warning in prettyNum(.Internal(format(x, trim, digits, nsmall, width, 3L, :
## 'big.mark' and 'decimal.mark' are both '.', which could be confusing
###3. data kota kedatangan dari eksplorasi data yang dilakukan
menggunakan destination_city, kota mumbai menjadi kota dengan jumlah
kedatangan tertinggi, disusul dengan kota Delhi dan kota Banglore,
sementara kota Chennai menjadi kota dengan jumlah kedatangan
terendah.
ggplot(data, aes(x = destination_city, fill = destination_city)) +
geom_bar() +
labs(title = "Jumlah Kedatangan per Kota Asal",
x = "Kota",
y = "Jumlah Kedatangan") +
theme_minimal() +
theme(
plot.title = element_text(hjust = 0.5, size = 14, face = "bold"), # Judul ke tengah
axis.text.x = element_text(angle = 45, hjust = 1) # Memiringkan label
) +
scale_y_continuous(labels = function(x) format(x, big.mark = ".", scientific = FALSE))
## Warning in prettyNum(.Internal(format(x, trim, digits, nsmall, width, 3L, :
## 'big.mark' and 'decimal.mark' are both '.', which could be confusing
##2. Pie chart ###1. Data waktu keberangkatan Proporsi waktu
keberangkatan
# Hitung jumlah penerbangan per waktu keberangkatan dan persentasenya
data_freq <- as.data.frame(table(data$departure_time))
colnames(data_freq) <- c("departure_time", "count")
data_freq$percent <- round(100 * data_freq$count / sum(data_freq$count), 1) # Hitung persen
# Plot pie chart dengan persentase
ggplot(data_freq, aes(x = "", y = count, fill = departure_time)) +
geom_bar(width = 1, stat = "identity") +
coord_polar("y", start = 0) + # Ubah menjadi pie chart
labs(title = "Proporsi Waktu Keberangkatan") +
theme_minimal() +
theme(
plot.title = element_text(hjust = 0.5, size = 14, face = "bold"), # Judul di tengah
axis.text.x = element_blank(), # Hilangkan teks sumbu X
axis.ticks = element_blank(), # Hilangkan tanda sumbu
panel.grid = element_blank() # Hilangkan grid background
) +
geom_text(aes(label = paste0(percent, "%")),
position = position_stack(vjust = 0.5),
size = 4, color = "white") # Tambahkan label persentase
###2. Data waktu kedatangan Proporsi waktu kedatangan
# Hitung jumlah penerbangan per waktu kedatangan dan persentasenya
data_freq <- as.data.frame(table(data$arrival_time))
colnames(data_freq) <- c("arrival_time", "count")
data_freq$percent <- round(100 * data_freq$count / sum(data_freq$count), 1) # Menghitung persen
# Plot pie chart dengan persentase
ggplot(data_freq, aes(x = "", y = count, fill = arrival_time)) +
geom_bar(width = 1, stat = "identity") +
coord_polar("y", start = 0) + # Ubah menjadi pie chart
labs(title = "Proporsi Waktu Kedatangan") + # Membuat Judul
theme_minimal() +
theme(
plot.title = element_text(hjust = 0.5, size = 14, face = "bold"), # Judul di tengah
axis.text.x = element_blank(), # Hilangkan teks sumbu X
axis.ticks = element_blank(), # Hilangkan tanda sumbu
panel.grid = element_blank() # Hilangkan grid background
) +
geom_text(aes(label = paste0(percent, "%")),
position = position_stack(vjust = 0.5),
size = 4, color = "white") # Tambahkan label persentase
###3.Data kelas penerbangan Proporsi kelas per penerbangan
# Hitung jumlah penerbangan per waktu kedatangan dan persentasenya
data_freq <- as.data.frame(table(data$class))
colnames(data_freq) <- c("class", "count")
data_freq$percent <- round(100 * data_freq$count / sum(data_freq$count), 1) # Menghitung persen
# Plot pie chart dengan persentase
ggplot(data_freq, aes(x = "", y = count, fill = class)) +
geom_bar(width = 1, stat = "identity") +
coord_polar("y", start = 0) + # Ubah menjadi pie chart
labs(title = "Proporsi Kelas") + # Membuat Judul
theme_minimal() +
theme(
plot.title = element_text(hjust = 0.5, size = 14, face = "bold"), # Judul di tengah
axis.text.x = element_blank(), # Hilangkan teks sumbu X
axis.ticks = element_blank(), # Hilangkan tanda sumbu
panel.grid = element_blank() # Hilangkan grid background
) +
geom_text(aes(label = paste0(percent, "%")),
position = position_stack(vjust = 0.5),
size = 4, color = "white") # Tambahkan label persentase
##3. Eksplorasi Data Numerik Eksplorasi yang dipilih adalah eksplorasi
pada data biaya penerbangan
install.packages("dplyr")
## Warning: package 'dplyr' is in use and will not be installed
library(dplyr)
# Memisahkan data biaya pada kelas Ekonomi dan kelas Bisnis
Ekonomi <- data %>% filter(class == "Economy")
Bisnis <- data %>% filter(class == "Business")
###1. rata-rata biaya masing-masing kelas
r_ekonomi <- mean(Ekonomi$price)
r_bisnis <- mean(Bisnis$price)
r_ekonomi
## [1] 6572.342
r_bisnis
## [1] 52540.08
###2. Simpangan baku dari biaya masing-masing kelas
sd_ekonomi <- sd(Ekonomi$price)
sd_bisnis <- sd(Bisnis$price)
sd_ekonomi
## [1] 3743.52
sd_bisnis
## [1] 12969.31
###3. Melihat sebaran data melihat sebaran data dengan menggunakan histogram
hist(Ekonomi$price, main="Histogram Harga Ekonomi", xlab="Harga", col="blue")
hist(Bisnis$price, main="Histogram Harga Bisnis", xlab="Harga", col="red")