Tổng quan nghiên cứu

Định nghĩa về sự hài lòng của trải nghiệm khách hàng, VD sự hài lòng c

Mục tiêu bài nghiên cứu

Mục tiêu của của bài nghiên cứu lần này chúng tôi sẽ đánh giá mức độ hài lòng của hành khách trong ngành hàng không dựa trên bộ dữ liệu về sự hài lòng của hành khách. Nghiên cứu tập trung vào các yếu tố như giới tính, độ tuổi, loại khách hàng, loại hình du lịch, độ trễ xuất phát và đến, khoảng cách bay, và các tiện ích liên quan đến thời gian. Mục đích là phân tích mối quan hệ giữa các yếu tố này và mức độ hài lòng của hành khách, từ đó đưa ra những nhận định và đề xuất cải thiện để nâng cao trải nghiệm của hành khách trong quá trình sử dụng dịch vụ hàng không

Giới thiệu bộ dữ liệu Airline Passenger Satisfaction

Để trình bày một cách rõ ràng và dễ hiểu trước khi phân tích, chúng tôi sẽ giới thiệu bộ dữ liệu “Airline Passenger Satisfaction”, được thu thập từ trang Kaggle. Bộ dữ liệu này bao gồm các thông tin và biến số sau đây để mọi người có thể dễ dàng có cái nhìn tổng quát hơn:

Bộ dữ liệu Airline Passenger Satisfaction cung cấp một số thông tin về điểm hài lòng của khách hàng từ hơn 120.000 hành khách đi máy bay, bao gồm thông tin bổ sung về từng hành khách, chuyến bay và loại hình di chuyển của họ, cũng như đánh giá các yếu tố khác nhau như độ sạch sẽ, sự thoải mái, dịch vụ và trải nghiệm tổng thể. Dựa vào những thông tin này chúng tôi có thể phân tích các mức độ về sự trải nghiệm của hành khách hàng không khi đi máy bay.

Mô tả đặc trưng dữ liệu

• ID (id): Định danh duy nhất cho từng hành khách

• Gender (gender): Giới tính của hành khách, “Male” (Nam) hoặc “Female” (Nữ).

• Age (age): Số tuổi của hành khách khi họ sử dụng dịch vụ hàng không.

• Customer Type (type of customer): xác định Loại khách hàng được phân thành Loyal Customer và Disloyal Customer

• Type of Travel (type of travel): Mô tả loại hình du lịch mà hành khách thực hiện chủ yếu, Business(việc kinh doanh) và Personal (riêng tư).

• Class (class): Mô tả hạng ghế trên máy bay mà hành khách sử dụng,

• Flight Distance (distance): Cho biết khoảng cách của các chuyến bay

• Departure Delay (delay): Thời gian chậm xuất phát của chuyến bay

• Arrival Delay (arrival delay): Thời gian đến của chuyên bay

• Departure and Arrival Time Convenience (dep and arr): Sự thuận tiện về thời gian xuất phát và đến của chuyến bay

AL <- read.csv("~/Downloads/archive-16/test.csv")
View(AL)

Bảng tần số - tần suất

str(AL)
## 'data.frame':    25976 obs. of  25 variables:
##  $ X                                : int  0 1 2 3 4 5 6 7 8 9 ...
##  $ id                               : int  19556 90035 12360 77959 36875 39177 79433 97286 27508 62482 ...
##  $ Gender                           : chr  "Female" "Female" "Male" "Male" ...
##  $ Customer.Type                    : chr  "Loyal Customer" "Loyal Customer" "disloyal Customer" "Loyal Customer" ...
##  $ Age                              : int  52 36 20 44 49 16 77 43 47 46 ...
##  $ Type.of.Travel                   : chr  "Business travel" "Business travel" "Business travel" "Business travel" ...
##  $ Class                            : chr  "Eco" "Business" "Eco" "Business" ...
##  $ Flight.Distance                  : int  160 2863 192 3377 1182 311 3987 2556 556 1744 ...
##  $ Inflight.wifi.service            : int  5 1 2 0 2 3 5 2 5 2 ...
##  $ Departure.Arrival.time.convenient: int  4 1 0 0 3 3 5 2 2 2 ...
##  $ Ease.of.Online.booking           : int  3 3 2 0 4 3 5 2 2 2 ...
##  $ Gate.location                    : int  4 1 4 2 3 3 5 2 2 2 ...
##  $ Food.and.drink                   : int  3 5 2 3 4 5 3 4 5 3 ...
##  $ Online.boarding                  : int  4 4 2 4 1 5 5 4 5 4 ...
##  $ Seat.comfort                     : int  3 5 2 4 2 3 5 5 5 4 ...
##  $ Inflight.entertainment           : int  5 4 2 1 2 5 5 4 5 4 ...
##  $ On.board.service                 : int  5 4 4 1 2 4 5 4 2 4 ...
##  $ Leg.room.service                 : int  5 4 1 1 2 3 5 4 2 4 ...
##  $ Baggage.handling                 : int  5 4 3 1 2 1 5 4 5 4 ...
##  $ Checkin.service                  : int  2 3 2 3 4 1 4 5 3 5 ...
##  $ Inflight.service                 : int  5 4 2 1 2 2 5 4 3 4 ...
##  $ Cleanliness                      : int  5 5 2 4 4 5 3 3 5 4 ...
##  $ Departure.Delay.in.Minutes       : int  50 0 0 0 0 0 0 77 1 28 ...
##  $ Arrival.Delay.in.Minutes         : num  44 0 0 6 20 0 0 65 0 14 ...
##  $ satisfaction                     : chr  "satisfied" "satisfied" "neutral or dissatisfied" "satisfied" ...

Thống kê mô tả cho biến GENDER

Đầu tiên, chúng tôi sẽ lập bảng tần số cho biến Gender nhằm mục đích để nắm bắt được số lượng giới thích của hàng khách khi sự dụng dịch vụ hàng không.

table(AL$Gender)
## 
## Female   Male 
##  13172  12804
library(DT)
datatable(AL)
## Warning in instance$preRenderHook(instance): It seems your data is too big for
## client-side DataTables. You may consider server-side processing:
## https://rstudio.github.io/DT/server.html
table(AL$Gender)/sum(table(AL$Gender))
## 
##    Female      Male 
## 0.5070835 0.4929165

Dựa vào kết quả bảng tần số và biểu đồ trên ta có thể thấy: Phân bố giới tính trong bộ dữ liệu “Airline Passenger Satisfaction” cho thấy sự cân bằng tương đối giữa số lượng hành khách nữ 13,172 (50.71%) và nam 12,804 (49.29%). Sự chênh lệch nhỏ này (nữ chỉ hơn nam khoảng 1.42%) cho thấy rằng cả hai giới tính đều được đại diện gần như đồng đều trong bộ dữ liệu, tạo điều kiện thuận lợi cho việc phân tích mức độ hài lòng một cách khách quan và công bằng.

library(ggplot2)
AL |> ggplot(aes(Gender)) +
  geom_bar()

AL |> ggplot(aes(Gender)) +
  geom_bar(aes(y = (..count..)/sum(..count..), fill = Gender)) +
  ylab('Tỷ lệ %') + 
  xlab('Giới tính') +
  scale_fill_manual(values = c('blue', 'red'))
## Warning: The dot-dot notation (`..count..`) was deprecated in ggplot2 3.4.0.
## ℹ Please use `after_stat(count)` instead.
## This warning is displayed once every 8 hours.
## Call `lifecycle::last_lifecycle_warnings()` to see where this warning was
## generated.

Thống kê mô tả cho biến Customer.Type

table(AL$Customer.Type)
## 
## disloyal Customer    Loyal Customer 
##              4799             21177

Thống kê mô tả cho biến Age

Biến Age thể hiện độ tuổi của hàng khách tham gia máy bây. Bây giờ chúng tôi sẽ lập bảng tần số để thể hiện rõ số tuổi cho khách hàng.

