Input Data

data <- read.csv("C:/Users/mhdha/Downloads/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.

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

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
# 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

histogram_ekonomi <- hist(Ekonomi$price)

histogram_bisnis <- hist(Bisnis$price)

histogram_ekonomi
## $breaks
##  [1]     0  2000  4000  6000  8000 10000 12000 14000 16000 18000 20000 22000
## [13] 24000 26000 28000 30000 32000 34000 36000 38000 40000 42000 44000
## 
## $counts
##  [1]  5046 39368 69987 44525 14728 13304  9211  4782  2575  1261   865   465
## [13]   290   108    71    53    14     7     4     0     1     1
## 
## $density
##  [1] 1.220810e-05 9.524547e-05 1.693239e-04 1.077221e-04 3.563237e-05
##  [6] 3.218720e-05 2.228475e-05 1.156939e-05 6.229859e-06 3.050816e-06
## [11] 2.092749e-06 1.125004e-06 7.016152e-07 2.612912e-07 1.717747e-07
## [16] 1.282262e-07 3.387108e-08 1.693554e-08 9.677451e-09 0.000000e+00
## [21] 2.419363e-09 2.419363e-09
## 
## $mids
##  [1]  1000  3000  5000  7000  9000 11000 13000 15000 17000 19000 21000 23000
## [13] 25000 27000 29000 31000 33000 35000 37000 39000 41000 43000
## 
## $xname
## [1] "Ekonomi$price"
## 
## $equidist
## [1] TRUE
## 
## attr(,"class")
## [1] "histogram"
histogram_bisnis
## $breaks
##  [1]  10000  15000  20000  25000  30000  35000  40000  45000  50000  55000
## [11]  60000  65000  70000  75000  80000  85000  90000  95000 100000 105000
## [21] 110000 115000 120000 125000
## 
## $counts
##  [1]    70   492  3151  2191  2885  5581  8616 11143 20325 13138 13293  6326
## [13]  2783  1413  1158   461   239   114    60    29    15     3     1
## 
## $density
##  [1] 1.497534e-07 1.052553e-06 6.741044e-06 4.687283e-06 6.171981e-06
##  [6] 1.193963e-05 1.843251e-05 2.383861e-05 4.348198e-05 2.810658e-05
## [11] 2.843818e-05 1.353343e-05 5.953769e-06 3.022880e-06 2.477350e-06
## [16] 9.862334e-07 5.113010e-07 2.438842e-07 1.283601e-07 6.204071e-08
## [21] 3.209002e-08 6.418005e-09 2.139335e-09
## 
## $mids
##  [1]  12500  17500  22500  27500  32500  37500  42500  47500  52500  57500
## [11]  62500  67500  72500  77500  82500  87500  92500  97500 102500 107500
## [21] 112500 117500 122500
## 
## $xname
## [1] "Bisnis$price"
## 
## $equidist
## [1] TRUE
## 
## attr(,"class")
## [1] "histogram"