table(AL$Age)
## 
##   7   8   9  10  11  12  13  14  15  16  17  18  19  20  21  22  23  24  25  26 
## 123 157 167 139 159 159 173 153 188 257 241 245 206 358 395 580 589 558 713 533 
##  27  28  29  30  31  32  33  34  35  36  37  38  39  40  41  42  43  44  45  46 
## 595 441 503 491 400 358 483 445 475 548 565 557 723 635 633 560 626 622 600 562 
##  47  48  49  50  51  52  53  54  55  56  57  58  59  60  61  62  63  64  65  66 
## 559 580 563 502 503 540 473 535 473 452 475 448 462 418 239 228 186 190 196 191 
##  67  68  69  70  71  72  73  74  75  76  77  78  79  80  85 
## 163 175 153 149  20  48  16  14  15  15  19  11  10  32   8

Độ tuổi của hàng khách khi tham gia máy bay rất đa dạng với mộ số lượng lớn hàng khách nằm trong độ tuổi từ 20 đến 40, đặc biệt là các độ tuổi 25 (713 người), 22(589 người), và 21(580 người). Ngoài ra còn các các hàng khách ở độ tuổi 40 (635 người); 39 tuổi (723 người); 60 tuổi (418 người).

table(AL$Age)/sum(table(AL$Age))
## 
##            7            8            9           10           11           12 
## 0.0047351401 0.0060440407 0.0064290114 0.0053510933 0.0061210348 0.0061210348 
##           13           14           15           16           17           18 
## 0.0066599938 0.0058900524 0.0072374500 0.0098937481 0.0092777949 0.0094317832 
##           19           20           21           22           23           24 
## 0.0079303973 0.0137819526 0.0152063443 0.0223283030 0.0226747767 0.0214813674 
##           25           26           27           28           29           30 
## 0.0274484139 0.0205189406 0.0229057592 0.0169772097 0.0193640283 0.0189020634 
##           31           32           33           34           35           36 
## 0.0153988297 0.0137819526 0.0185940868 0.0171311980 0.0182861103 0.0210963967 
##           37           38           39           40           41           42 
## 0.0217508469 0.0214428703 0.0278333847 0.0244456421 0.0243686480 0.0215583616 
##           43           44           45           46           47           48 
## 0.0240991685 0.0239451802 0.0230982445 0.0216353557 0.0215198645 0.0223283030 
##           49           50           51           52           53           54 
## 0.0216738528 0.0193255313 0.0193640283 0.0207884201 0.0182091161 0.0205959347 
##           55           56           57           58           59           60 
## 0.0182091161 0.0174006775 0.0182861103 0.0172466893 0.0177856483 0.0160917770 
##           61           62           63           64           65           66 
## 0.0092008007 0.0087773329 0.0071604558 0.0073144441 0.0075454265 0.0073529412 
##           67           68           69           70           71           72 
## 0.0062750231 0.0067369880 0.0058900524 0.0057360641 0.0007699415 0.0018478596 
##           73           74           75           76           77           78 
## 0.0006159532 0.0005389590 0.0005774561 0.0005774561 0.0007314444 0.0004234678 
##           79           80           85 
## 0.0003849707 0.0012319064 0.0003079766
# Giả sử dữ liệu được lưu trong một data frame có tên 'df'
 AL<- data.frame(
  Age = c(7:80, 85),
  Percentage = c(0.0047351, 0.0060440, 0.0064290, 0.0053511, 0.0061210, 0.0061210, 0.0066600, 0.0058901, 0.0072374, 0.0098937, 0.0092778, 0.0094318, 0.0079304, 0.0137820, 0.0152063, 0.0223283, 0.0226748, 0.0214814, 0.0274484, 0.0205189, 0.0229058, 0.0169772, 0.0193640, 0.0189021, 0.0153988, 0.0137820, 0.0185941, 0.0171312, 0.0182861, 0.0210964, 0.0217508, 0.0214429, 0.0278334, 0.0244456, 0.0243686, 0.0215584, 0.0240992, 0.0239452, 0.0230982, 0.0216354, 0.0215199, 0.0223283, 0.0216739, 0.0193255, 0.0193640, 0.0207884, 0.0182091, 0.0205959, 0.0182091, 0.0174007, 0.0182861, 0.0172467, 0.0177856, 0.0160918, 0.0092008, 0.0087773, 0.0071605, 0.0073144, 0.0075454, 0.0073529, 0.0062750, 0.0067370, 0.0058901, 0.0057361, 0.0007699, 0.0018479, 0.0006160, 0.0005390, 0.0005775, 0.0005775, 0.0007314, 0.0004235, 0.0003850, 0.0012319, 0.0003080)
)

library(ggplot2)
library(scales)

# Vẽ biểu đồ
ggplot(AL, aes(x = Age, y = Percentage)) +
  geom_bar(stat = "identity", fill = "#4c78a8") +
  labs(x = "Độ tuổi", y = "Tỷ lệ %", 
       title = "Biểu đồ tỷ lệ độ tuổi",
       subtitle = "Dữ liệu cập nhật đến tháng 8 năm 2023") +
  scale_y_continuous(labels = scales::percent) +
  theme_minimal() +
  theme(
    plot.title = element_text(size = 16, face = "bold"),
    plot.subtitle = element_text(size = 12, color = "grey50"),
    axis.title = element_text(size = 14),
    axis.text = element_text(size = 12)
  )

Biểu đồ cho chúng ta thấy sự đa dạng về độ tuổi, với phần lớn hành khách tập trung trong độ tuổi từ 20 đến 40, đặc biệt đỉnh cao nhất ở tuổi 25. Tỷ lệ hành khách giảm dần từ khoảng 45 tuổi trở đi, với nhóm tuổi trên 60 và dưới 16 có tỷ lệ thấp hơn đáng kể. Nhóm trẻ (dưới 20) chiếm khoảng 7-10% tổng số hành khách. Phân bố này giúp điều chỉnh dịch vụ và chiến lược kinh doanh phù hợp hơn với từng nhóm tuổi.

# Chia dữ liệu thành các nhóm tuổi
AL$AgeGroup <- cut(AL$Age, breaks = c(0, 20, 40, 60, 80, 100), 
                  labels = c("0-20", "21-40", "s41-60", "61-80", "81-100"))

# Vẽ biểu đồ
ggplot(AL, aes(x = AgeGroup, y = Percentage)) +
  geom_bar(stat = "identity", fill = "#4c78a8") +
  labs(x = "Nhóm tuổi", y = "Tỷ lệ", 
       title = "Biểu đồ tỷ lệ độ tuổi",
       subtitle = "Dữ liệu cập nhật đến tháng 8 năm 2023") +
  theme_minimal() +
  theme(
    plot.title = element_text(size = 16, face = "bold"),
    plot.subtitle = element_text(size = 12, color = "grey50"),
    axis.title = element_text(size = 14),
    axis.text = element_text(size = 12)
  )

Thống kê mô tả cho biến Type.of.Travel

Việc mô tả loại hình du lịch mà hành khách thực hiện chủ yếu rất quan trọng, giúp cho chúng ta có thể hiểu rõ về hàng khách hơn. Như việc khách dùng dịch vụ dịch chuyển nhầm mục đích gì?

Nên bây giờ chúng tôi sẽ vẽ biểu đồ thống kê xem khách hàng tham gia dịch vụ nhắm mục đích làm việc gì

table(AL$Type.of.Travel)
## < table of extent 0 >
table(AL$Type.of.Travel)/sum(table(AL$Type.of.Travel))
## numeric(0)
# Tạo dữ liệu
AL<- data.frame(
  Indicator = c("Business Travel", "Personal Travel"),
  Value = c(18038, 7938)
)

# Vẽ biểu đồ
ggplot(AL, aes(x = Indicator, y = Value, fill = Indicator)) +
  geom_bar(stat = "identity", position = "dodge") +
  labs(
    x = "", y = "Số lượng",
    title = "Biểu đồ Business Travel và Personal Travel",
    
  ) +
  scale_y_continuous(labels = comma) +
  theme_minimal() +
  theme(
    plot.title = element_text(size = 16, face = "bold"),
    plot.subtitle = element_text(size = 12, color = "grey50"),
    axis.title = element_text(size = 14),
    axis.text = element_text(size = 12),
    legend.title = element_blank(),
    legend.position = "top"
  )

Biểu đồ cho thấy số lượng hành khách đi công tác (Business Travel) nhiều hơn gấp đôi so với hành khách đi du lịch cá nhân (Personal Travel).

Điều này cho thấy rằng hành khách sử dụng dịch vụ của hãng hàng không chủ yếu vì mục đích công việc hơn là giải trí hoặc du lịch.Thông tin này có thể hướng dẫn cho doanh nghiệp hàng không về việc phát triển và tối ưu hóa dịch vụ, tiếp thị và chiến lược phân phối. Các chính sách khuyến mãi, dịch vụ chăm sóc khách hàng và lựa chọn các tuyến bay có thể được điều chỉnh để phù hợp với nhu cầu chủ yếu của khách hàng là đi công tác.

Chẳng hạn, cung cấp các dịch vụ và tiện ích phù hợp với nhu cầu cụ thể của hành khách đi công tác như wifi, dịch vụ chăm sóc khách hàng trong khi họ đang bận công việc

Thống kê mô tả cho biến Class

table(AL$"Class")
## < table of extent 0 >
table(AL$Class)/sum(table(AL$Class))
## numeric(0)
# Tạo dữ liệu
AL <- data.frame(
  Class = c("Business", "Eco", "Eco Plus"),
  Value = c(12495, 11564, 1917)
)

# Vẽ biểu đồ
ggplot(AL, aes(x = Class, y = Value, fill = Class)) +
  geom_bar(stat = "identity", position = "dodge") +
  labs(
    x = "", y = "Số lượng",
    title = "Phân bố các hạng vé trong Business Travel",
    subtitle = "Dữ liệu cập nhật đến tháng 8 năm 2023"
  ) +
  scale_y_continuous(labels = comma) +
  theme_minimal() +
  theme(
    plot.title = element_text(size = 16, face = "bold"),
    plot.subtitle = element_text(size = 12, color = "grey50"),
    axis.title = element_text(size = 14),
    axis.text = element_text(size = 12),
    legend.title = element_blank(),
    legend.position = "top"
  )

# Thống kê mô tả cho biến Satisfaction

table(AL$satisfaction)
## < table of extent 0 >
table(AL$satisfaction)/sum(table(AL$satisfaction))
## numeric(0)
# Assuming the data is in a data frame named 'df'
AL <- data.frame(
AL = c("neutral or dissatisfied", "satisfied"),
  count = c(14573, 11403)
)

# Calculate the total count
total_count <- sum(AL$count)

# Calculate the percentage for each category
AL$percentage <- round(AL$count / total_count * 100, 2)

# Plot the bar chart with percentages
barplot(AL$count, 
        names.arg = paste(AL$satisfaction, "\n", AL$percentage, "%"),
        col = c("lightblue", "lightgreen"),
        main = "Distribution of Satisfaction Levels",
        xlab = "Satisfaction Level",
        ylab = "Count")

table(AL$Inflight.wifi.service)/sum(table(AL$Inflight.wifi.service))
## numeric(0)
# Dữ liệu
labels <- c("Không đánh giá","Rất tệ", "Tệ", "Bình thường", "Hài lòng", "Rất hài lòng")
values <- c(0.0313, 0.1728, 0.2498, 0.2432, 0.1918, 0.1111)
variable_name <- "Inflight.wifi.service"

# Tính tổng giá trị
total <- sum(values)

# Tính phần trăm cho mỗi mức độ
percentages <- values / total * 100

# Tạo dataframe
df <- data.frame(labels, values, percentages)

# Vẽ biểu đồ cột
library(ggplot2)
ggplot(df, aes(x = labels, y = percentages)) +
  geom_col(fill = '#4c72b0') +
  geom_text(aes(label = sprintf("%.2f%%", percentages)), vjust = -0.5, size = 4) +
  labs(x = "Mức độ đánh giá", y = "Phần trăm", title = paste0("Phân bố các mức độ đánh giá cho ", variable_name)) +
  theme_minimal() +
  theme(axis.text.x = element_text(angle = 45, hjust = 1))

# Dữ liệu
labels <- c("Không đánh giá","Rất tệ", "Tệ", "Bình thường", "Hài lòng", "Rất hài lòng")
values <- c(0.05316, 0.15056, 0.16719, 0.16985, 0.24384, 0.21539)
variable_name <- "Departure.Arrival.time.convenient"

# Tính tổng giá trị
total <- sum(values)

# Tính phần trăm cho mỗi mức độ
percentages <- values / total * 100

# Tạo dataframe
df <- data.frame(labels, values , percentages)

# Vẽ biểu đồ cột
library(ggplot2)
ggplot(df, aes(x = labels, y = percentages)) +
  geom_col(fill = '#4c72b0') +
  geom_text(aes(label = sprintf("%.2f%%", percentages)), vjust = -0.5, size = 4) +
  labs(x = "Mức độ đánh giá", y = "Phần trăm", title = "Phân bố các mức độ đánh giá cho", variable_name) +
  theme_minimal() +
  theme(axis.text.x = element_text(angle = 45, hjust = 1))

table(AL$Ease.of.Online.booking)/sum(table(AL$Ease.of.Online.booking))
## numeric(0)
# Dữ liệu
labels <- c("Không đánh giá","Rất tệ", "Tệ", "Bình thường", "Hài lòng", "Rất hài lòng")
values <- c(0.0460, 0.1679, 0.2321, 0.2288, 0.1876, 0.1376 )
variable_name <- "Ease.of.Online.booking"

# Tính toán tổng giá trị
total <- sum(values)

# Tính phần trăm cho mỗi mức độ
percentages <- values / total * 100

# Tạo dataframe
df <- data.frame(labels, values, percentages)

# Vẽ biểu đồ cột
library(ggplot2)
ggplot(df, aes(x = labels, y = percentages)) +
  geom_col(fill = '#4c72b0') +
  geom_text(aes(label = sprintf("%.2f%%", percentages)), vjust = -0.5, size = 4) +
  labs(x = "Mức độ đánh giá", y = "Phần trăm", title = paste0("Phân bố các mức độ đánh giá cho ", variable_name)) +
  theme_minimal() +
  theme(axis.text.x = element_text(angle = 45, hjust = 1))

table(AL$Gate.location)/sum(table(AL$Gate.location))
## numeric(0)
# Dữ liệu
labels <- c("Không đánh giá","Rất tệ", "Tệ", "Bình thường", "Hài lòng", "Rất hài lòng")
values <- c(0,0.1705, 0.1862, 0.2749, 0.2325, 0.1359)
variable_name <- "Gate.location"

# Tính toán tổng giá trị
total <- sum(values)

# Tính phần trăm cho mỗi mức độ
percentages <- values / total * 100

# Tạo dataframe
df <- data.frame(labels, values, percentages)

# Vẽ biểu đồ cột
library(ggplot2)
ggplot(df, aes(x = labels, y = percentages)) +
  geom_col(fill = '#4c72b0') +
  geom_text(aes(label = sprintf("%.2f%%", percentages)), vjust = -0.5, size = 4) +
  labs(x = "Mức độ đánh giá", y = "Phần trăm", title = paste0("Phân bố các mức độ đánh giá cho ", variable_name)) +
  theme_minimal() +
  theme(axis.text.x = element_text(angle = 45, hjust = 1))

table(AL$Food.and.drink)/sum(table(AL$Food.and.drink))
## numeric(0)
# Dữ liệu
labels <- c("Không đánh giá","Rất tệ", "Tệ", "Bình thường", "Hài lòng", "Rất hài lòng")
values <- c(0.0009624, 0.1237296, 0.2076917, 0.2115029, 0.2388358, 0.2172775)
variable_name <- "Food.and.drink"

# Tính toán tổng giá trị
total <- sum(values)

# Tính phần trăm cho mỗi mức độ
percentages <- values / total * 100

# Tạo dataframe
df <- data.frame(labels, values, percentages)

# Vẽ biểu đồ cột
library(ggplot2)
ggplot(df, aes(x = labels, y = percentages)) +
  geom_col(fill = '#4c72b0') +
  geom_text(aes(label = sprintf("%.2f%%", percentages)), vjust = -0.5, size = 4) +
  labs(x = "Mức độ đánh giá", y = "Phần trăm", title = paste0("Phân bố các mức độ đánh giá cho ", variable_name)) +
  theme_minimal() +
  theme(axis.text.x = element_text(angle = 45, hjust = 1))

table(AL$Online.boarding)/sum(table(AL$Online.boarding))
## numeric(0)
# Dữ liệu
labels <- c("Không đánh giá","Rất tệ", "Tệ", "Bình thường", "Hài lòng", "Rất hài lòng")
values <- c(0.0251, 0.0989, 0.1705, 0.2045, 0.2967, 0.2043 )
variable_name <- "Online.boarding"

# Tính toán tổng giá trị
total <- sum(values)

# Tính phần trăm cho mỗi mức độ
percentages <- values / total * 100

# Tạo dataframe
df <- data.frame(labels, values, percentages)

# Vẽ biểu đồ cột
library(ggplot2)
ggplot(df, aes(x = labels, y = percentages)) +
  geom_col(fill = '#4c72b0') +
  geom_text(aes(label = sprintf("%.2f%%", percentages)), vjust = -0.5, size = 4) +
  labs(x = "Mức độ đánh giá", y = "Phần trăm", title = paste0("Phân bố các mức độ đánh giá cho ", variable_name)) +
  theme_minimal() +
  theme(axis.text.x = element_text(angle = 45, hjust = 1))

table(AL$Seat.comfort)/sum(table(AL$Seat.comfort))
## numeric(0)
# Dữ liệu
labels <- c("Không đánh giá","Rất tệ", "Tệ", "Bình thường", "Hài lòng", "Rất hài lòng")
values <- c(0,0.1168, 0.1398, 0.1783, 0.3076, 0.2575  )
variable_name <- "Seat.comfort"

# Tính toán tổng giá trị
total <- sum(values)

# Tính phần trăm cho mỗi mức độ
percentages <- values / total * 100

# Tạo dataframe
df <- data.frame(labels, values, percentages)

# Vẽ biểu đồ cột
library(ggplot2)
ggplot(df, aes(x = labels, y = percentages)) +
  geom_col(fill = '#4c72b0') +
  geom_text(aes(label = sprintf("%.2f%%", percentages)), vjust = -0.5, size = 4) +
  labs(x = "Mức độ đánh giá", y = "Phần trăm", title = paste0("Phân bố các mức độ đánh giá cho ", variable_name)) +
  theme_minimal() +
  theme(axis.text.x = element_text(angle = 45, hjust = 1))

table(AL$Inflight.entertainment)/sum(table(AL$Inflight.entertainment))
## numeric(0)
# Dữ liệu
labels <- c("Không đánh giá","Rất tệ", "Tệ", "Bình thường", "Hài lòng", "Rất hài lòng")
values <- c(0.000154, 0.123075, 0.166731, 0.182669, 0.283646, 0.243725  )
variable_name <- "Inflight.entertainment"

# Tính toán tổng giá trị
total <- sum(values)

# Tính phần trăm cho mỗi mức độ
percentages <- values / total * 100

# Tạo dataframe
df <- data.frame(labels, values, percentages)

# Vẽ biểu đồ cột
library(ggplot2)
ggplot(df, aes(x = labels, y = percentages)) +
  geom_col(fill = '#4c72b0') +
  geom_text(aes(label = sprintf("%.2f%%", percentages)), vjust = -0.5, size = 4) +
  labs(x = "Mức độ đánh giá", y = "Phần trăm", title = paste0("Phân bố các mức độ đánh giá cho ", variable_name)) +
  theme_minimal() +
  theme(axis.text.x = element_text(angle = 45, hjust = 1))

table(AL$On.board.service)/sum(table(AL$On.board.service))
## numeric(0)
# Dữ liệu
labels <- c("Không đánh giá","Rất tệ", "Tệ", "Bình thường", "Hài lòng", "Rất hài lòng")
values <- c(7.699e-05,1.122e-01,1.413e-01, 2.198e-01, 3.017e-01, 2.250e-01  )
variable_name <- "On.board.service"

# Tính toán tổng giá trị
total <- sum(values)

# Tính phần trăm cho mỗi mức độ
percentages <- values / total * 100

# Tạo dataframe
df <- data.frame(labels, values, percentages)

# Vẽ biểu đồ cột
library(ggplot2)
ggplot(df, aes(x = labels, y = percentages)) +
  geom_col(fill = '#4c72b0') +
  geom_text(aes(label = sprintf("%.2f%%", percentages)), vjust = -0.5, size = 4) +
  labs(x = "Mức độ đánh giá", y = "Phần trăm", title = paste0("Phân bố các mức độ đánh giá cho ", variable_name)) +
  theme_minimal() +
  theme(axis.text.x = element_text(angle = 45, hjust = 1))

table(AL$Leg.room.service)/sum(table(AL$Leg.room.service))
## numeric(0)
# Dữ liệu
labels <- c("Không đánh giá","Rất tệ", "Tệ", "Bình thường", "Hài lòng", "Rất hài lòng")
values <- c( 0.004851, 0.097860, 0.193063, 0.190868, 0.273214, 0.240145  )
variable_name <- "Leg.room.service"

# Tính toán tổng giá trị
total <- sum(values)

# Tính phần trăm cho mỗi mức độ
percentages <- values / total * 100

# Tạo dataframe
df <- data.frame(labels, values, percentages)

# Vẽ biểu đồ cột
library(ggplot2)
ggplot(df, aes(x = labels, y = percentages)) +
  geom_col(fill = '#4c72b0') +
  geom_text(aes(label = sprintf("%.2f%%", percentages)), vjust = -0.5, size = 4) +
  labs(x = "Mức độ đánh giá", y = "Phần trăm", title = paste0("Phân bố các mức độ đánh giá cho ", variable_name)) +
  theme_minimal() +
  theme(axis.text.x = element_text(angle = 45, hjust = 1))

table(AL$Baggage.handling)/sum(table(AL$Baggage.handling))
## numeric(0)
# Dữ liệu
labels <- c("Không đánh giá","Rất tệ", "Tệ", "Bình thường", "Hài lòng", "Rất hài lòng")
values <- c( 0,0.06895, 0.10937, 0.20092, 0.36103, 0.25974  )
variable_name <- "Baggage.handling"

# Tính toán tổng giá trị
total <- sum(values)

# Tính phần trăm cho mỗi mức độ
percentages <- values / total * 100

# Tạo dataframe
df <- data.frame(labels, values, percentages)

# Vẽ biểu đồ cột
library(ggplot2)
ggplot(df, aes(x = labels, y = percentages)) +
  geom_col(fill = '#4c72b0') +
  geom_text(aes(label = sprintf("%.2f%%", percentages)), vjust = -0.5, size = 4) +
  labs(x = "Mức độ đánh giá", y = "Phần trăm", title = paste0("Phân bố các mức độ đánh giá cho ", variable_name)) +
  theme_minimal() +
  theme(axis.text.x = element_text(angle = 45, hjust = 1))

table(AL$Checkin.service)/sum(table(AL$Checkin.service))
## numeric(0)
# Dữ liệu
labels <- c("Không đánh giá","Rất tệ", "Tệ", "Bình thường", "Hài lòng", "Rất hài lòng")
values <- c( 0,0.1239, 0.1235, 0.2697, 0.2802, 0.2026  )
variable_name <- "Checkin.service"

# Tính toán tổng giá trị
total <- sum(values)

# Tính phần trăm cho mỗi mức độ
percentages <- values / total * 100

# Tạo dataframe
df <- data.frame(labels, values, percentages)

# Vẽ biểu đồ cột
library(ggplot2)
ggplot(df, aes(x = labels, y = percentages)) +
  geom_col(fill = '#4c72b0') +
  geom_text(aes(label = sprintf("%.2f%%", percentages)), vjust = -0.5, size = 4) +
  labs(x = "Mức độ đánh giá", y = "Phần trăm", title = paste0("Phân bố các mức độ đánh giá cho ", variable_name)) +
  theme_minimal() +
  theme(axis.text.x = element_text(angle = 45, hjust = 1))

table(AL$Inflight.service)/sum(table(AL$Inflight.service))
## numeric(0)
# Dữ liệu
labels <- c("Không đánh giá","Rất tệ", "Tệ", "Bình thường", "Hài lòng", "Rất hài lòng")
values <- c( 7.699e-05, 6.845e-02, 1.098e-01, 1.931e-01, 3.610e-01, 2.676e-01   )
variable_name <- "Inflight.service"

# Tính toán tổng giá trị
total <- sum(values)

# Tính phần trăm cho mỗi mức độ
percentages <- values / total * 100

# Tạo dataframe
df <- data.frame(labels, values, percentages)

# Vẽ biểu đồ cột
library(ggplot2)
ggplot(df, aes(x = labels, y = percentages)) +
  geom_col(fill = '#4c72b0') +
  geom_text(aes(label = sprintf("%.2f%%", percentages)), vjust = -0.5, size = 4) +
  labs(x = "Mức độ đánh giá", y = "Phần trăm", title = paste0("Phân bố các mức độ đánh giá cho ", variable_name)) +
  theme_minimal() +
  theme(axis.text.x = element_text(angle = 45, hjust = 1))

table(AL$Cleanliness)/sum(table(AL$Cleanliness))
## numeric(0)
table(AL$Cleanliness)
## < table of extent 0 >
# Dữ liệu
labels <- c("Không đánh giá","Rất tệ", "Tệ", "Bình thường", "Hài lòng", "Rất hài lòng")
values <- c(  7.699e-05, 1.313e-01, 1.533e-01, 2.335e-01 ,2.614e-01, 2.205e-01   )
variable_name <- "Cleaneliness"

# Tính toán tổng giá trị
total <- sum(values)

# Tính phần trăm cho mỗi mức độ
percentages <- values / total * 100

# Tạo dataframe
df <- data.frame(labels, values, percentages)

# Vẽ biểu đồ cột
library(ggplot2)
ggplot(df, aes(x = labels, y = percentages)) +
  geom_col(fill = '#4c72b0') +
  geom_text(aes(label = sprintf("%.2f%%", percentages)), vjust = -0.5, size = 4) +
  labs(x = "Mức độ đánh giá", y = "Phần trăm", title = paste0("Phân bố các mức độ đánh giá cho ", variable_name)) +
  theme_minimal() +
  theme(axis.text.x = element_text(angle = 45, hjust = 1))

DDM <- data.frame(AL$Departure.Delay.in.Minutes,AL$Arrival.Delay.in.Minutes)
summary(DDM)
## < table of extent 0 x 0 >

Thống kê mô tả 2 biến

FM <- table(AL$Customer.Type, AL$Gender )
FM
## < table of extent 0 x 0 >
# Dữ liệu
customer_data <- data.frame(
  Customer_Type = c("Disloyal Customer", "Loyal Customer"),
  Female = c(2574, 10598),
  Male = c(2225, 10579)
)

# Vẽ biểu đồ
library(ggplot2)

ggplot(customer_data, aes(x = Customer_Type, y = Female, fill = "Female")) +
  geom_bar(stat = "identity", position = "dodge") +
  geom_bar(aes(y = Male, fill = "Male"), stat = "identity", position = "dodge") +
  labs(
    title = "Phân bố khách hàng theo giới tính và trạng thái trung thành",
    x = "Trạng thái trung thành",
    y = "Số lượng khách hàng",
    fill = "Giới tính"
  ) +
  theme_minimal() +
  theme(
    plot.title = element_text(hjust = 0.5),
    axis.text.x = element_text(angle = 45, hjust = 1)
  )

FM <- table(AL$Customer.Type, AL$Age )
FM
## < table of extent 0 x 0 >
# Dữ liệu
customer_data <- data.frame(
  Age = c(7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 85),
  Disloyal_Customer = c(1, 22, 25, 18, 21, 17, 20, 25, 33, 66, 64, 66, 36, 189, 189, 308, 292, 305, 361, 270, 297, 133, 154, 121, 30, 42, 71, 86, 106, 146, 168, 133, 152, 92, 58, 61, 59, 62, 55, 28, 30, 41, 46, 38, 8, 20, 0, 30, 19, 16, 24, 20, 19, 3, 11, 26, 3, 10, 10, 6, 0, 4, 3, 2, 1, 8, 1, 0, 1, 0, 2, 0, 3, 9, 3),
  Loyal_Customer = c(122, 135, 142, 121, 138, 142, 153, 128, 155, 191, 177, 179, 170, 169, 206, 272, 297, 253, 352, 263, 298, 308, 349, 370, 370, 316, 412, 359, 369, 402, 397, 424, 571, 543, 575, 499, 567, 560, 545, 534, 529, 539, 517, 464, 495, 520, 473, 505, 454, 436, 451, 428, 443, 415, 228, 202, 183, 180, 186, 185, 163, 171, 150, 147, 19, 40, 15, 14, 14, 15, 17, 11, 7, 23, 5)
)

# Vẽ biểu đồ
library(ggplot2)

ggplot(customer_data, aes(x = Age)) +
  geom_line(aes(y = Disloyal_Customer, color = "Disloyal Customer")) +
  geom_line(aes(y = Loyal_Customer, color = "Loyal Customer")) +
  labs(
    title = "Phân bố khách hàng theo độ tuổi và trạng thái trung thành",
    x = "Độ tuổi",
    y = "Số lượng khách hàng",
    color = "Trạng thái trung thành"
  ) +
  theme_minimal() +
  theme(
    plot.title = element_text(hjust = 0.5),
    axis.text.x = element_text(angle = 45, hjust = 1)
  )

FM <- table(AL$Customer.Type, AL$Type.of.Travel )
FM
## < table of extent 0 x 0 >
# Dữ liệu
customer_data <- data.frame(
  Travel_Type = c("Business travel", "Personal Travel"),
  Disloyal_Customer = c(4762, 37),
  Loyal_Customer = c(13276, 7901)
)

# Vẽ biểu đồ
library(ggplot2)

ggplot(customer_data, aes(x = Travel_Type)) +
  geom_bar(aes(y = Disloyal_Customer, fill = "Disloyal Customer"), stat = "identity", position = "dodge") +
  geom_bar(aes(y = Loyal_Customer, fill = "Loyal Customer"), stat = "identity", position = "dodge") +
  labs(
    title = "Phân bố khách hàng theo loại chuyến đi",
    x = "Loại chuyến đi",
    y = "Số lượng khách hàng",
    fill = "Trạng thái trung thành"
  ) +
  theme_minimal() +
  theme(
    plot.title = element_text(hjust = 0.5),
    axis.text.x = element_text(angle = 45, hjust = 1)
  )

FM <- table(AL$Customer.Type, AL$Class )
FM
## < table of extent 0 x 0 >
# Dữ liệu
customer_data <- data.frame(
  Travel_Type = c("Business", "Eco", "Eco Plus"),
  Disloyal_Customer = c(1875, 2724, 200),
  Loyal_Customer = c(10620, 8840, 1717)
)

# Vẽ biểu đồ
library(ggplot2)

ggplot(customer_data, aes(x = Travel_Type)) +
  geom_bar(aes(y = Disloyal_Customer, fill = "Disloyal Customer"), stat = "identity", position = "dodge") +
  geom_bar(aes(y = Loyal_Customer, fill = "Loyal Customer"), stat = "identity", position = "dodge") +
  labs(
    title = "Phân bố khách hàng theo loại chuyến đi",
    x = "Loại chuyến đi",
    y = "Số lượng khách hàng",
    fill = "Trạng thái trung thành"
  ) +
  theme_minimal() +
  theme(
    plot.title = element_text(hjust = 0.5),
    axis.text.x = element_text(angle = 45, hjust = 1)
  )

FM <- table(AL$Customer.Type, AL$Flight.Distance )
FM
## < table of extent 0 x 0 >
FM <- table(AL$Customer.Type, AL$Inflight.wifi.service )
FM
## < table of extent 0 x 0 >
# Dữ liệu
customer_data <- data.frame(
  Evaluation_Level = c("Không đánh giá", "Rất tệ", "Tệ", "Bình Thường", "Hài Lòng", "Rất Hài Lòng"),
  Disloyal_Customer = c(186, 701, 1268, 1202, 959, 483),
  Loyal_Customer = c(627, 3787, 5222, 5115, 4022, 2404)
)

# Tính tổng số lượng khách hàng
total_customers <- sum(customer_data$Disloyal_Customer) + sum(customer_data$Loyal_Customer)

# Tính tỷ lệ phần trăm
customer_data$Disloyal_Percentage <- customer_data$Disloyal_Customer / total_customers * 100
customer_data$Loyal_Percentage <- customer_data$Loyal_Customer / total_customers * 100

# Vẽ biểu đồ
library(ggplot2)

ggplot(customer_data, aes(x = Evaluation_Level)) +
  geom_bar(aes(y = Disloyal_Percentage, fill = "Disloyal Customer"), stat = "identity", position = "dodge") +
  geom_bar(aes(y = Loyal_Percentage, fill = "Loyal Customer"), stat = "identity", position = "dodge") +
  labs(
    title = "Phân bố khách hàng theo mức độ đánh giá (tỷ lệ %)",
    x = "Mức độ đánh giá",
    y = "Tỷ lệ khách hàng (%)",
    fill = "Trạng thái trung thành"
  ) +
  scale_y_continuous(labels = scales::percent) +
  theme_minimal() +
  theme(
    plot.title = element_text(hjust = 0.5),
    axis.text.x = element_text(angle = 45, hjust = 1)
  )

FM <- table(AL$Customer.Type, AL$Departure.Arrival.time.convenient )
FM
## < table of extent 0 x 0 >
customer_data <- data.frame(
  Evaluation_Level = c(0, 1, 2, 3, 4, 5),
  Disloyal_Customer = c(868, 615, 996, 945, 893, 482),
  Loyal_Customer = c(513, 3296, 3347, 3467, 5441, 5113)
)
# Tính tổng số khách hàng
total_customers <- sum(customer_data$Disloyal_Customer) + sum(customer_data$Loyal_Customer)

# Tính tỷ lệ phần trăm
customer_data$Disloyal_Percentage <- customer_data$Disloyal_Customer / total_customers * 100
customer_data$Loyal_Percentage <- customer_data$Loyal_Customer / total_customers * 100
library(ggplot2)

ggplot(customer_data, aes(x = Evaluation_Level)) +
  geom_bar(aes(y = Disloyal_Percentage, fill = "Disloyal Customer"), stat = "identity", position = "dodge") +
  geom_bar(aes(y = Loyal_Percentage, fill = "Loyal Customer"), stat = "identity", position = "dodge") +
  labs(
    title = "Phân bố khách hàng theo mức độ đánh giá (tỷ lệ %)",
    x = "Mức độ đánh giá",
    y = "Tỷ lệ khách hàng (%)",
    fill = "Trạng thái trung thành"
  ) +
  scale_y_continuous(labels = scales::percent) +
  theme_minimal() +
  theme(
    plot.title = element_text(hjust = 0.5),
    axis.text.x = element_text(angle = 45, hjust = 1)
  )

FM <- table(AL$Customer.Type, AL$Ease.of.Online.booking )
FM
## < table of extent 0 x 0 >
# Tạo data frame
customer_data <- data.frame(
  Evaluation_Level = c(0, 1, 2, 3, 4, 5),
  Disloyal_Customer = c(247, 674, 1228, 1193, 940, 517),
  Loyal_Customer = c(948, 3687, 4802, 4751, 3933, 3056)
)

# Tính tổng số khách hàng
total_customers <- sum(customer_data$Disloyal_Customer) + sum(customer_data$Loyal_Customer)

# Tính tỷ lệ phần trăm
customer_data$Disloyal_Percentage <- customer_data$Disloyal_Customer / total_customers * 100
customer_data$Loyal_Percentage <- customer_data$Loyal_Customer / total_customers * 100

# Vẽ biểu đồ
library(ggplot2)

ggplot(customer_data, aes(x = Evaluation_Level)) +
  geom_bar(aes(y = Disloyal_Percentage, fill = "Disloyal Customer"), stat = "identity", position = "dodge") +
  geom_bar(aes(y = Loyal_Percentage, fill = "Loyal Customer"), stat = "identity", position = "dodge") +
  labs(
    title = "Phân bố khách hàng theo mức độ đánh giá (tỷ lệ %)",
    x = "Mức độ đánh giá",
    y = "Tỷ lệ khách hàng (%)",
    fill = "Trạng thái trung thành"
  ) +
  scale_y_continuous(labels = scales::percent) +
  theme_minimal() +
  theme(
    plot.title = element_text(hjust = 0.5),
    axis.text.x = element_text(angle = 45, hjust = 1)
  )

FM <- table(AL$Customer.Type, AL$Gate.location )
FM
## < table of extent 0 x 0 >
# Tạo data frame
customer_data <- data.frame(
  Evaluation_Level = c(1, 2, 3, 4, 5),
  Disloyal_Customer = c(662, 801, 1682, 1318, 336),
  Loyal_Customer = c(3767, 4036, 5458, 4722, 3194)
)

# Tính tổng số khách hàng
total_customers <- sum(customer_data$Disloyal_Customer) + sum(customer_data$Loyal_Customer)

# Tính tỷ lệ phần trăm
customer_data$Disloyal_Percentage <- customer_data$Disloyal_Customer / total_customers * 100
customer_data$Loyal_Percentage <- customer_data$Loyal_Customer / total_customers * 100

# Vẽ biểu đồ
library(ggplot2)

ggplot(customer_data, aes(x = Evaluation_Level)) +
  geom_bar(aes(y = Disloyal_Percentage, fill = "Disloyal Customer"), stat = "identity", position = "dodge") +
  geom_bar(aes(y = Loyal_Percentage, fill = "Loyal Customer"), stat = "identity", position = "dodge") +
  labs(
    title = "Phân bố khách hàng theo mức độ đánh giá (tỷ lệ %)",
    x = "Mức độ đánh giá",
    y = "Tỷ lệ khách hàng (%)",
    fill = "Trạng thái trung thành"
  ) +
  scale_y_continuous(labels = scales::percent) +
  theme_minimal() +
  theme(
    plot.title = element_text(hjust = 0.5),
    axis.text.x = element_text(angle = 45, hjust = 1)
  )

FM <- table(AL$Customer.Type, AL$Food.and.drink )
FM
## < table of extent 0 x 0 >
# Tạo data frame
customer_data <- data.frame(
  Evaluation_Level = c(0, 1, 2, 3, 4, 5),
  Disloyal_Customer = c(8, 824, 946, 985, 1055, 981),
  Loyal_Customer = c(17, 2390, 4449, 4509, 5149, 4663)
)

# Tính tổng số khách hàng
total_customers <- sum(customer_data$Disloyal_Customer) + sum(customer_data$Loyal_Customer)

# Tính tỷ lệ phần trăm
customer_data$Disloyal_Percentage <- customer_data$Disloyal_Customer / total_customers * 100
customer_data$Loyal_Percentage <- customer_data$Loyal_Customer / total_customers * 100

# Vẽ biểu đồ
library(ggplot2)

ggplot(customer_data, aes(x = Evaluation_Level)) +
  geom_bar(aes(y = Disloyal_Percentage, fill = "Disloyal Customer"), stat = "identity", position = "dodge") +
  geom_bar(aes(y = Loyal_Percentage, fill = "Loyal Customer"), stat = "identity", position = "dodge") +
  labs(
    title = "Phân bố khách hàng theo mức độ đánh giá (tỷ lệ %)",
    x = "Mức độ đánh giá",
    y = "Tỷ lệ khách hàng (%)",
    fill = "Trạng thái trung thành"
  ) +
  scale_y_continuous(labels = scales::percent) +
  theme_minimal() +
  theme(
    plot.title = element_text(hjust = 0.5),
    axis.text.x = element_text(angle = 45, hjust = 1)
  )

FM <- table(AL$Customer.Type, AL$Online.boarding )
FM
## < table of extent 0 x 0 >
# Tạo data frame
customer_data <- data.frame(
  Evaluation_Level = c(0, 1, 2, 3, 4, 5),
  Disloyal_Customer = c(231, 686, 1234, 1181, 954, 513),
  Loyal_Customer = c(421, 1883, 3195, 4132, 6752, 4794)
)

# Tính tổng số khách hàng
total_customers <- sum(customer_data$Disloyal_Customer) + sum(customer_data$Loyal_Customer)

# Tính tỷ lệ phần trăm
customer_data$Disloyal_Percentage <- customer_data$Disloyal_Customer / total_customers * 100
customer_data$Loyal_Percentage <- customer_data$Loyal_Customer / total_customers * 100

# Vẽ biểu đồ
library(ggplot2)

ggplot(customer_data, aes(x = Evaluation_Level)) +
  geom_bar(aes(y = Disloyal_Percentage, fill = "Disloyal Customer"), stat = "identity", position = "dodge") +
  geom_bar(aes(y = Loyal_Percentage, fill = "Loyal Customer"), stat = "identity", position = "dodge") +
  labs(
    title = "Phân bố khách hàng theo mức độ đánh giá (tỷ lệ %)",
    x = "Mức độ đánh giá",
    y = "Tỷ lệ khách hàng (%)",
    fill = "Trạng thái trung thành"
  ) +
  scale_y_continuous(labels = scales::percent) +
  theme_minimal() +
  theme(
    plot.title = element_text(hjust = 0.5),
    axis.text.x = element_text(angle = 45, hjust = 1)
  )

FM <- table(AL$Customer.Type, AL$Seat.comfort )
FM
## < table of extent 0 x 0 >
# Tạo data frame
customer_data <- data.frame(
  Evaluation_Level = c(1, 2, 3, 4, 5),
  Disloyal_Customer = c(920, 925, 929, 1037, 988),
  Loyal_Customer = c(2113, 2707, 3703, 6954, 5700)
)

# Tính tổng số khách hàng
total_customers <- sum(customer_data$Disloyal_Customer) + sum(customer_data$Loyal_Customer)

# Tính tỷ lệ phần trăm
customer_data$Disloyal_Percentage <- customer_data$Disloyal_Customer / total_customers * 100
customer_data$Loyal_Percentage <- customer_data$Loyal_Customer / total_customers * 100

# Vẽ biểu đồ
library(ggplot2)

ggplot(customer_data, aes(x = Evaluation_Level)) +
  geom_bar(aes(y = Disloyal_Percentage, fill = "Disloyal Customer"), stat = "identity", position = "dodge") +
  geom_bar(aes(y = Loyal_Percentage, fill = "Loyal Customer"), stat = "identity", position = "dodge") +
  labs(
    title = "Phân bố khách hàng theo mức độ đánh giá (tỷ lệ %)",
    x = "Mức độ đánh giá",
    y = "Tỷ lệ khách hàng (%)",
    fill = "Trạng thái trung thành"
  ) +
  scale_y_continuous(labels = scales::percent) +
  theme_minimal() +
  theme(
    plot.title = element_text(hjust = 0.5),
    axis.text.x = element_text(angle = 45, hjust = 1)
  )

FM <- table(AL$Customer.Type, AL$Inflight.entertainment )
FM
## < table of extent 0 x 0 >
# Tạo data frame
customer_data <- data.frame(
  Evaluation_Level = c(0, 1, 2, 3, 4, 5),
  Disloyal_Customer = c(0, 820, 933, 972, 1078, 996),
  Loyal_Customer = c(4, 2377, 3398, 3773, 6290, 5335)
)

# Tính tổng số khách hàng
total_customers <- sum(customer_data$Disloyal_Customer) + sum(customer_data$Loyal_Customer)

# Tính tỷ lệ phần trăm
customer_data$Disloyal_Percentage <- customer_data$Disloyal_Customer / total_customers * 100
customer_data$Loyal_Percentage <- customer_data$Loyal_Customer / total_customers * 100

# Vẽ biểu đồ
library(ggplot2)

ggplot(customer_data, aes(x = Evaluation_Level)) +
  geom_bar(aes(y = Disloyal_Percentage, fill = "Disloyal Customer"), stat = "identity", position = "dodge") +
  geom_bar(aes(y = Loyal_Percentage, fill = "Loyal Customer"), stat = "identity", position = "dodge") +
  labs(
    title = "Phân bố khách hàng theo mức độ đánh giá (tỷ lệ %)",
    x = "Mức độ đánh giá",
    y = "Tỷ lệ khách hàng (%)",
    fill = "Trạng thái trung thành"
  ) +
  scale_y_continuous(labels = scales::percent) +
  theme_minimal() +
  theme(
    plot.title = element_text(hjust = 0.5),
    axis.text.x = element_text(angle = 45, hjust = 1)
  )

FM <- table(AL$Customer.Type, AL$On.board.service )
FM
## < table of extent 0 x 0 >
# Tạo data frame
customer_data <- data.frame(
  Evaluation_Level = c(0, 1, 2, 3, 4, 5),
  Disloyal_Customer = c(0, 610, 658, 1277, 1356, 898),
  Loyal_Customer = c(2, 2305, 3012, 4432, 6480, 4946)
)

# Tính tổng số khách hàng
total_customers <- sum(customer_data$Disloyal_Customer) + sum(customer_data$Loyal_Customer)

# Tính tỷ lệ phần trăm
customer_data$Disloyal_Percentage <- customer_data$Disloyal_Customer / total_customers * 100
customer_data$Loyal_Percentage <- customer_data$Loyal_Customer / total_customers * 100

# Vẽ biểu đồ
library(ggplot2)

ggplot(customer_data, aes(x = Evaluation_Level)) +
  geom_bar(aes(y = Disloyal_Percentage, fill = "Disloyal Customer"), stat = "identity", position = "dodge") +
  geom_bar(aes(y = Loyal_Percentage, fill = "Loyal Customer"), stat = "identity", position = "dodge") +
  labs(
    title = "Phân bố khách hàng theo mức độ đánh giá (tỷ lệ %)",
    x = "Mức độ đánh giá",
    y = "Tỷ lệ khách hàng (%)",
    fill = "Trạng thái trung thành"
  ) +
  scale_y_continuous(labels = scales::percent) +
  theme_minimal() +
  theme(
    plot.title = element_text(hjust = 0.5),
    axis.text.x = element_text(angle = 45, hjust = 1)
  )

FM <- table(AL$Customer.Type, AL$Leg.room.service )
FM
## < table of extent 0 x 0 >
# Tạo data frame
customer_data <- data.frame(
  Evaluation_Level = c(0, 1, 2, 3, 4, 5),
  Disloyal_Customer = c(0, 525, 1059, 1059, 1091, 1065),
  Loyal_Customer = c(126, 2017, 3956, 3899, 6006, 5173)
)

# Tính tổng số khách hàng
total_customers <- sum(customer_data$Disloyal_Customer) + sum(customer_data$Loyal_Customer)

# Tính tỷ lệ phần trăm
customer_data$Disloyal_Percentage <- customer_data$Disloyal_Customer / total_customers * 100
customer_data$Loyal_Percentage <- customer_data$Loyal_Customer / total_customers * 100

# Vẽ biểu đồ
library(ggplot2)

ggplot(customer_data, aes(x = Evaluation_Level)) +
  geom_bar(aes(y = Disloyal_Percentage, fill = "Disloyal Customer"), stat = "identity", position = "dodge") +
  geom_bar(aes(y = Loyal_Percentage, fill = "Loyal Customer"), stat = "identity", position = "dodge") +
  labs(
    title = "Phân bố khách hàng theo mức độ đánh giá (tỷ lệ %)",
    x = "Mức độ đánh giá",
    y = "Tỷ lệ khách hàng (%)",
    fill = "Trạng thái trung thành"
  ) +
  scale_y_continuous(labels = scales::percent) +
  theme_minimal() +
  theme(
    plot.title = element_text(hjust = 0.5),
    axis.text.x = element_text(angle = 45, hjust = 1)
  )       

FM <- table(AL$Customer.Type, AL$Baggage.handling )
FM
## < table of extent 0 x 0 >
# Tạo data frame
customer_data <- data.frame(
  Evaluation_Level = c(1, 2, 3, 4, 5),
  Disloyal_Customer = c(248, 407, 1105, 1834, 1205),
  Loyal_Customer = c(1543, 2434, 4114, 7544, 5542)
)

# Tính tổng số khách hàng
total_customers <- sum(customer_data$Disloyal_Customer) + sum(customer_data$Loyal_Customer)

# Tính tỷ lệ phần trăm
customer_data$Disloyal_Percentage <- customer_data$Disloyal_Customer / total_customers * 100
customer_data$Loyal_Percentage <- customer_data$Loyal_Customer / total_customers * 100

# Vẽ biểu đồ
library(ggplot2)

ggplot(customer_data, aes(x = Evaluation_Level)) +
  geom_bar(aes(y = Disloyal_Percentage, fill = "Disloyal Customer"), stat = "identity", position = "dodge") +
  geom_bar(aes(y = Loyal_Percentage, fill = "Loyal Customer"), stat = "identity", position = "dodge") +
  labs(
    title = "Phân bố khách hàng theo mức độ đánh giá (tỷ lệ %)",
    x = "Mức độ đánh giá",
    y = "Tỷ lệ khách hàng (%)",
    fill = "Trạng thái trung thành"
  ) +
  scale_y_continuous(labels = scales::percent) +
  theme_minimal() +
  theme(
    plot.title = element_text(hjust = 0.5),
    axis.text.x = element_text(angle = 45, hjust = 1)
  )

FM <- table(AL$Customer.Type, AL$Checkin.service)
FM
## < table of extent 0 x 0 >
# Tạo data frame
customer_data <- data.frame(
  Evaluation_Level = c(1, 2, 3, 4, 5),
  Disloyal_Customer = c(650, 641, 1298, 1324, 886),
  Loyal_Customer = c(2568, 2568, 5709, 5954, 4378)
)

# Tính tổng số khách hàng
total_customers <- sum(customer_data$Disloyal_Customer) + sum(customer_data$Loyal_Customer)

# Tính tỷ lệ phần trăm
customer_data$Disloyal_Percentage <- customer_data$Disloyal_Customer / total_customers * 100
customer_data$Loyal_Percentage <- customer_data$Loyal_Customer / total_customers * 100

# Vẽ biểu đồ
library(ggplot2)

ggplot(customer_data, aes(x = Evaluation_Level)) +
  geom_bar(aes(y = Disloyal_Percentage, fill = "Disloyal Customer"), stat = "identity", position = "dodge") +
  geom_bar(aes(y = Loyal_Percentage, fill = "Loyal Customer"), stat = "identity", position = "dodge") +
  labs(
    title = "Phân bố khách hàng theo mức độ đánh giá (tỷ lệ %)",
    x = "Mức độ đánh giá",
    y = "Tỷ lệ khách hàng (%)",
    fill = "Trạng thái trung thành"
  ) +
  scale_y_continuous(labels = scales::percent) +
  theme_minimal() +
  theme(
    plot.title = element_text(hjust = 0.5),
    axis.text.x = element_text(angle = 45, hjust = 1)
  )

FM <- table(AL$Customer.Type, AL$Inflight.service)
FM
## < table of extent 0 x 0 >
# Tạo data frame
customer_data <- data.frame(
  Evaluation_Level = c(0, 1, 2, 3, 4, 5),
  Disloyal_Customer = c(0, 283, 386, 999, 1888, 1243),
  Loyal_Customer = c(2, 1495, 2465, 4018, 7490, 5707)
)

# Tính tổng số khách hàng
total_customers <- sum(customer_data$Disloyal_Customer) + sum(customer_data$Loyal_Customer)

# Tính tỷ lệ phần trăm
customer_data$Disloyal_Percentage <- customer_data$Disloyal_Customer / total_customers * 100
customer_data$Loyal_Percentage <- customer_data$Loyal_Customer / total_customers * 100

# Vẽ biểu đồ
library(ggplot2)

ggplot(customer_data, aes(x = Evaluation_Level)) +
  geom_bar(aes(y = Disloyal_Percentage, fill = "Disloyal Customer"), stat = "identity", position = "dodge") +
  geom_bar(aes(y = Loyal_Percentage, fill = "Loyal Customer"), stat = "identity", position = "dodge") +
  labs(
    title = "Phân bố khách hàng theo mức độ đánh giá (tỷ lệ %)",
    x = "Mức độ đánh giá",
    y = "Tỷ lệ khách hàng (%)",
    fill = "Trạng thái trung thành"
  ) +
  scale_y_continuous(labels = scales::percent) +
  theme_minimal() +
  theme(
    plot.title = element_text(hjust = 0.5),
    axis.text.x = element_text(angle = 45, hjust = 1)
  )

FM <- table(AL$Customer.Type, AL$Cleanliness)
FM
## < table of extent 0 x 0 >
# Tạo data frame
customer_data <- data.frame(
  Evaluation_Level = c(0, 1, 2, 3, 4, 5),
  Disloyal_Customer = c(0, 833, 945, 981, 1055, 985),
  Loyal_Customer = c(2, 2578, 3036, 5084, 5735, 4742)
)

# Tính tổng số khách hàng
total_customers <- sum(customer_data$Disloyal_Customer) + sum(customer_data$Loyal_Customer)

# Tính tỷ lệ phần trăm
customer_data$Disloyal_Percentage <- customer_data$Disloyal_Customer / total_customers * 100
customer_data$Loyal_Percentage <- customer_data$Loyal_Customer / total_customers * 100

# Vẽ biểu đồ
library(ggplot2)

ggplot(customer_data, aes(x = Evaluation_Level)) +
  geom_bar(aes(y = Disloyal_Percentage, fill = "Disloyal Customer"), stat = "identity", position = "dodge") +
  geom_bar(aes(y = Loyal_Percentage, fill = "Loyal Customer"), stat = "identity", position = "dodge") +
  labs(
    title = "Phân bố khách hàng theo mức độ đánh giá (tỷ lệ %)",
    x = "Mức độ đánh giá",
    y = "Tỷ lệ khách hàng (%)",
    fill = "Trạng thái trung thành"
  ) +
  scale_y_continuous(labels = scales::percent) +
  theme_minimal() +
  theme(
    plot.title = element_text(hjust = 0.5),
    axis.text.x = element_text(angle = 45, hjust = 1)
  )

FM <- table(AL$Customer.Type, AL$Departure.Delay.in.Minutes)
FM
## < table of extent 0 x 0 >

Chia dữ liệu thành các nhóm tuổi

AL\(AgeGroup <- cut(AL\)Age, breaks = c(0, 20, 40, 60, 80, 100), labels = c(“0-20”, “21-40”, “41-60”, “61-80”, “81-100”)) # Load thư viện cần thiết library(tidyverse) # Tính toán tỷ lệ phần trăm cho mỗi nhóm tuổi AL <- AL %>% group_by(AgeGroup) %>% mutate(Percentage = n() / sum(n()) * 100)

Vẽ biểu đồ

ggplot(AL, aes(x = AgeGroup, y = Percentage)) + geom_bar(stat = “identity”, fill = “#4c78a8”) + labs(x = “Nhóm tuổi”, y = “Số Người”, title = “Biểu đồ nhóm độ tuổi”, subtitle = “Dữ liệu cập nhật đến tháng 8 năm 2023”) + theme_minimal() + theme( plot.title = element_text(size = 16, face = “bold”), plot.subtitle = element_text(size = 12, color = “grey50”), axis.title = element_text(size = 14), axis.text = element_text(size = 12) )