1. Read and set up Data Loyalty for SEM4

# Read Data directly
t = "E:/NGHIEN CUU SINH/NCS - PHUONG ANH/Part 2-Satisfaction and Loyalty/So lieu/So lieu - PA xu ly-for SEM/So lieu - PA xu ly-for SEM-27.2.2022/858-Loyaltyofbuspassenger_NonBus_Mising-outliersSEM5.csv"
SEM5 = read.csv(t, header = T)
head(SEM5)
##   ID MCCar MCMotor MCBus AGE CITY FRE TripPurpose Departure TimeUseonBus
## 1  3     0       0     1   1    2   1           2         0            4
## 2  4     0       0     1   1    2   2           4         0            4
## 3  5     0       0     1   1    2   1           2         1            4
## 4  6     0       0     1   1    2   1           2         1            1
## 5  7     0       0     1   1    2   1           2         1            4
## 6  8     0       1     1   1    2   1           2         1            6
##   TravelTime PSW1 PSW2 PSW3 PSW4 PSW5 PSW6 PSW7 PSS1 PSS2 PSS3 PSS4 PSS5 PSS6
## 1       3.00    4    5    6    4    6    4    5    6    6    6    6    4    6
## 2       2.00    2    5    3    2    4    5    3    2    3    4    2    2    2
## 3       0.17    4    6    6    4    1    4    2    2    6    6    4    2    2
## 4       4.00    5    5    5    2    6    4    2    6    6    4    1    4    4
## 5       2.00    3    2    4    4    2    6    5    3    3    5    2    1    2
## 6       2.00    2    5    6    5    4    4    6    3    4    6    2    1    1
##   PSS7 PSB1 PSB2 PSB3 PSB4 PSB5 PSB6 PSB7 PSB8 PSQT1 PSQT2 PSQT3 PSQT4 PSQC1
## 1    4    6    6    4    6    5    6    6    6     6     6     4     4     6
## 2    2    3    3    4    4    6    6    6    6     4     6     5     4     4
## 3    2    2    6    6    4    6    6    4    2     2     2     2     2     2
## 4    6    5    6    6    5    5    6    7    6     6     5     4     5     5
## 5    2    2    2    5    5    5    6    4    3     6     3     6     3     6
## 6    2    2    5    4    4    4    6    4    2     4     4     5     4     5
##   PSQC2 PSQC3 PSQC4 PSQC5 PSQP1 PSQP2 PSQP3 PSQP4 PSQR1 PSQR2 PSQR3 PSQR4 PSQC6
## 1     4     4     4     6     6     6     5     6     4     4     6     4     2
## 2     5     6     4     6     6     4     4     5     4     3     4     3     6
## 3     4     1     2     1     1     1     6     6     2     6     2     5     2
## 4     5     5     4     4     5     5     5     5     4     5     5     5     5
## 5     6     4     3     6     4     4     4     5     5     3     5     3     5
## 6     5     4     3     3     4     4     4     5     3     3     3     3     4
##   SAT1 SAT2 SAT3 LOY1 LOY2 LOY3 LOY4 LOY5 LOY6 LOY7 IMA1 IMA2 IMA3 IMA4 IMA5
## 1    6    6    6    4    6    5    7    6    6    6    6    6    6    4    6
## 2    5    5    4    4    5    4    4    4    4    5    4    5    6    5    4
## 3    2    2    2    2    6    6    4    4    2    2    4    2    5    2    2
## 4    5    5    5    5    5    5    5    5    5    5    5    5    5    5    5
## 5    4    4    4    4    5    5    4    4    4    6    5    4    5    4    5
## 6    4    5    5    4    3    2    5    5    6    6    4    3    2    2    4
##   PHB1 PHB2 PHB3 PHB4 PHB5 PEB1 PEB2 PEB3 PEB4 ATM1 ATM2 ATM3 ATM4 ATM5 ATM6
## 1    6    7    6    7    7    4    4    4    4    3    5    6    4    2    4
## 2    3    4    3    4    6    5    6    6    4    3    5    4    4    4    4
## 3    5    2    6    6    6    6    5    6    6    2    6    4    2    2    4
## 4    5    5    5    5    5    5    5    5    5    5    5    5    5    5    5
## 5    5    6    6    6    5    6    6    6    6    3    4    2    2    5    4
## 6    4    6    7    6    4    7    7    5    2    1    4    5    2    1    4
##   ATM7 PPI1 PPI2 PPI3 SIM1 SIM2 SIM3 SIM4 PPA1 PPA2 PPA3 PPA4 SBE1 SBE2 SBE3
## 1    6    6    6    6    4    4    4    2    4    6    4    4    4    4    4
## 2    5    4    4    4    4    4    4    4    4    4    4    4    5    4    5
## 3    2    4    2    2    4    4    4    2    4    6    6    2    6    6    6
## 4    5    5    5    5    5    5    5    5    5    5    5    5    5    5    5
## 5    3    2    3    4    6    6    5    5    5    5    5    5    5    5    5
## 6    2    5    2    2    2    2    2    2    2    3    3    2    2    2    2
##   SBE4 EXB1 EXB2 EXB3 PVA1 PVA2 PVA3 EC_Stop WC_Stop EC_Bus WC_Bus Gender
## 1    4    4    4    3    6    6    6       0       1      0      1      0
## 2    5    4    5    3    5    5    3       0       0      1      0      0
## 3    6    4    6    2    6    2    4       0       0      0      0      1
## 4    5    5    5    5    5    5    5       0       1      0      1      1
## 5    5    5    5    4    6    2    3       0       1      0      1      1
## 6    2    5    5    4    6    5    5       0       1      0      1      0
##   MarriedStatus Occupation Education Income
## 1             1          1         2      1
## 2             1          1         2      1
## 3             1          1         2      1
## 4             1          1         2      1
## 5             1          1         2      1
## 6             1          1         3      1
names(SEM5)
##   [1] "ID"            "MCCar"         "MCMotor"       "MCBus"        
##   [5] "AGE"           "CITY"          "FRE"           "TripPurpose"  
##   [9] "Departure"     "TimeUseonBus"  "TravelTime"    "PSW1"         
##  [13] "PSW2"          "PSW3"          "PSW4"          "PSW5"         
##  [17] "PSW6"          "PSW7"          "PSS1"          "PSS2"         
##  [21] "PSS3"          "PSS4"          "PSS5"          "PSS6"         
##  [25] "PSS7"          "PSB1"          "PSB2"          "PSB3"         
##  [29] "PSB4"          "PSB5"          "PSB6"          "PSB7"         
##  [33] "PSB8"          "PSQT1"         "PSQT2"         "PSQT3"        
##  [37] "PSQT4"         "PSQC1"         "PSQC2"         "PSQC3"        
##  [41] "PSQC4"         "PSQC5"         "PSQP1"         "PSQP2"        
##  [45] "PSQP3"         "PSQP4"         "PSQR1"         "PSQR2"        
##  [49] "PSQR3"         "PSQR4"         "PSQC6"         "SAT1"         
##  [53] "SAT2"          "SAT3"          "LOY1"          "LOY2"         
##  [57] "LOY3"          "LOY4"          "LOY5"          "LOY6"         
##  [61] "LOY7"          "IMA1"          "IMA2"          "IMA3"         
##  [65] "IMA4"          "IMA5"          "PHB1"          "PHB2"         
##  [69] "PHB3"          "PHB4"          "PHB5"          "PEB1"         
##  [73] "PEB2"          "PEB3"          "PEB4"          "ATM1"         
##  [77] "ATM2"          "ATM3"          "ATM4"          "ATM5"         
##  [81] "ATM6"          "ATM7"          "PPI1"          "PPI2"         
##  [85] "PPI3"          "SIM1"          "SIM2"          "SIM3"         
##  [89] "SIM4"          "PPA1"          "PPA2"          "PPA3"         
##  [93] "PPA4"          "SBE1"          "SBE2"          "SBE3"         
##  [97] "SBE4"          "EXB1"          "EXB2"          "EXB3"         
## [101] "PVA1"          "PVA2"          "PVA3"          "EC_Stop"      
## [105] "WC_Stop"       "EC_Bus"        "WC_Bus"        "Gender"       
## [109] "MarriedStatus" "Occupation"    "Education"     "Income"
dim(SEM5)
## [1] 858 112

2. Desscriptive statistic

# 2.1. Subset Data SEM1 (6 constructs and 42 items)
SEM5 <- SEM5[, c(2, 3, 5, 6, 7, 8, 9, 10, 11, 26, 27, 28, 29, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112)]
head(SEM5)
##   MCCar MCMotor AGE CITY FRE TripPurpose Departure TimeUseonBus TravelTime PSB1
## 1     0       0   1    2   1           2         0            4       3.00    6
## 2     0       0   1    2   2           4         0            4       2.00    3
## 3     0       0   1    2   1           2         1            4       0.17    2
## 4     0       0   1    2   1           2         1            1       4.00    5
## 5     0       0   1    2   1           2         1            4       2.00    2
## 6     0       1   1    2   1           2         1            6       2.00    2
##   PSB2 PSB3 PSB4 PSQT1 PSQT2 PSQT3 PSQT4 PSQC1 PSQC2 PSQC3 PSQC4 PSQC5 PSQP1
## 1    6    4    6     6     6     4     4     6     4     4     4     6     6
## 2    3    4    4     4     6     5     4     4     5     6     4     6     6
## 3    6    6    4     2     2     2     2     2     4     1     2     1     1
## 4    6    6    5     6     5     4     5     5     5     5     4     4     5
## 5    2    5    5     6     3     6     3     6     6     4     3     6     4
## 6    5    4    4     4     4     5     4     5     5     4     3     3     4
##   PSQP2 PSQP3 PSQP4 PSQR1 PSQR2 PSQR3 PSQR4 PSQC6 SAT1 SAT2 SAT3 IMA1 IMA2 IMA3
## 1     6     5     6     4     4     6     4     2    6    6    6    6    6    6
## 2     4     4     5     4     3     4     3     6    5    5    4    4    5    6
## 3     1     6     6     2     6     2     5     2    2    2    2    4    2    5
## 4     5     5     5     4     5     5     5     5    5    5    5    5    5    5
## 5     4     4     5     5     3     5     3     5    4    4    4    5    4    5
## 6     4     4     5     3     3     3     3     4    4    5    5    4    3    2
##   IMA4 IMA5 PHB1 PHB2 PHB3 PHB4 PHB5 PEB1 PEB2 PEB3 PEB4 PVA1 PVA2 PVA3 EC_Stop
## 1    4    6    6    7    6    7    7    4    4    4    4    6    6    6       0
## 2    5    4    3    4    3    4    6    5    6    6    4    5    5    3       0
## 3    2    2    5    2    6    6    6    6    5    6    6    6    2    4       0
## 4    5    5    5    5    5    5    5    5    5    5    5    5    5    5       0
## 5    4    5    5    6    6    6    5    6    6    6    6    6    2    3       0
## 6    2    4    4    6    7    6    4    7    7    5    2    6    5    5       0
##   WC_Stop EC_Bus WC_Bus Gender MarriedStatus Occupation Education Income
## 1       1      0      1      0             1          1         2      1
## 2       0      1      0      0             1          1         2      1
## 3       0      0      0      1             1          1         2      1
## 4       1      0      1      1             1          1         2      1
## 5       1      0      1      1             1          1         2      1
## 6       1      0      1      0             1          1         3      1
names(SEM5)
##  [1] "MCCar"         "MCMotor"       "AGE"           "CITY"         
##  [5] "FRE"           "TripPurpose"   "Departure"     "TimeUseonBus" 
##  [9] "TravelTime"    "PSB1"          "PSB2"          "PSB3"         
## [13] "PSB4"          "PSQT1"         "PSQT2"         "PSQT3"        
## [17] "PSQT4"         "PSQC1"         "PSQC2"         "PSQC3"        
## [21] "PSQC4"         "PSQC5"         "PSQP1"         "PSQP2"        
## [25] "PSQP3"         "PSQP4"         "PSQR1"         "PSQR2"        
## [29] "PSQR3"         "PSQR4"         "PSQC6"         "SAT1"         
## [33] "SAT2"          "SAT3"          "IMA1"          "IMA2"         
## [37] "IMA3"          "IMA4"          "IMA5"          "PHB1"         
## [41] "PHB2"          "PHB3"          "PHB4"          "PHB5"         
## [45] "PEB1"          "PEB2"          "PEB3"          "PEB4"         
## [49] "PVA1"          "PVA2"          "PVA3"          "EC_Stop"      
## [53] "WC_Stop"       "EC_Bus"        "WC_Bus"        "Gender"       
## [57] "MarriedStatus" "Occupation"    "Education"     "Income"
dim(SEM5)
## [1] 858  60
# Data coding
str(SEM5)
## 'data.frame':    858 obs. of  60 variables:
##  $ MCCar        : int  0 0 0 0 0 0 0 0 0 0 ...
##  $ MCMotor      : int  0 0 0 0 0 1 1 1 1 1 ...
##  $ AGE          : int  1 1 1 1 1 1 1 4 1 1 ...
##  $ CITY         : int  2 2 2 2 2 2 2 2 2 2 ...
##  $ FRE          : int  1 2 1 1 1 1 4 1 1 1 ...
##  $ TripPurpose  : int  2 4 2 2 2 2 4 1 2 2 ...
##  $ Departure    : int  0 0 1 1 1 1 1 1 1 1 ...
##  $ TimeUseonBus : int  4 4 4 1 4 6 1 4 4 3 ...
##  $ TravelTime   : num  3 2 0.17 4 2 2 1 2 2.5 1.5 ...
##  $ PSB1         : int  6 3 2 5 2 2 1 6 2 4 ...
##  $ PSB2         : int  6 3 6 6 2 5 1 6 4 4 ...
##  $ PSB3         : int  4 4 6 6 5 4 5 6 4 7 ...
##  $ PSB4         : int  6 4 4 5 5 4 1 6 4 4 ...
##  $ PSQT1        : int  6 4 2 6 6 4 2 5 5 7 ...
##  $ PSQT2        : int  6 6 2 5 3 4 5 6 4 7 ...
##  $ PSQT3        : int  4 5 2 4 6 5 5 4 5 7 ...
##  $ PSQT4        : int  4 4 2 5 3 4 2 4 3 7 ...
##  $ PSQC1        : int  6 4 2 5 6 5 2 6 3 7 ...
##  $ PSQC2        : int  4 5 4 5 6 5 2 6 4 7 ...
##  $ PSQC3        : int  4 6 1 5 4 4 2 3 4 7 ...
##  $ PSQC4        : int  4 4 2 4 3 3 2 4 4 4 ...
##  $ PSQC5        : int  6 6 1 4 6 3 2 3 3 4 ...
##  $ PSQP1        : int  6 6 1 5 4 4 4 4 3 4 ...
##  $ PSQP2        : int  6 4 1 5 4 4 4 4 4 4 ...
##  $ PSQP3        : int  5 4 6 5 4 4 3 4 5 7 ...
##  $ PSQP4        : int  6 5 6 5 5 5 4 4 6 7 ...
##  $ PSQR1        : int  4 4 2 4 5 3 2 5 3 4 ...
##  $ PSQR2        : int  4 3 6 5 3 3 1 3 4 7 ...
##  $ PSQR3        : int  6 4 2 5 5 3 1 3 5 4 ...
##  $ PSQR4        : int  4 3 5 5 3 3 2 2 4 7 ...
##  $ PSQC6        : int  2 6 2 5 5 4 4 6 4 7 ...
##  $ SAT1         : int  6 5 2 5 4 4 2 7 5 7 ...
##  $ SAT2         : int  6 5 2 5 4 5 2 7 6 7 ...
##  $ SAT3         : int  6 4 2 5 4 5 3 6 4 7 ...
##  $ IMA1         : int  6 4 4 5 5 4 2 6 5 6 ...
##  $ IMA2         : int  6 5 2 5 4 3 3 6 6 7 ...
##  $ IMA3         : int  6 6 5 5 5 2 2 5 6 7 ...
##  $ IMA4         : int  4 5 2 5 4 2 2 6 6 7 ...
##  $ IMA5         : int  6 4 2 5 5 4 2 6 6 7 ...
##  $ PHB1         : int  6 3 5 5 5 4 3 6 6 7 ...
##  $ PHB2         : int  7 4 2 5 6 6 3 7 5 7 ...
##  $ PHB3         : int  6 3 6 5 6 7 1 4 3 7 ...
##  $ PHB4         : int  7 4 6 5 6 6 4 6 7 7 ...
##  $ PHB5         : int  7 6 6 5 5 4 4 6 7 7 ...
##  $ PEB1         : int  4 5 6 5 6 7 4 6 7 7 ...
##  $ PEB2         : int  4 6 5 5 6 7 2 7 7 7 ...
##  $ PEB3         : int  4 6 6 5 6 5 2 6 6 7 ...
##  $ PEB4         : int  4 4 6 5 6 2 2 6 6 7 ...
##  $ PVA1         : int  6 5 6 5 6 6 6 6 6 6 ...
##  $ PVA2         : int  6 5 2 5 2 5 4 5 4 6 ...
##  $ PVA3         : int  6 3 4 5 3 5 5 6 5 6 ...
##  $ EC_Stop      : int  0 0 0 0 0 0 0 0 0 0 ...
##  $ WC_Stop      : int  1 0 0 1 1 1 0 0 1 0 ...
##  $ EC_Bus       : int  0 1 0 0 0 0 0 0 0 0 ...
##  $ WC_Bus       : int  1 0 0 1 1 1 0 0 1 0 ...
##  $ Gender       : int  0 0 1 1 1 0 0 0 0 0 ...
##  $ MarriedStatus: int  1 1 1 1 1 1 1 0 1 1 ...
##  $ Occupation   : int  1 1 1 1 1 1 1 2 1 1 ...
##  $ Education    : int  2 2 2 2 2 3 5 1 2 3 ...
##  $ Income       : int  1 1 1 1 1 1 1 1 1 1 ...
attach(SEM5)
SEM5 = within(SEM5, {
  MCCar = factor(MCCar,labels = c("No", "Yes"))
  MCMotor = factor(MCMotor,labels = c("No", "Yes"))
  AGE = factor(AGE, labels = c("16-25", "26-35", "36-45", "46-55", ">55"))
  CITY = factor(CITY,labels = c("DaNang", "HoChiMinh"))
  FRE = factor(FRE, labels = c(">=3 days/week", "2days/month-2days/week", "2days/year-1day/month", "<2 days/year"))
  TripPurpose = factor(TripPurpose, labels = c("Working", "Studying", "Shopping", "Entertaining", "Others"))
  Departure = factor(Departure, labels = c("Normal", "Peak-Hour"))
  TimeUseonBus = factor(TimeUseonBus, labels = c("Using.telephone", "Reading", "Listening", "Nothing", "Talking", "Others"))
  EC_Stop = factor(EC_Stop, labels = c("Never", "Ever"))
  WC_Stop = factor(WC_Stop, labels = c("Never", "Ever"))
  EC_Bus = factor(EC_Bus, labels = c("Never", "Ever"))
  WC_Bus = factor(WC_Bus, labels = c("Never", "Ever"))
  Gender = factor(Gender, labels = c("Female", "Male"))
  MarriedStatus = factor(MarriedStatus, labels = c("Married", "Single"))
  Occupation = factor(Occupation, labels = c("Students/Pupils", "Full.time.job", "Part.time.job", "Retirement", "No.job", "Housewife", "Others"))
  Education = factor(Education, labels = c("Secondary.school", "Undergraduate", "High.school", "Postgraduate", "Others"))
  Income = factor(Income, labels = c("<5millions", "5-10millions", "10-15millions", ">15millions"))
    } )
str(SEM5)
## 'data.frame':    858 obs. of  60 variables:
##  $ MCCar        : Factor w/ 2 levels "No","Yes": 1 1 1 1 1 1 1 1 1 1 ...
##  $ MCMotor      : Factor w/ 2 levels "No","Yes": 1 1 1 1 1 2 2 2 2 2 ...
##  $ AGE          : Factor w/ 5 levels "16-25","26-35",..: 1 1 1 1 1 1 1 3 1 1 ...
##  $ CITY         : Factor w/ 2 levels "DaNang","HoChiMinh": 2 2 2 2 2 2 2 2 2 2 ...
##  $ FRE          : Factor w/ 4 levels ">=3 days/week",..: 1 2 1 1 1 1 4 1 1 1 ...
##  $ TripPurpose  : Factor w/ 5 levels "Working","Studying",..: 2 4 2 2 2 2 4 1 2 2 ...
##  $ Departure    : Factor w/ 2 levels "Normal","Peak-Hour": 1 1 2 2 2 2 2 2 2 2 ...
##  $ TimeUseonBus : Factor w/ 6 levels "Using.telephone",..: 4 4 4 1 4 6 1 4 4 3 ...
##  $ TravelTime   : num  3 2 0.17 4 2 2 1 2 2.5 1.5 ...
##  $ PSB1         : int  6 3 2 5 2 2 1 6 2 4 ...
##  $ PSB2         : int  6 3 6 6 2 5 1 6 4 4 ...
##  $ PSB3         : int  4 4 6 6 5 4 5 6 4 7 ...
##  $ PSB4         : int  6 4 4 5 5 4 1 6 4 4 ...
##  $ PSQT1        : int  6 4 2 6 6 4 2 5 5 7 ...
##  $ PSQT2        : int  6 6 2 5 3 4 5 6 4 7 ...
##  $ PSQT3        : int  4 5 2 4 6 5 5 4 5 7 ...
##  $ PSQT4        : int  4 4 2 5 3 4 2 4 3 7 ...
##  $ PSQC1        : int  6 4 2 5 6 5 2 6 3 7 ...
##  $ PSQC2        : int  4 5 4 5 6 5 2 6 4 7 ...
##  $ PSQC3        : int  4 6 1 5 4 4 2 3 4 7 ...
##  $ PSQC4        : int  4 4 2 4 3 3 2 4 4 4 ...
##  $ PSQC5        : int  6 6 1 4 6 3 2 3 3 4 ...
##  $ PSQP1        : int  6 6 1 5 4 4 4 4 3 4 ...
##  $ PSQP2        : int  6 4 1 5 4 4 4 4 4 4 ...
##  $ PSQP3        : int  5 4 6 5 4 4 3 4 5 7 ...
##  $ PSQP4        : int  6 5 6 5 5 5 4 4 6 7 ...
##  $ PSQR1        : int  4 4 2 4 5 3 2 5 3 4 ...
##  $ PSQR2        : int  4 3 6 5 3 3 1 3 4 7 ...
##  $ PSQR3        : int  6 4 2 5 5 3 1 3 5 4 ...
##  $ PSQR4        : int  4 3 5 5 3 3 2 2 4 7 ...
##  $ PSQC6        : int  2 6 2 5 5 4 4 6 4 7 ...
##  $ SAT1         : int  6 5 2 5 4 4 2 7 5 7 ...
##  $ SAT2         : int  6 5 2 5 4 5 2 7 6 7 ...
##  $ SAT3         : int  6 4 2 5 4 5 3 6 4 7 ...
##  $ IMA1         : int  6 4 4 5 5 4 2 6 5 6 ...
##  $ IMA2         : int  6 5 2 5 4 3 3 6 6 7 ...
##  $ IMA3         : int  6 6 5 5 5 2 2 5 6 7 ...
##  $ IMA4         : int  4 5 2 5 4 2 2 6 6 7 ...
##  $ IMA5         : int  6 4 2 5 5 4 2 6 6 7 ...
##  $ PHB1         : int  6 3 5 5 5 4 3 6 6 7 ...
##  $ PHB2         : int  7 4 2 5 6 6 3 7 5 7 ...
##  $ PHB3         : int  6 3 6 5 6 7 1 4 3 7 ...
##  $ PHB4         : int  7 4 6 5 6 6 4 6 7 7 ...
##  $ PHB5         : int  7 6 6 5 5 4 4 6 7 7 ...
##  $ PEB1         : int  4 5 6 5 6 7 4 6 7 7 ...
##  $ PEB2         : int  4 6 5 5 6 7 2 7 7 7 ...
##  $ PEB3         : int  4 6 6 5 6 5 2 6 6 7 ...
##  $ PEB4         : int  4 4 6 5 6 2 2 6 6 7 ...
##  $ PVA1         : int  6 5 6 5 6 6 6 6 6 6 ...
##  $ PVA2         : int  6 5 2 5 2 5 4 5 4 6 ...
##  $ PVA3         : int  6 3 4 5 3 5 5 6 5 6 ...
##  $ EC_Stop      : Factor w/ 2 levels "Never","Ever": 1 1 1 1 1 1 1 1 1 1 ...
##  $ WC_Stop      : Factor w/ 2 levels "Never","Ever": 2 1 1 2 2 2 1 1 2 1 ...
##  $ EC_Bus       : Factor w/ 2 levels "Never","Ever": 1 2 1 1 1 1 1 1 1 1 ...
##  $ WC_Bus       : Factor w/ 2 levels "Never","Ever": 2 1 1 2 2 2 1 1 2 1 ...
##  $ Gender       : Factor w/ 2 levels "Female","Male": 1 1 2 2 2 1 1 1 1 1 ...
##  $ MarriedStatus: Factor w/ 2 levels "Married","Single": 2 2 2 2 2 2 2 1 2 2 ...
##  $ Occupation   : Factor w/ 7 levels "Students/Pupils",..: 1 1 1 1 1 1 1 2 1 1 ...
##  $ Education    : Factor w/ 5 levels "Secondary.school",..: 2 2 2 2 2 3 5 1 2 3 ...
##  $ Income       : Factor w/ 4 levels "<5millions","5-10millions",..: 1 1 1 1 1 1 1 1 1 1 ...
dim(SEM5)
## [1] 858  60
# 2.2. Descritive Table
library(tableone)
require(tableone)
library(magrittr)
summary(SEM5)
##  MCCar     MCMotor      AGE             CITY                         FRE     
##  No :838   No :696   16-25:417   DaNang   :410   >=3 days/week         :498  
##  Yes: 20   Yes:162   26-35:169   HoChiMinh:448   2days/month-2days/week:163  
##                      36-45:101                   2days/year-1day/month : 98  
##                      46-55: 77                   <2 days/year          : 99  
##                      >55  : 94                                               
##                                                                              
##                                                                              
##        TripPurpose      Departure            TimeUseonBus   TravelTime    
##  Working     :304   Normal   :217   Using.telephone:198   Min.   : 0.000  
##  Studying    :295   Peak-Hour:641   Reading        : 52   1st Qu.: 0.500  
##  Shopping    : 58                   Listening      :137   Median : 1.000  
##  Entertaining: 98                   Nothing        :418   Mean   : 1.273  
##  Others      :103                   Talking        : 33   3rd Qu.: 2.000  
##                                     Others         : 20   Max.   :20.000  
##                                                                           
##       PSB1            PSB2            PSB3            PSB4      
##  Min.   :1.000   Min.   :1.000   Min.   :1.000   Min.   :1.000  
##  1st Qu.:3.000   1st Qu.:4.000   1st Qu.:5.000   1st Qu.:4.000  
##  Median :5.000   Median :6.000   Median :6.000   Median :5.000  
##  Mean   :4.638   Mean   :5.079   Mean   :5.499   Mean   :4.818  
##  3rd Qu.:6.000   3rd Qu.:6.000   3rd Qu.:6.000   3rd Qu.:6.000  
##  Max.   :7.000   Max.   :7.000   Max.   :7.000   Max.   :7.000  
##                                                                 
##      PSQT1           PSQT2           PSQT3           PSQT4      
##  Min.   :1.000   Min.   :1.000   Min.   :1.000   Min.   :1.000  
##  1st Qu.:5.000   1st Qu.:5.000   1st Qu.:5.000   1st Qu.:5.000  
##  Median :6.000   Median :6.000   Median :6.000   Median :6.000  
##  Mean   :5.351   Mean   :5.392   Mean   :5.203   Mean   :5.183  
##  3rd Qu.:6.000   3rd Qu.:6.000   3rd Qu.:6.000   3rd Qu.:6.000  
##  Max.   :7.000   Max.   :7.000   Max.   :7.000   Max.   :7.000  
##                                                                 
##      PSQC1           PSQC2          PSQC3           PSQC4           PSQC5      
##  Min.   :1.000   Min.   :1.00   Min.   :1.000   Min.   :1.000   Min.   :1.000  
##  1st Qu.:4.000   1st Qu.:5.00   1st Qu.:4.000   1st Qu.:4.000   1st Qu.:4.000  
##  Median :6.000   Median :6.00   Median :6.000   Median :5.000   Median :5.000  
##  Mean   :5.138   Mean   :5.58   Mean   :5.119   Mean   :4.773   Mean   :5.033  
##  3rd Qu.:6.000   3rd Qu.:6.00   3rd Qu.:6.000   3rd Qu.:6.000   3rd Qu.:6.000  
##  Max.   :7.000   Max.   :7.00   Max.   :7.000   Max.   :7.000   Max.   :7.000  
##                                                                                
##      PSQP1           PSQP2           PSQP3           PSQP4      
##  Min.   :1.000   Min.   :1.000   Min.   :1.000   Min.   :1.000  
##  1st Qu.:5.000   1st Qu.:5.000   1st Qu.:5.000   1st Qu.:5.000  
##  Median :6.000   Median :6.000   Median :6.000   Median :6.000  
##  Mean   :5.321   Mean   :5.308   Mean   :5.382   Mean   :5.558  
##  3rd Qu.:6.000   3rd Qu.:6.000   3rd Qu.:6.000   3rd Qu.:6.000  
##  Max.   :7.000   Max.   :7.000   Max.   :7.000   Max.   :7.000  
##                                                                 
##      PSQR1           PSQR2           PSQR3          PSQR4          PSQC6      
##  Min.   :1.000   Min.   :1.000   Min.   :1.00   Min.   :1.00   Min.   :1.000  
##  1st Qu.:4.000   1st Qu.:5.000   1st Qu.:4.00   1st Qu.:4.00   1st Qu.:5.000  
##  Median :5.000   Median :6.000   Median :5.00   Median :5.00   Median :6.000  
##  Mean   :4.951   Mean   :5.234   Mean   :5.02   Mean   :4.85   Mean   :5.531  
##  3rd Qu.:6.000   3rd Qu.:6.000   3rd Qu.:6.00   3rd Qu.:6.00   3rd Qu.:6.000  
##  Max.   :7.000   Max.   :7.000   Max.   :7.00   Max.   :7.00   Max.   :7.000  
##                                                                               
##       SAT1            SAT2            SAT3            IMA1           IMA2     
##  Min.   :1.000   Min.   :1.000   Min.   :1.000   Min.   :1.00   Min.   :1.00  
##  1st Qu.:5.000   1st Qu.:5.000   1st Qu.:5.000   1st Qu.:5.00   1st Qu.:5.00  
##  Median :6.000   Median :6.000   Median :6.000   Median :5.00   Median :6.00  
##  Mean   :5.326   Mean   :5.497   Mean   :5.495   Mean   :5.21   Mean   :5.22  
##  3rd Qu.:6.000   3rd Qu.:6.000   3rd Qu.:6.000   3rd Qu.:6.00   3rd Qu.:6.00  
##  Max.   :7.000   Max.   :7.000   Max.   :7.000   Max.   :7.00   Max.   :7.00  
##                                                                               
##       IMA3            IMA4            IMA5           PHB1            PHB2      
##  Min.   :1.000   Min.   :1.000   Min.   :1.00   Min.   :1.000   Min.   :1.000  
##  1st Qu.:5.000   1st Qu.:5.000   1st Qu.:5.00   1st Qu.:5.000   1st Qu.:5.000  
##  Median :6.000   Median :6.000   Median :6.00   Median :6.000   Median :6.000  
##  Mean   :5.367   Mean   :5.364   Mean   :5.42   Mean   :5.297   Mean   :5.604  
##  3rd Qu.:6.000   3rd Qu.:6.000   3rd Qu.:6.00   3rd Qu.:6.000   3rd Qu.:6.000  
##  Max.   :7.000   Max.   :7.000   Max.   :7.00   Max.   :7.000   Max.   :7.000  
##                                                                                
##       PHB3            PHB4            PHB5            PEB1      
##  Min.   :1.000   Min.   :1.000   Min.   :1.000   Min.   :1.000  
##  1st Qu.:5.000   1st Qu.:5.000   1st Qu.:6.000   1st Qu.:5.000  
##  Median :6.000   Median :6.000   Median :6.000   Median :6.000  
##  Mean   :5.446   Mean   :5.872   Mean   :5.802   Mean   :5.763  
##  3rd Qu.:6.000   3rd Qu.:7.000   3rd Qu.:7.000   3rd Qu.:7.000  
##  Max.   :7.000   Max.   :7.000   Max.   :7.000   Max.   :7.000  
##                                                                 
##       PEB2            PEB3            PEB4            PVA1      
##  Min.   :1.000   Min.   :1.000   Min.   :1.000   Min.   :1.000  
##  1st Qu.:5.000   1st Qu.:5.000   1st Qu.:5.000   1st Qu.:5.000  
##  Median :6.000   Median :6.000   Median :6.000   Median :6.000  
##  Mean   :5.586   Mean   :5.533   Mean   :5.487   Mean   :5.846  
##  3rd Qu.:6.000   3rd Qu.:6.000   3rd Qu.:6.000   3rd Qu.:7.000  
##  Max.   :7.000   Max.   :7.000   Max.   :7.000   Max.   :7.000  
##                                                                 
##       PVA2            PVA3        EC_Stop     WC_Stop      EC_Bus   
##  Min.   :1.000   Min.   :1.000   Never:822   Never:737   Never:818  
##  1st Qu.:5.000   1st Qu.:5.000   Ever : 36   Ever :121   Ever : 40  
##  Median :6.000   Median :6.000                                      
##  Mean   :5.436   Mean   :5.709                                      
##  3rd Qu.:6.000   3rd Qu.:6.000                                      
##  Max.   :7.000   Max.   :7.000                                      
##                                                                     
##    WC_Bus       Gender    MarriedStatus           Occupation 
##  Never:743   Female:502   Married:331   Students/Pupils:361  
##  Ever :115   Male  :356   Single :527   Full.time.job  :304  
##                                         Part.time.job  : 65  
##                                         Retirement     : 46  
##                                         No.job         :  4  
##                                         Housewife      : 52  
##                                         Others         : 26  
##             Education             Income   
##  Secondary.school: 59   <5millions   :458  
##  Undergraduate   :276   5-10millions :248  
##  High.school     :365   10-15millions:116  
##  Postgraduate    :103   >15millions  : 36  
##  Others          : 55                      
##                                            
## 
library(table1)
## 
## Attaching package: 'table1'
## The following objects are masked from 'package:base':
## 
##     units, units<-
Tab1_SEM5 <- table1(~ PSB1 + PSB2 + PSB3 + PSB4 + PSQT1 + PSQT2 + PSQT3 + PSQT4 + PSQC1 + PSQC2 + PSQC3 + PSQC4 + PSQC5 + PSQC6 + PSQP1 + PSQP2 + PSQP3 + PSQP4 + PSQR1 + PSQR2 + PSQR3 + PSQR4 + SAT1 + SAT2 + SAT3 + IMA1 + IMA2 + IMA3 + IMA4 + IMA5 + PHB1 + PHB2 + PHB3 + PHB4 + PHB5 + PEB1 + PEB2 + PEB3 + PEB4 + PVA1 + PVA2 + PVA3 + EC_Stop + WC_Stop + EC_Bus + WC_Bus + Gender + MarriedStatus + Occupation + Education + Income + MCCar + MCMotor + AGE + CITY + FRE + TripPurpose + Departure + TimeUseonBus + TravelTime| CITY , data = SEM5)
Tab1_SEM5
DaNang
(N=410)
HoChiMinh
(N=448)
Overall
(N=858)
PSB1
Mean (SD) 5.57 (1.24) 3.79 (1.90) 4.64 (1.85)
Median [Min, Max] 6.00 [1.00, 7.00] 4.00 [1.00, 7.00] 5.00 [1.00, 7.00]
PSB2
Mean (SD) 5.62 (1.19) 4.58 (1.77) 5.08 (1.60)
Median [Min, Max] 6.00 [1.00, 7.00] 5.00 [1.00, 7.00] 6.00 [1.00, 7.00]
PSB3
Mean (SD) 5.77 (0.964) 5.25 (1.39) 5.50 (1.23)
Median [Min, Max] 6.00 [1.00, 7.00] 6.00 [1.00, 7.00] 6.00 [1.00, 7.00]
PSB4
Mean (SD) 5.40 (1.22) 4.28 (1.70) 4.82 (1.59)
Median [Min, Max] 6.00 [1.00, 7.00] 4.00 [1.00, 7.00] 5.00 [1.00, 7.00]
PSQT1
Mean (SD) 5.74 (1.06) 5.00 (1.44) 5.35 (1.32)
Median [Min, Max] 6.00 [1.00, 7.00] 5.00 [1.00, 7.00] 6.00 [1.00, 7.00]
PSQT2
Mean (SD) 5.91 (1.08) 4.91 (1.56) 5.39 (1.44)
Median [Min, Max] 6.00 [1.00, 7.00] 5.00 [1.00, 7.00] 6.00 [1.00, 7.00]
PSQT3
Mean (SD) 5.73 (1.19) 4.72 (1.63) 5.20 (1.52)
Median [Min, Max] 6.00 [1.00, 7.00] 5.00 [1.00, 7.00] 6.00 [1.00, 7.00]
PSQT4
Mean (SD) 5.50 (1.14) 4.89 (1.51) 5.18 (1.38)
Median [Min, Max] 6.00 [1.00, 7.00] 5.00 [1.00, 7.00] 6.00 [1.00, 7.00]
PSQC1
Mean (SD) 5.21 (1.27) 5.07 (1.49) 5.14 (1.39)
Median [Min, Max] 5.00 [1.00, 7.00] 6.00 [1.00, 7.00] 6.00 [1.00, 7.00]
PSQC2
Mean (SD) 5.77 (0.995) 5.41 (1.40) 5.58 (1.24)
Median [Min, Max] 6.00 [1.00, 7.00] 6.00 [1.00, 7.00] 6.00 [1.00, 7.00]
PSQC3
Mean (SD) 5.10 (1.41) 5.14 (1.38) 5.12 (1.40)
Median [Min, Max] 5.00 [1.00, 7.00] 6.00 [1.00, 7.00] 6.00 [1.00, 7.00]
PSQC4
Mean (SD) 4.81 (1.34) 4.73 (1.40) 4.77 (1.37)
Median [Min, Max] 5.00 [1.00, 7.00] 5.00 [1.00, 7.00] 5.00 [1.00, 7.00]
PSQC5
Mean (SD) 5.17 (1.30) 4.91 (1.46) 5.03 (1.39)
Median [Min, Max] 6.00 [1.00, 7.00] 5.00 [1.00, 7.00] 5.00 [1.00, 7.00]
PSQC6
Mean (SD) 5.57 (1.19) 5.49 (1.28) 5.53 (1.24)
Median [Min, Max] 6.00 [1.00, 7.00] 6.00 [1.00, 7.00] 6.00 [1.00, 7.00]
PSQP1
Mean (SD) 5.70 (0.984) 4.97 (1.45) 5.32 (1.30)
Median [Min, Max] 6.00 [1.00, 7.00] 5.00 [1.00, 7.00] 6.00 [1.00, 7.00]
PSQP2
Mean (SD) 5.71 (0.982) 4.94 (1.46) 5.31 (1.31)
Median [Min, Max] 6.00 [1.00, 7.00] 5.00 [1.00, 7.00] 6.00 [1.00, 7.00]
PSQP3
Mean (SD) 5.72 (0.884) 5.07 (1.38) 5.38 (1.22)
Median [Min, Max] 6.00 [1.00, 7.00] 5.00 [1.00, 7.00] 6.00 [1.00, 7.00]
PSQP4
Mean (SD) 5.85 (0.809) 5.29 (1.32) 5.56 (1.14)
Median [Min, Max] 6.00 [3.00, 7.00] 6.00 [1.00, 7.00] 6.00 [1.00, 7.00]
PSQR1
Mean (SD) 5.06 (1.41) 4.85 (1.46) 4.95 (1.44)
Median [Min, Max] 5.00 [1.00, 7.00] 5.00 [1.00, 7.00] 5.00 [1.00, 7.00]
PSQR2
Mean (SD) 5.68 (1.02) 4.83 (1.45) 5.23 (1.33)
Median [Min, Max] 6.00 [2.00, 7.00] 5.00 [1.00, 7.00] 6.00 [1.00, 7.00]
PSQR3
Mean (SD) 5.19 (1.30) 4.86 (1.46) 5.02 (1.39)
Median [Min, Max] 5.00 [1.00, 7.00] 5.00 [1.00, 7.00] 5.00 [1.00, 7.00]
PSQR4
Mean (SD) 5.29 (1.29) 4.45 (1.72) 4.85 (1.58)
Median [Min, Max] 6.00 [1.00, 7.00] 5.00 [1.00, 7.00] 5.00 [1.00, 7.00]
SAT1
Mean (SD) 5.52 (1.06) 5.15 (1.35) 5.33 (1.23)
Median [Min, Max] 6.00 [2.00, 7.00] 6.00 [1.00, 7.00] 6.00 [1.00, 7.00]
SAT2
Mean (SD) 5.68 (1.00) 5.33 (1.25) 5.50 (1.15)
Median [Min, Max] 6.00 [1.00, 7.00] 6.00 [1.00, 7.00] 6.00 [1.00, 7.00]
SAT3
Mean (SD) 5.74 (0.947) 5.27 (1.28) 5.50 (1.15)
Median [Min, Max] 6.00 [1.00, 7.00] 6.00 [1.00, 7.00] 6.00 [1.00, 7.00]
IMA1
Mean (SD) 5.36 (0.970) 5.07 (1.27) 5.21 (1.15)
Median [Min, Max] 5.00 [1.00, 7.00] 5.00 [1.00, 7.00] 5.00 [1.00, 7.00]
IMA2
Mean (SD) 5.52 (0.874) 4.95 (1.34) 5.22 (1.18)
Median [Min, Max] 6.00 [3.00, 7.00] 5.00 [1.00, 7.00] 6.00 [1.00, 7.00]
IMA3
Mean (SD) 5.62 (0.843) 5.14 (1.28) 5.37 (1.12)
Median [Min, Max] 6.00 [3.00, 7.00] 5.00 [1.00, 7.00] 6.00 [1.00, 7.00]
IMA4
Mean (SD) 5.68 (0.858) 5.07 (1.34) 5.36 (1.18)
Median [Min, Max] 6.00 [2.00, 7.00] 5.00 [1.00, 7.00] 6.00 [1.00, 7.00]
IMA5
Mean (SD) 5.74 (0.795) 5.13 (1.27) 5.42 (1.11)
Median [Min, Max] 6.00 [3.00, 7.00] 5.00 [1.00, 7.00] 6.00 [1.00, 7.00]
PHB1
Mean (SD) 5.42 (1.09) 5.19 (1.53) 5.30 (1.34)
Median [Min, Max] 6.00 [1.00, 7.00] 6.00 [1.00, 7.00] 6.00 [1.00, 7.00]
PHB2
Mean (SD) 5.82 (1.00) 5.40 (1.45) 5.60 (1.27)
Median [Min, Max] 6.00 [2.00, 7.00] 6.00 [1.00, 7.00] 6.00 [1.00, 7.00]
PHB3
Mean (SD) 5.47 (1.18) 5.42 (1.38) 5.45 (1.29)
Median [Min, Max] 6.00 [2.00, 7.00] 6.00 [1.00, 7.00] 6.00 [1.00, 7.00]
PHB4
Mean (SD) 6.07 (0.843) 5.69 (1.33) 5.87 (1.14)
Median [Min, Max] 6.00 [3.00, 7.00] 6.00 [1.00, 7.00] 6.00 [1.00, 7.00]
PHB5
Mean (SD) 6.04 (0.846) 5.59 (1.46) 5.80 (1.23)
Median [Min, Max] 6.00 [2.00, 7.00] 6.00 [1.00, 7.00] 6.00 [1.00, 7.00]
PEB1
Mean (SD) 5.97 (0.841) 5.58 (1.55) 5.76 (1.28)
Median [Min, Max] 6.00 [1.00, 7.00] 6.00 [1.00, 7.00] 6.00 [1.00, 7.00]
PEB2
Mean (SD) 5.79 (1.00) 5.40 (1.60) 5.59 (1.36)
Median [Min, Max] 6.00 [1.00, 7.00] 6.00 [1.00, 7.00] 6.00 [1.00, 7.00]
PEB3
Mean (SD) 5.72 (1.06) 5.36 (1.59) 5.53 (1.38)
Median [Min, Max] 6.00 [2.00, 7.00] 6.00 [1.00, 7.00] 6.00 [1.00, 7.00]
PEB4
Mean (SD) 5.70 (1.05) 5.29 (1.57) 5.49 (1.36)
Median [Min, Max] 6.00 [2.00, 7.00] 6.00 [1.00, 7.00] 6.00 [1.00, 7.00]
PVA1
Mean (SD) 5.94 (0.933) 5.76 (1.19) 5.85 (1.08)
Median [Min, Max] 6.00 [2.00, 7.00] 6.00 [1.00, 7.00] 6.00 [1.00, 7.00]
PVA2
Mean (SD) 5.53 (1.20) 5.35 (1.29) 5.44 (1.25)
Median [Min, Max] 6.00 [1.00, 7.00] 6.00 [1.00, 7.00] 6.00 [1.00, 7.00]
PVA3
Mean (SD) 5.89 (0.846) 5.54 (1.25) 5.71 (1.09)
Median [Min, Max] 6.00 [2.00, 7.00] 6.00 [1.00, 7.00] 6.00 [1.00, 7.00]
EC_Stop
Never 406 (99.0%) 416 (92.9%) 822 (95.8%)
Ever 4 (1.0%) 32 (7.1%) 36 (4.2%)
WC_Stop
Never 388 (94.6%) 349 (77.9%) 737 (85.9%)
Ever 22 (5.4%) 99 (22.1%) 121 (14.1%)
EC_Bus
Never 407 (99.3%) 411 (91.7%) 818 (95.3%)
Ever 3 (0.7%) 37 (8.3%) 40 (4.7%)
WC_Bus
Never 393 (95.9%) 350 (78.1%) 743 (86.6%)
Ever 17 (4.1%) 98 (21.9%) 115 (13.4%)
Gender
Female 230 (56.1%) 272 (60.7%) 502 (58.5%)
Male 180 (43.9%) 176 (39.3%) 356 (41.5%)
MarriedStatus
Married 147 (35.9%) 184 (41.1%) 331 (38.6%)
Single 263 (64.1%) 264 (58.9%) 527 (61.4%)
Occupation
Students/Pupils 201 (49.0%) 160 (35.7%) 361 (42.1%)
Full.time.job 115 (28.0%) 189 (42.2%) 304 (35.4%)
Part.time.job 25 (6.1%) 40 (8.9%) 65 (7.6%)
Retirement 33 (8.0%) 13 (2.9%) 46 (5.4%)
No.job 3 (0.7%) 1 (0.2%) 4 (0.5%)
Housewife 27 (6.6%) 25 (5.6%) 52 (6.1%)
Others 6 (1.5%) 20 (4.5%) 26 (3.0%)
Education
Secondary.school 30 (7.3%) 29 (6.5%) 59 (6.9%)
Undergraduate 128 (31.2%) 148 (33.0%) 276 (32.2%)
High.school 173 (42.2%) 192 (42.9%) 365 (42.5%)
Postgraduate 61 (14.9%) 42 (9.4%) 103 (12.0%)
Others 18 (4.4%) 37 (8.3%) 55 (6.4%)
Income
<5millions 270 (65.9%) 188 (42.0%) 458 (53.4%)
5-10millions 83 (20.2%) 165 (36.8%) 248 (28.9%)
10-15millions 49 (12.0%) 67 (15.0%) 116 (13.5%)
>15millions 8 (2.0%) 28 (6.2%) 36 (4.2%)
MCCar
No 410 (100%) 428 (95.5%) 838 (97.7%)
Yes 0 (0%) 20 (4.5%) 20 (2.3%)
MCMotor
No 409 (99.8%) 287 (64.1%) 696 (81.1%)
Yes 1 (0.2%) 161 (35.9%) 162 (18.9%)
AGE
16-25 217 (52.9%) 200 (44.6%) 417 (48.6%)
26-35 76 (18.5%) 93 (20.8%) 169 (19.7%)
36-45 35 (8.5%) 66 (14.7%) 101 (11.8%)
46-55 35 (8.5%) 42 (9.4%) 77 (9.0%)
>55 47 (11.5%) 47 (10.5%) 94 (11.0%)
CITY
DaNang 410 (100%) 0 (0%) 410 (47.8%)
HoChiMinh 0 (0%) 448 (100%) 448 (52.2%)
FRE
>=3 days/week 261 (63.7%) 237 (52.9%) 498 (58.0%)
2days/month-2days/week 83 (20.2%) 80 (17.9%) 163 (19.0%)
2days/year-1day/month 28 (6.8%) 70 (15.6%) 98 (11.4%)
<2 days/year 38 (9.3%) 61 (13.6%) 99 (11.5%)
TripPurpose
Working 115 (28.0%) 189 (42.2%) 304 (35.4%)
Studying 161 (39.3%) 134 (29.9%) 295 (34.4%)
Shopping 45 (11.0%) 13 (2.9%) 58 (6.8%)
Entertaining 51 (12.4%) 47 (10.5%) 98 (11.4%)
Others 38 (9.3%) 65 (14.5%) 103 (12.0%)
Departure
Normal 145 (35.4%) 72 (16.1%) 217 (25.3%)
Peak-Hour 265 (64.6%) 376 (83.9%) 641 (74.7%)
TimeUseonBus
Using.telephone 104 (25.4%) 94 (21.0%) 198 (23.1%)
Reading 21 (5.1%) 31 (6.9%) 52 (6.1%)
Listening 54 (13.2%) 83 (18.5%) 137 (16.0%)
Nothing 202 (49.3%) 216 (48.2%) 418 (48.7%)
Talking 24 (5.9%) 9 (2.0%) 33 (3.8%)
Others 5 (1.2%) 15 (3.3%) 20 (2.3%)
TravelTime
Mean (SD) 1.12 (0.827) 1.41 (1.81) 1.27 (1.44)
Median [Min, Max] 1.00 [0, 6.00] 1.00 [0, 20.0] 1.00 [0, 20.0]
#2.3 Histogram
hist(SEM5$PEB1)

hist(SEM5$PEB2)

hist(SEM5$PEB3)

hist(SEM5$PEB4)

hist(SEM5$SAT1)

hist(SEM5$SAT2)

hist(SEM5$SAT3)

## Loại phân bố dữ liệu không thuộc phân bố chuẩn

3. Perception of bus user 3.1. Tạo dữ liệu biểu đồ likert

# Create data for Likert graph by BS (remove ID and TM =7-Bus) 
head(SEM5)
##   MCCar MCMotor   AGE      CITY                    FRE  TripPurpose Departure
## 1    No      No 16-25 HoChiMinh          >=3 days/week     Studying    Normal
## 2    No      No 16-25 HoChiMinh 2days/month-2days/week Entertaining    Normal
## 3    No      No 16-25 HoChiMinh          >=3 days/week     Studying Peak-Hour
## 4    No      No 16-25 HoChiMinh          >=3 days/week     Studying Peak-Hour
## 5    No      No 16-25 HoChiMinh          >=3 days/week     Studying Peak-Hour
## 6    No     Yes 16-25 HoChiMinh          >=3 days/week     Studying Peak-Hour
##      TimeUseonBus TravelTime PSB1 PSB2 PSB3 PSB4 PSQT1 PSQT2 PSQT3 PSQT4 PSQC1
## 1         Nothing       3.00    6    6    4    6     6     6     4     4     6
## 2         Nothing       2.00    3    3    4    4     4     6     5     4     4
## 3         Nothing       0.17    2    6    6    4     2     2     2     2     2
## 4 Using.telephone       4.00    5    6    6    5     6     5     4     5     5
## 5         Nothing       2.00    2    2    5    5     6     3     6     3     6
## 6          Others       2.00    2    5    4    4     4     4     5     4     5
##   PSQC2 PSQC3 PSQC4 PSQC5 PSQP1 PSQP2 PSQP3 PSQP4 PSQR1 PSQR2 PSQR3 PSQR4 PSQC6
## 1     4     4     4     6     6     6     5     6     4     4     6     4     2
## 2     5     6     4     6     6     4     4     5     4     3     4     3     6
## 3     4     1     2     1     1     1     6     6     2     6     2     5     2
## 4     5     5     4     4     5     5     5     5     4     5     5     5     5
## 5     6     4     3     6     4     4     4     5     5     3     5     3     5
## 6     5     4     3     3     4     4     4     5     3     3     3     3     4
##   SAT1 SAT2 SAT3 IMA1 IMA2 IMA3 IMA4 IMA5 PHB1 PHB2 PHB3 PHB4 PHB5 PEB1 PEB2
## 1    6    6    6    6    6    6    4    6    6    7    6    7    7    4    4
## 2    5    5    4    4    5    6    5    4    3    4    3    4    6    5    6
## 3    2    2    2    4    2    5    2    2    5    2    6    6    6    6    5
## 4    5    5    5    5    5    5    5    5    5    5    5    5    5    5    5
## 5    4    4    4    5    4    5    4    5    5    6    6    6    5    6    6
## 6    4    5    5    4    3    2    2    4    4    6    7    6    4    7    7
##   PEB3 PEB4 PVA1 PVA2 PVA3 EC_Stop WC_Stop EC_Bus WC_Bus Gender MarriedStatus
## 1    4    4    6    6    6   Never    Ever  Never   Ever Female        Single
## 2    6    4    5    5    3   Never   Never   Ever  Never Female        Single
## 3    6    6    6    2    4   Never   Never  Never  Never   Male        Single
## 4    5    5    5    5    5   Never    Ever  Never   Ever   Male        Single
## 5    6    6    6    2    3   Never    Ever  Never   Ever   Male        Single
## 6    5    2    6    5    5   Never    Ever  Never   Ever Female        Single
##        Occupation     Education     Income
## 1 Students/Pupils Undergraduate <5millions
## 2 Students/Pupils Undergraduate <5millions
## 3 Students/Pupils Undergraduate <5millions
## 4 Students/Pupils Undergraduate <5millions
## 5 Students/Pupils Undergraduate <5millions
## 6 Students/Pupils   High.school <5millions
str(SEM5)
## 'data.frame':    858 obs. of  60 variables:
##  $ MCCar        : Factor w/ 2 levels "No","Yes": 1 1 1 1 1 1 1 1 1 1 ...
##  $ MCMotor      : Factor w/ 2 levels "No","Yes": 1 1 1 1 1 2 2 2 2 2 ...
##  $ AGE          : Factor w/ 5 levels "16-25","26-35",..: 1 1 1 1 1 1 1 3 1 1 ...
##  $ CITY         : Factor w/ 2 levels "DaNang","HoChiMinh": 2 2 2 2 2 2 2 2 2 2 ...
##  $ FRE          : Factor w/ 4 levels ">=3 days/week",..: 1 2 1 1 1 1 4 1 1 1 ...
##  $ TripPurpose  : Factor w/ 5 levels "Working","Studying",..: 2 4 2 2 2 2 4 1 2 2 ...
##  $ Departure    : Factor w/ 2 levels "Normal","Peak-Hour": 1 1 2 2 2 2 2 2 2 2 ...
##  $ TimeUseonBus : Factor w/ 6 levels "Using.telephone",..: 4 4 4 1 4 6 1 4 4 3 ...
##  $ TravelTime   : num  3 2 0.17 4 2 2 1 2 2.5 1.5 ...
##  $ PSB1         : int  6 3 2 5 2 2 1 6 2 4 ...
##  $ PSB2         : int  6 3 6 6 2 5 1 6 4 4 ...
##  $ PSB3         : int  4 4 6 6 5 4 5 6 4 7 ...
##  $ PSB4         : int  6 4 4 5 5 4 1 6 4 4 ...
##  $ PSQT1        : int  6 4 2 6 6 4 2 5 5 7 ...
##  $ PSQT2        : int  6 6 2 5 3 4 5 6 4 7 ...
##  $ PSQT3        : int  4 5 2 4 6 5 5 4 5 7 ...
##  $ PSQT4        : int  4 4 2 5 3 4 2 4 3 7 ...
##  $ PSQC1        : int  6 4 2 5 6 5 2 6 3 7 ...
##  $ PSQC2        : int  4 5 4 5 6 5 2 6 4 7 ...
##  $ PSQC3        : int  4 6 1 5 4 4 2 3 4 7 ...
##  $ PSQC4        : int  4 4 2 4 3 3 2 4 4 4 ...
##  $ PSQC5        : int  6 6 1 4 6 3 2 3 3 4 ...
##  $ PSQP1        : int  6 6 1 5 4 4 4 4 3 4 ...
##  $ PSQP2        : int  6 4 1 5 4 4 4 4 4 4 ...
##  $ PSQP3        : int  5 4 6 5 4 4 3 4 5 7 ...
##  $ PSQP4        : int  6 5 6 5 5 5 4 4 6 7 ...
##  $ PSQR1        : int  4 4 2 4 5 3 2 5 3 4 ...
##  $ PSQR2        : int  4 3 6 5 3 3 1 3 4 7 ...
##  $ PSQR3        : int  6 4 2 5 5 3 1 3 5 4 ...
##  $ PSQR4        : int  4 3 5 5 3 3 2 2 4 7 ...
##  $ PSQC6        : int  2 6 2 5 5 4 4 6 4 7 ...
##  $ SAT1         : int  6 5 2 5 4 4 2 7 5 7 ...
##  $ SAT2         : int  6 5 2 5 4 5 2 7 6 7 ...
##  $ SAT3         : int  6 4 2 5 4 5 3 6 4 7 ...
##  $ IMA1         : int  6 4 4 5 5 4 2 6 5 6 ...
##  $ IMA2         : int  6 5 2 5 4 3 3 6 6 7 ...
##  $ IMA3         : int  6 6 5 5 5 2 2 5 6 7 ...
##  $ IMA4         : int  4 5 2 5 4 2 2 6 6 7 ...
##  $ IMA5         : int  6 4 2 5 5 4 2 6 6 7 ...
##  $ PHB1         : int  6 3 5 5 5 4 3 6 6 7 ...
##  $ PHB2         : int  7 4 2 5 6 6 3 7 5 7 ...
##  $ PHB3         : int  6 3 6 5 6 7 1 4 3 7 ...
##  $ PHB4         : int  7 4 6 5 6 6 4 6 7 7 ...
##  $ PHB5         : int  7 6 6 5 5 4 4 6 7 7 ...
##  $ PEB1         : int  4 5 6 5 6 7 4 6 7 7 ...
##  $ PEB2         : int  4 6 5 5 6 7 2 7 7 7 ...
##  $ PEB3         : int  4 6 6 5 6 5 2 6 6 7 ...
##  $ PEB4         : int  4 4 6 5 6 2 2 6 6 7 ...
##  $ PVA1         : int  6 5 6 5 6 6 6 6 6 6 ...
##  $ PVA2         : int  6 5 2 5 2 5 4 5 4 6 ...
##  $ PVA3         : int  6 3 4 5 3 5 5 6 5 6 ...
##  $ EC_Stop      : Factor w/ 2 levels "Never","Ever": 1 1 1 1 1 1 1 1 1 1 ...
##  $ WC_Stop      : Factor w/ 2 levels "Never","Ever": 2 1 1 2 2 2 1 1 2 1 ...
##  $ EC_Bus       : Factor w/ 2 levels "Never","Ever": 1 2 1 1 1 1 1 1 1 1 ...
##  $ WC_Bus       : Factor w/ 2 levels "Never","Ever": 2 1 1 2 2 2 1 1 2 1 ...
##  $ Gender       : Factor w/ 2 levels "Female","Male": 1 1 2 2 2 1 1 1 1 1 ...
##  $ MarriedStatus: Factor w/ 2 levels "Married","Single": 2 2 2 2 2 2 2 1 2 2 ...
##  $ Occupation   : Factor w/ 7 levels "Students/Pupils",..: 1 1 1 1 1 1 1 2 1 1 ...
##  $ Education    : Factor w/ 5 levels "Secondary.school",..: 2 2 2 2 2 3 5 1 2 3 ...
##  $ Income       : Factor w/ 4 levels "<5millions","5-10millions",..: 1 1 1 1 1 1 1 1 1 1 ...
dim(SEM5)
## [1] 858  60
names(SEM5)
##  [1] "MCCar"         "MCMotor"       "AGE"           "CITY"         
##  [5] "FRE"           "TripPurpose"   "Departure"     "TimeUseonBus" 
##  [9] "TravelTime"    "PSB1"          "PSB2"          "PSB3"         
## [13] "PSB4"          "PSQT1"         "PSQT2"         "PSQT3"        
## [17] "PSQT4"         "PSQC1"         "PSQC2"         "PSQC3"        
## [21] "PSQC4"         "PSQC5"         "PSQP1"         "PSQP2"        
## [25] "PSQP3"         "PSQP4"         "PSQR1"         "PSQR2"        
## [29] "PSQR3"         "PSQR4"         "PSQC6"         "SAT1"         
## [33] "SAT2"          "SAT3"          "IMA1"          "IMA2"         
## [37] "IMA3"          "IMA4"          "IMA5"          "PHB1"         
## [41] "PHB2"          "PHB3"          "PHB4"          "PHB5"         
## [45] "PEB1"          "PEB2"          "PEB3"          "PEB4"         
## [49] "PVA1"          "PVA2"          "PVA3"          "EC_Stop"      
## [53] "WC_Stop"       "EC_Bus"        "WC_Bus"        "Gender"       
## [57] "MarriedStatus" "Occupation"    "Education"     "Income"
SEM5_likert = SEM5[,c(3, 4, 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)] # BPE gom cac bien tu 10-51
head(SEM5_likert)
##     AGE      CITY PSB1 PSB2 PSB3 PSB4 PSQT1 PSQT2 PSQT3 PSQT4 PSQC1 PSQC2 PSQC3
## 1 16-25 HoChiMinh    6    6    4    6     6     6     4     4     6     4     4
## 2 16-25 HoChiMinh    3    3    4    4     4     6     5     4     4     5     6
## 3 16-25 HoChiMinh    2    6    6    4     2     2     2     2     2     4     1
## 4 16-25 HoChiMinh    5    6    6    5     6     5     4     5     5     5     5
## 5 16-25 HoChiMinh    2    2    5    5     6     3     6     3     6     6     4
## 6 16-25 HoChiMinh    2    5    4    4     4     4     5     4     5     5     4
##   PSQC4 PSQC5 PSQP1 PSQP2 PSQP3 PSQP4 PSQR1 PSQR2 PSQR3 PSQR4 PSQC6 SAT1 SAT2
## 1     4     6     6     6     5     6     4     4     6     4     2    6    6
## 2     4     6     6     4     4     5     4     3     4     3     6    5    5
## 3     2     1     1     1     6     6     2     6     2     5     2    2    2
## 4     4     4     5     5     5     5     4     5     5     5     5    5    5
## 5     3     6     4     4     4     5     5     3     5     3     5    4    4
## 6     3     3     4     4     4     5     3     3     3     3     4    4    5
##   SAT3 IMA1 IMA2 IMA3 IMA4 IMA5 PHB1 PHB2 PHB3 PHB4 PHB5 PEB1 PEB2 PEB3 PEB4
## 1    6    6    6    6    4    6    6    7    6    7    7    4    4    4    4
## 2    4    4    5    6    5    4    3    4    3    4    6    5    6    6    4
## 3    2    4    2    5    2    2    5    2    6    6    6    6    5    6    6
## 4    5    5    5    5    5    5    5    5    5    5    5    5    5    5    5
## 5    4    5    4    5    4    5    5    6    6    6    5    6    6    6    6
## 6    5    4    3    2    2    4    4    6    7    6    4    7    7    5    2
##   PVA1 PVA2 PVA3 EC_Stop WC_Stop EC_Bus WC_Bus Gender
## 1    6    6    6   Never    Ever  Never   Ever Female
## 2    5    5    3   Never   Never   Ever  Never Female
## 3    6    2    4   Never   Never  Never  Never   Male
## 4    5    5    5   Never    Ever  Never   Ever   Male
## 5    6    2    3   Never    Ever  Never   Ever   Male
## 6    6    5    5   Never    Ever  Never   Ever Female
str(SEM5_likert)
## 'data.frame':    858 obs. of  49 variables:
##  $ AGE    : Factor w/ 5 levels "16-25","26-35",..: 1 1 1 1 1 1 1 3 1 1 ...
##  $ CITY   : Factor w/ 2 levels "DaNang","HoChiMinh": 2 2 2 2 2 2 2 2 2 2 ...
##  $ PSB1   : int  6 3 2 5 2 2 1 6 2 4 ...
##  $ PSB2   : int  6 3 6 6 2 5 1 6 4 4 ...
##  $ PSB3   : int  4 4 6 6 5 4 5 6 4 7 ...
##  $ PSB4   : int  6 4 4 5 5 4 1 6 4 4 ...
##  $ PSQT1  : int  6 4 2 6 6 4 2 5 5 7 ...
##  $ PSQT2  : int  6 6 2 5 3 4 5 6 4 7 ...
##  $ PSQT3  : int  4 5 2 4 6 5 5 4 5 7 ...
##  $ PSQT4  : int  4 4 2 5 3 4 2 4 3 7 ...
##  $ PSQC1  : int  6 4 2 5 6 5 2 6 3 7 ...
##  $ PSQC2  : int  4 5 4 5 6 5 2 6 4 7 ...
##  $ PSQC3  : int  4 6 1 5 4 4 2 3 4 7 ...
##  $ PSQC4  : int  4 4 2 4 3 3 2 4 4 4 ...
##  $ PSQC5  : int  6 6 1 4 6 3 2 3 3 4 ...
##  $ PSQP1  : int  6 6 1 5 4 4 4 4 3 4 ...
##  $ PSQP2  : int  6 4 1 5 4 4 4 4 4 4 ...
##  $ PSQP3  : int  5 4 6 5 4 4 3 4 5 7 ...
##  $ PSQP4  : int  6 5 6 5 5 5 4 4 6 7 ...
##  $ PSQR1  : int  4 4 2 4 5 3 2 5 3 4 ...
##  $ PSQR2  : int  4 3 6 5 3 3 1 3 4 7 ...
##  $ PSQR3  : int  6 4 2 5 5 3 1 3 5 4 ...
##  $ PSQR4  : int  4 3 5 5 3 3 2 2 4 7 ...
##  $ PSQC6  : int  2 6 2 5 5 4 4 6 4 7 ...
##  $ SAT1   : int  6 5 2 5 4 4 2 7 5 7 ...
##  $ SAT2   : int  6 5 2 5 4 5 2 7 6 7 ...
##  $ SAT3   : int  6 4 2 5 4 5 3 6 4 7 ...
##  $ IMA1   : int  6 4 4 5 5 4 2 6 5 6 ...
##  $ IMA2   : int  6 5 2 5 4 3 3 6 6 7 ...
##  $ IMA3   : int  6 6 5 5 5 2 2 5 6 7 ...
##  $ IMA4   : int  4 5 2 5 4 2 2 6 6 7 ...
##  $ IMA5   : int  6 4 2 5 5 4 2 6 6 7 ...
##  $ PHB1   : int  6 3 5 5 5 4 3 6 6 7 ...
##  $ PHB2   : int  7 4 2 5 6 6 3 7 5 7 ...
##  $ PHB3   : int  6 3 6 5 6 7 1 4 3 7 ...
##  $ PHB4   : int  7 4 6 5 6 6 4 6 7 7 ...
##  $ PHB5   : int  7 6 6 5 5 4 4 6 7 7 ...
##  $ PEB1   : int  4 5 6 5 6 7 4 6 7 7 ...
##  $ PEB2   : int  4 6 5 5 6 7 2 7 7 7 ...
##  $ PEB3   : int  4 6 6 5 6 5 2 6 6 7 ...
##  $ PEB4   : int  4 4 6 5 6 2 2 6 6 7 ...
##  $ PVA1   : int  6 5 6 5 6 6 6 6 6 6 ...
##  $ PVA2   : int  6 5 2 5 2 5 4 5 4 6 ...
##  $ PVA3   : int  6 3 4 5 3 5 5 6 5 6 ...
##  $ EC_Stop: Factor w/ 2 levels "Never","Ever": 1 1 1 1 1 1 1 1 1 1 ...
##  $ WC_Stop: Factor w/ 2 levels "Never","Ever": 2 1 1 2 2 2 1 1 2 1 ...
##  $ EC_Bus : Factor w/ 2 levels "Never","Ever": 1 2 1 1 1 1 1 1 1 1 ...
##  $ WC_Bus : Factor w/ 2 levels "Never","Ever": 2 1 1 2 2 2 1 1 2 1 ...
##  $ Gender : Factor w/ 2 levels "Female","Male": 1 1 2 2 2 1 1 1 1 1 ...
dim(SEM5_likert)
## [1] 858  49
## Creat dat_PSB1 - cot 3 cua SEM5_likert
dat_PSB1 <- SEM5_likert [, c(1,2,3,45, 46, 47, 48, 49)]
head(dat_PSB1)
##     AGE      CITY PSB1 EC_Stop WC_Stop EC_Bus WC_Bus Gender
## 1 16-25 HoChiMinh    6   Never    Ever  Never   Ever Female
## 2 16-25 HoChiMinh    3   Never   Never   Ever  Never Female
## 3 16-25 HoChiMinh    2   Never   Never  Never  Never   Male
## 4 16-25 HoChiMinh    5   Never    Ever  Never   Ever   Male
## 5 16-25 HoChiMinh    2   Never    Ever  Never   Ever   Male
## 6 16-25 HoChiMinh    2   Never    Ever  Never   Ever Female
dim(dat_PSB1)
## [1] 858   8
size <- 858
dat_PSB1$BPE <- rep("PSB1", size = size) # Tạo biến mới BPE
names(dat_PSB1)[names(dat_PSB1) == "PSB1"] <- "Res" # Đổi tên biến BST thành Res
head(dat_PSB1)
##     AGE      CITY Res EC_Stop WC_Stop EC_Bus WC_Bus Gender  BPE
## 1 16-25 HoChiMinh   6   Never    Ever  Never   Ever Female PSB1
## 2 16-25 HoChiMinh   3   Never   Never   Ever  Never Female PSB1
## 3 16-25 HoChiMinh   2   Never   Never  Never  Never   Male PSB1
## 4 16-25 HoChiMinh   5   Never    Ever  Never   Ever   Male PSB1
## 5 16-25 HoChiMinh   2   Never    Ever  Never   Ever   Male PSB1
## 6 16-25 HoChiMinh   2   Never    Ever  Never   Ever Female PSB1
## Creat dat_PSB2 - cot 4 cua SEM5_likert
dat_PSB2 <- SEM5_likert [, c(1,2,4,45, 46, 47, 48, 49)]
head(dat_PSB2)
##     AGE      CITY PSB2 EC_Stop WC_Stop EC_Bus WC_Bus Gender
## 1 16-25 HoChiMinh    6   Never    Ever  Never   Ever Female
## 2 16-25 HoChiMinh    3   Never   Never   Ever  Never Female
## 3 16-25 HoChiMinh    6   Never   Never  Never  Never   Male
## 4 16-25 HoChiMinh    6   Never    Ever  Never   Ever   Male
## 5 16-25 HoChiMinh    2   Never    Ever  Never   Ever   Male
## 6 16-25 HoChiMinh    5   Never    Ever  Never   Ever Female
dim(dat_PSB2)
## [1] 858   8
size <- 858
dat_PSB2$BPE <- rep("PSB2", size = size) # Tạo biến mới BPE
names(dat_PSB2)[names(dat_PSB2) == "PSB2"] <- "Res" # Đổi tên biến BST thành Res
head(dat_PSB2)
##     AGE      CITY Res EC_Stop WC_Stop EC_Bus WC_Bus Gender  BPE
## 1 16-25 HoChiMinh   6   Never    Ever  Never   Ever Female PSB2
## 2 16-25 HoChiMinh   3   Never   Never   Ever  Never Female PSB2
## 3 16-25 HoChiMinh   6   Never   Never  Never  Never   Male PSB2
## 4 16-25 HoChiMinh   6   Never    Ever  Never   Ever   Male PSB2
## 5 16-25 HoChiMinh   2   Never    Ever  Never   Ever   Male PSB2
## 6 16-25 HoChiMinh   5   Never    Ever  Never   Ever Female PSB2
## Creat dat_PSB3 - cot 5 cua SEN5_likert
dat_PSB3 <- SEM5_likert [, c(1,2,5,45, 46, 47, 48, 49)]
head(dat_PSB3)
##     AGE      CITY PSB3 EC_Stop WC_Stop EC_Bus WC_Bus Gender
## 1 16-25 HoChiMinh    4   Never    Ever  Never   Ever Female
## 2 16-25 HoChiMinh    4   Never   Never   Ever  Never Female
## 3 16-25 HoChiMinh    6   Never   Never  Never  Never   Male
## 4 16-25 HoChiMinh    6   Never    Ever  Never   Ever   Male
## 5 16-25 HoChiMinh    5   Never    Ever  Never   Ever   Male
## 6 16-25 HoChiMinh    4   Never    Ever  Never   Ever Female
dim(dat_PSB3)
## [1] 858   8
size <- 858
dat_PSB3$BPE <- rep("PSB3", size = size) # Tạo biến mới BPE
names(dat_PSB3)[names(dat_PSB3) == "PSB3"] <- "Res" # Đổi tên biến BST thành Res
head(dat_PSB3)
##     AGE      CITY Res EC_Stop WC_Stop EC_Bus WC_Bus Gender  BPE
## 1 16-25 HoChiMinh   4   Never    Ever  Never   Ever Female PSB3
## 2 16-25 HoChiMinh   4   Never   Never   Ever  Never Female PSB3
## 3 16-25 HoChiMinh   6   Never   Never  Never  Never   Male PSB3
## 4 16-25 HoChiMinh   6   Never    Ever  Never   Ever   Male PSB3
## 5 16-25 HoChiMinh   5   Never    Ever  Never   Ever   Male PSB3
## 6 16-25 HoChiMinh   4   Never    Ever  Never   Ever Female PSB3
## Creat dat_PSB4 - cot 6 cua SEM5_likert
dat_PSB4 <- SEM5_likert [, c(1,2,6,45, 46, 47, 48, 49)]
head(dat_PSB4)
##     AGE      CITY PSB4 EC_Stop WC_Stop EC_Bus WC_Bus Gender
## 1 16-25 HoChiMinh    6   Never    Ever  Never   Ever Female
## 2 16-25 HoChiMinh    4   Never   Never   Ever  Never Female
## 3 16-25 HoChiMinh    4   Never   Never  Never  Never   Male
## 4 16-25 HoChiMinh    5   Never    Ever  Never   Ever   Male
## 5 16-25 HoChiMinh    5   Never    Ever  Never   Ever   Male
## 6 16-25 HoChiMinh    4   Never    Ever  Never   Ever Female
dim(dat_PSB4)
## [1] 858   8
size <- 858
dat_PSB4$BPE <- rep("PSB4", size = size) # Tạo biến mới BPE
names(dat_PSB4)[names(dat_PSB4) == "PSB4"] <- "Res" # Đổi tên biến BST thành Res
head(dat_PSB4)
##     AGE      CITY Res EC_Stop WC_Stop EC_Bus WC_Bus Gender  BPE
## 1 16-25 HoChiMinh   6   Never    Ever  Never   Ever Female PSB4
## 2 16-25 HoChiMinh   4   Never   Never   Ever  Never Female PSB4
## 3 16-25 HoChiMinh   4   Never   Never  Never  Never   Male PSB4
## 4 16-25 HoChiMinh   5   Never    Ever  Never   Ever   Male PSB4
## 5 16-25 HoChiMinh   5   Never    Ever  Never   Ever   Male PSB4
## 6 16-25 HoChiMinh   4   Never    Ever  Never   Ever Female PSB4
## Creat dat_PSQT1 - cot 7 cua SEM5_likert
dat_PSQT1 <- SEM5_likert [, c(1,2,7,45, 46, 47, 48, 49)]
head(dat_PSQT1)
##     AGE      CITY PSQT1 EC_Stop WC_Stop EC_Bus WC_Bus Gender
## 1 16-25 HoChiMinh     6   Never    Ever  Never   Ever Female
## 2 16-25 HoChiMinh     4   Never   Never   Ever  Never Female
## 3 16-25 HoChiMinh     2   Never   Never  Never  Never   Male
## 4 16-25 HoChiMinh     6   Never    Ever  Never   Ever   Male
## 5 16-25 HoChiMinh     6   Never    Ever  Never   Ever   Male
## 6 16-25 HoChiMinh     4   Never    Ever  Never   Ever Female
dim(dat_PSQT1)
## [1] 858   8
size <- 858
dat_PSQT1$BPE <- rep("PSQT1", size = size) # Tạo biến mới BPE
names(dat_PSQT1)[names(dat_PSQT1) == "PSQT1"] <- "Res" # Đổi tên biến BST thành Res
head(dat_PSQT1)
##     AGE      CITY Res EC_Stop WC_Stop EC_Bus WC_Bus Gender   BPE
## 1 16-25 HoChiMinh   6   Never    Ever  Never   Ever Female PSQT1
## 2 16-25 HoChiMinh   4   Never   Never   Ever  Never Female PSQT1
## 3 16-25 HoChiMinh   2   Never   Never  Never  Never   Male PSQT1
## 4 16-25 HoChiMinh   6   Never    Ever  Never   Ever   Male PSQT1
## 5 16-25 HoChiMinh   6   Never    Ever  Never   Ever   Male PSQT1
## 6 16-25 HoChiMinh   4   Never    Ever  Never   Ever Female PSQT1
## Creat dat_PSQT2 - cot 8 cua SEM5_likert
dat_PSQT2 <- SEM5_likert [, c(1,2,8,45, 46, 47, 48, 49)]
head(dat_PSQT2)
##     AGE      CITY PSQT2 EC_Stop WC_Stop EC_Bus WC_Bus Gender
## 1 16-25 HoChiMinh     6   Never    Ever  Never   Ever Female
## 2 16-25 HoChiMinh     6   Never   Never   Ever  Never Female
## 3 16-25 HoChiMinh     2   Never   Never  Never  Never   Male
## 4 16-25 HoChiMinh     5   Never    Ever  Never   Ever   Male
## 5 16-25 HoChiMinh     3   Never    Ever  Never   Ever   Male
## 6 16-25 HoChiMinh     4   Never    Ever  Never   Ever Female
dim(dat_PSQT2)
## [1] 858   8
size <- 858
dat_PSQT2$BPE <- rep("PSQT2", size = size) # Tạo biến mới BPE
names(dat_PSQT2)[names(dat_PSQT2) == "PSQT2"] <- "Res" # Đổi tên biến BST thành Res
head(dat_PSQT2)
##     AGE      CITY Res EC_Stop WC_Stop EC_Bus WC_Bus Gender   BPE
## 1 16-25 HoChiMinh   6   Never    Ever  Never   Ever Female PSQT2
## 2 16-25 HoChiMinh   6   Never   Never   Ever  Never Female PSQT2
## 3 16-25 HoChiMinh   2   Never   Never  Never  Never   Male PSQT2
## 4 16-25 HoChiMinh   5   Never    Ever  Never   Ever   Male PSQT2
## 5 16-25 HoChiMinh   3   Never    Ever  Never   Ever   Male PSQT2
## 6 16-25 HoChiMinh   4   Never    Ever  Never   Ever Female PSQT2
## Creat dat_PSQT3 - cot 9 cua SEM5_likert
dat_PSQT3 <- SEM5_likert [, c(1,2,9,45, 46, 47, 48, 49)]
head(dat_PSQT3)
##     AGE      CITY PSQT3 EC_Stop WC_Stop EC_Bus WC_Bus Gender
## 1 16-25 HoChiMinh     4   Never    Ever  Never   Ever Female
## 2 16-25 HoChiMinh     5   Never   Never   Ever  Never Female
## 3 16-25 HoChiMinh     2   Never   Never  Never  Never   Male
## 4 16-25 HoChiMinh     4   Never    Ever  Never   Ever   Male
## 5 16-25 HoChiMinh     6   Never    Ever  Never   Ever   Male
## 6 16-25 HoChiMinh     5   Never    Ever  Never   Ever Female
dim(dat_PSQT3)
## [1] 858   8
size <- 858
dat_PSQT3$BPE <- rep("PSQT3", size = size) # Tạo biến mới BPE
names(dat_PSQT3)[names(dat_PSQT3) == "PSQT3"] <- "Res" # Đổi tên biến BST thành Res
head(dat_PSQT3)
##     AGE      CITY Res EC_Stop WC_Stop EC_Bus WC_Bus Gender   BPE
## 1 16-25 HoChiMinh   4   Never    Ever  Never   Ever Female PSQT3
## 2 16-25 HoChiMinh   5   Never   Never   Ever  Never Female PSQT3
## 3 16-25 HoChiMinh   2   Never   Never  Never  Never   Male PSQT3
## 4 16-25 HoChiMinh   4   Never    Ever  Never   Ever   Male PSQT3
## 5 16-25 HoChiMinh   6   Never    Ever  Never   Ever   Male PSQT3
## 6 16-25 HoChiMinh   5   Never    Ever  Never   Ever Female PSQT3
## Creat dat_PSQT4 - cot 10 cua SEM5_likert
dat_PSQT4 <- SEM5_likert [, c(1,2,10,45, 46, 47, 48, 49)]
head(dat_PSQT4)
##     AGE      CITY PSQT4 EC_Stop WC_Stop EC_Bus WC_Bus Gender
## 1 16-25 HoChiMinh     4   Never    Ever  Never   Ever Female
## 2 16-25 HoChiMinh     4   Never   Never   Ever  Never Female
## 3 16-25 HoChiMinh     2   Never   Never  Never  Never   Male
## 4 16-25 HoChiMinh     5   Never    Ever  Never   Ever   Male
## 5 16-25 HoChiMinh     3   Never    Ever  Never   Ever   Male
## 6 16-25 HoChiMinh     4   Never    Ever  Never   Ever Female
dim(dat_PSQT4)
## [1] 858   8
size <- 858
dat_PSQT4$BPE <- rep("PSQT4", size = size) # Tạo biến mới BPE
names(dat_PSQT4)[names(dat_PSQT4) == "PSQT4"] <- "Res" # Đổi tên biến BST thành Res
head(dat_PSQT4)
##     AGE      CITY Res EC_Stop WC_Stop EC_Bus WC_Bus Gender   BPE
## 1 16-25 HoChiMinh   4   Never    Ever  Never   Ever Female PSQT4
## 2 16-25 HoChiMinh   4   Never   Never   Ever  Never Female PSQT4
## 3 16-25 HoChiMinh   2   Never   Never  Never  Never   Male PSQT4
## 4 16-25 HoChiMinh   5   Never    Ever  Never   Ever   Male PSQT4
## 5 16-25 HoChiMinh   3   Never    Ever  Never   Ever   Male PSQT4
## 6 16-25 HoChiMinh   4   Never    Ever  Never   Ever Female PSQT4
## Creat dat_PSQC1 - cot 11 cua SEM5_likert
dat_PSQC1 <- SEM5_likert [, c(1,2,11,45, 46, 47, 48, 49)]
head(dat_PSQC1)
##     AGE      CITY PSQC1 EC_Stop WC_Stop EC_Bus WC_Bus Gender
## 1 16-25 HoChiMinh     6   Never    Ever  Never   Ever Female
## 2 16-25 HoChiMinh     4   Never   Never   Ever  Never Female
## 3 16-25 HoChiMinh     2   Never   Never  Never  Never   Male
## 4 16-25 HoChiMinh     5   Never    Ever  Never   Ever   Male
## 5 16-25 HoChiMinh     6   Never    Ever  Never   Ever   Male
## 6 16-25 HoChiMinh     5   Never    Ever  Never   Ever Female
dim(dat_PSQC1)
## [1] 858   8
size <- 858
dat_PSQC1$BPE <- rep("PSQC1", size = size) # Tạo biến mới BPE
names(dat_PSQC1)[names(dat_PSQC1) == "PSQC1"] <- "Res" # Đổi tên biến BST thành Res
head(dat_PSQC1)
##     AGE      CITY Res EC_Stop WC_Stop EC_Bus WC_Bus Gender   BPE
## 1 16-25 HoChiMinh   6   Never    Ever  Never   Ever Female PSQC1
## 2 16-25 HoChiMinh   4   Never   Never   Ever  Never Female PSQC1
## 3 16-25 HoChiMinh   2   Never   Never  Never  Never   Male PSQC1
## 4 16-25 HoChiMinh   5   Never    Ever  Never   Ever   Male PSQC1
## 5 16-25 HoChiMinh   6   Never    Ever  Never   Ever   Male PSQC1
## 6 16-25 HoChiMinh   5   Never    Ever  Never   Ever Female PSQC1
## Creat dat_PSQC2 - cot 12 cua SEM5_likert
dat_PSQC2 <- SEM5_likert [, c(1,2,12,45, 46, 47, 48, 49)]
head(dat_PSQC2)
##     AGE      CITY PSQC2 EC_Stop WC_Stop EC_Bus WC_Bus Gender
## 1 16-25 HoChiMinh     4   Never    Ever  Never   Ever Female
## 2 16-25 HoChiMinh     5   Never   Never   Ever  Never Female
## 3 16-25 HoChiMinh     4   Never   Never  Never  Never   Male
## 4 16-25 HoChiMinh     5   Never    Ever  Never   Ever   Male
## 5 16-25 HoChiMinh     6   Never    Ever  Never   Ever   Male
## 6 16-25 HoChiMinh     5   Never    Ever  Never   Ever Female
dim(dat_PSQC2)
## [1] 858   8
size <- 858
dat_PSQC2$BPE <- rep("PSQC2", size = size) # Tạo biến mới BPE
names(dat_PSQC2)[names(dat_PSQC2) == "PSQC2"] <- "Res" # Đổi tên biến BST thành Res
head(dat_PSQC2)
##     AGE      CITY Res EC_Stop WC_Stop EC_Bus WC_Bus Gender   BPE
## 1 16-25 HoChiMinh   4   Never    Ever  Never   Ever Female PSQC2
## 2 16-25 HoChiMinh   5   Never   Never   Ever  Never Female PSQC2
## 3 16-25 HoChiMinh   4   Never   Never  Never  Never   Male PSQC2
## 4 16-25 HoChiMinh   5   Never    Ever  Never   Ever   Male PSQC2
## 5 16-25 HoChiMinh   6   Never    Ever  Never   Ever   Male PSQC2
## 6 16-25 HoChiMinh   5   Never    Ever  Never   Ever Female PSQC2
## Creat dat_PSQC3 - cot 13 cua SEM5_likert
dat_PSQC3 <- SEM5_likert [, c(1,2,13,45, 46, 47, 48, 49)]
head(dat_PSQC3)
##     AGE      CITY PSQC3 EC_Stop WC_Stop EC_Bus WC_Bus Gender
## 1 16-25 HoChiMinh     4   Never    Ever  Never   Ever Female
## 2 16-25 HoChiMinh     6   Never   Never   Ever  Never Female
## 3 16-25 HoChiMinh     1   Never   Never  Never  Never   Male
## 4 16-25 HoChiMinh     5   Never    Ever  Never   Ever   Male
## 5 16-25 HoChiMinh     4   Never    Ever  Never   Ever   Male
## 6 16-25 HoChiMinh     4   Never    Ever  Never   Ever Female
dim(dat_PSQC3)
## [1] 858   8
size <- 858
dat_PSQC3$BPE <- rep("PSQC3", size = size) # Tạo biến mới BPE
names(dat_PSQC3)[names(dat_PSQC3) == "PSQC3"] <- "Res" # Đổi tên biến BST thành Res
head(dat_PSQC3)
##     AGE      CITY Res EC_Stop WC_Stop EC_Bus WC_Bus Gender   BPE
## 1 16-25 HoChiMinh   4   Never    Ever  Never   Ever Female PSQC3
## 2 16-25 HoChiMinh   6   Never   Never   Ever  Never Female PSQC3
## 3 16-25 HoChiMinh   1   Never   Never  Never  Never   Male PSQC3
## 4 16-25 HoChiMinh   5   Never    Ever  Never   Ever   Male PSQC3
## 5 16-25 HoChiMinh   4   Never    Ever  Never   Ever   Male PSQC3
## 6 16-25 HoChiMinh   4   Never    Ever  Never   Ever Female PSQC3
## Creat dat_PSQC4 - cot 14 cua SEM5_likert
dat_PSQC4 <- SEM5_likert [, c(1,2,14,45, 46, 47, 48, 49)]
head(dat_PSQC4)
##     AGE      CITY PSQC4 EC_Stop WC_Stop EC_Bus WC_Bus Gender
## 1 16-25 HoChiMinh     4   Never    Ever  Never   Ever Female
## 2 16-25 HoChiMinh     4   Never   Never   Ever  Never Female
## 3 16-25 HoChiMinh     2   Never   Never  Never  Never   Male
## 4 16-25 HoChiMinh     4   Never    Ever  Never   Ever   Male
## 5 16-25 HoChiMinh     3   Never    Ever  Never   Ever   Male
## 6 16-25 HoChiMinh     3   Never    Ever  Never   Ever Female
dim(dat_PSQC4)
## [1] 858   8
size <- 858
dat_PSQC4$BPE <- rep("PSQC4", size = size) # Tạo biến mới BPE
names(dat_PSQC4)[names(dat_PSQC4) == "PSQC4"] <- "Res" # Đổi tên biến BST thành Res
head(dat_PSQC4)
##     AGE      CITY Res EC_Stop WC_Stop EC_Bus WC_Bus Gender   BPE
## 1 16-25 HoChiMinh   4   Never    Ever  Never   Ever Female PSQC4
## 2 16-25 HoChiMinh   4   Never   Never   Ever  Never Female PSQC4
## 3 16-25 HoChiMinh   2   Never   Never  Never  Never   Male PSQC4
## 4 16-25 HoChiMinh   4   Never    Ever  Never   Ever   Male PSQC4
## 5 16-25 HoChiMinh   3   Never    Ever  Never   Ever   Male PSQC4
## 6 16-25 HoChiMinh   3   Never    Ever  Never   Ever Female PSQC4
## Creat dat_PSQC5 - cot 15 cua SEM5_likert
dat_PSQC5 <- SEM5_likert [, c(1,2,15,45, 46, 47, 48, 49)]
head(dat_PSQC5)
##     AGE      CITY PSQC5 EC_Stop WC_Stop EC_Bus WC_Bus Gender
## 1 16-25 HoChiMinh     6   Never    Ever  Never   Ever Female
## 2 16-25 HoChiMinh     6   Never   Never   Ever  Never Female
## 3 16-25 HoChiMinh     1   Never   Never  Never  Never   Male
## 4 16-25 HoChiMinh     4   Never    Ever  Never   Ever   Male
## 5 16-25 HoChiMinh     6   Never    Ever  Never   Ever   Male
## 6 16-25 HoChiMinh     3   Never    Ever  Never   Ever Female
dim(dat_PSQC5)
## [1] 858   8
size <- 858
dat_PSQC5$BPE <- rep("PSQC5", size = size) # Tạo biến mới BPE
names(dat_PSQC5)[names(dat_PSQC5) == "PSQC5"] <- "Res" # Đổi tên biến BST thành Res
head(dat_PSQC5)
##     AGE      CITY Res EC_Stop WC_Stop EC_Bus WC_Bus Gender   BPE
## 1 16-25 HoChiMinh   6   Never    Ever  Never   Ever Female PSQC5
## 2 16-25 HoChiMinh   6   Never   Never   Ever  Never Female PSQC5
## 3 16-25 HoChiMinh   1   Never   Never  Never  Never   Male PSQC5
## 4 16-25 HoChiMinh   4   Never    Ever  Never   Ever   Male PSQC5
## 5 16-25 HoChiMinh   6   Never    Ever  Never   Ever   Male PSQC5
## 6 16-25 HoChiMinh   3   Never    Ever  Never   Ever Female PSQC5
## Creat dat_PSQC6 - cot 24 cua SEM5_likert
dat_PSQC6 <- SEM5_likert [, c(1,2,24,45, 46, 47, 48, 49)]
head(dat_PSQC6)
##     AGE      CITY PSQC6 EC_Stop WC_Stop EC_Bus WC_Bus Gender
## 1 16-25 HoChiMinh     2   Never    Ever  Never   Ever Female
## 2 16-25 HoChiMinh     6   Never   Never   Ever  Never Female
## 3 16-25 HoChiMinh     2   Never   Never  Never  Never   Male
## 4 16-25 HoChiMinh     5   Never    Ever  Never   Ever   Male
## 5 16-25 HoChiMinh     5   Never    Ever  Never   Ever   Male
## 6 16-25 HoChiMinh     4   Never    Ever  Never   Ever Female
dim(dat_PSQC6)
## [1] 858   8
size <- 858
dat_PSQC6$BPE <- rep("PSQC6", size = size) # Tạo biến mới BPE
names(dat_PSQC6)[names(dat_PSQC6) == "PSQC6"] <- "Res" # Đổi tên biến BST thành Res
head(dat_PSQC6)
##     AGE      CITY Res EC_Stop WC_Stop EC_Bus WC_Bus Gender   BPE
## 1 16-25 HoChiMinh   2   Never    Ever  Never   Ever Female PSQC6
## 2 16-25 HoChiMinh   6   Never   Never   Ever  Never Female PSQC6
## 3 16-25 HoChiMinh   2   Never   Never  Never  Never   Male PSQC6
## 4 16-25 HoChiMinh   5   Never    Ever  Never   Ever   Male PSQC6
## 5 16-25 HoChiMinh   5   Never    Ever  Never   Ever   Male PSQC6
## 6 16-25 HoChiMinh   4   Never    Ever  Never   Ever Female PSQC6
## Creat dat_PSQP1 - cot 16 cua SEM5_likert
dat_PSQP1 <- SEM5_likert [, c(1,2,16,45, 46, 47, 48, 49)]
head(dat_PSQP1)
##     AGE      CITY PSQP1 EC_Stop WC_Stop EC_Bus WC_Bus Gender
## 1 16-25 HoChiMinh     6   Never    Ever  Never   Ever Female
## 2 16-25 HoChiMinh     6   Never   Never   Ever  Never Female
## 3 16-25 HoChiMinh     1   Never   Never  Never  Never   Male
## 4 16-25 HoChiMinh     5   Never    Ever  Never   Ever   Male
## 5 16-25 HoChiMinh     4   Never    Ever  Never   Ever   Male
## 6 16-25 HoChiMinh     4   Never    Ever  Never   Ever Female
dim(dat_PSQP1)
## [1] 858   8
size <- 858
dat_PSQP1$BPE <- rep("PSQP1", size = size) # Tạo biến mới BPE
names(dat_PSQP1)[names(dat_PSQP1) == "PSQP1"] <- "Res" # Đổi tên biến BST thành Res
head(dat_PSQP1)
##     AGE      CITY Res EC_Stop WC_Stop EC_Bus WC_Bus Gender   BPE
## 1 16-25 HoChiMinh   6   Never    Ever  Never   Ever Female PSQP1
## 2 16-25 HoChiMinh   6   Never   Never   Ever  Never Female PSQP1
## 3 16-25 HoChiMinh   1   Never   Never  Never  Never   Male PSQP1
## 4 16-25 HoChiMinh   5   Never    Ever  Never   Ever   Male PSQP1
## 5 16-25 HoChiMinh   4   Never    Ever  Never   Ever   Male PSQP1
## 6 16-25 HoChiMinh   4   Never    Ever  Never   Ever Female PSQP1
## Creat dat_PSQP2 - cot 17 cua SEM5_likert
dat_PSQP2 <- SEM5_likert [, c(1,2,17,45, 46, 47, 48, 49)]
head(dat_PSQP2)
##     AGE      CITY PSQP2 EC_Stop WC_Stop EC_Bus WC_Bus Gender
## 1 16-25 HoChiMinh     6   Never    Ever  Never   Ever Female
## 2 16-25 HoChiMinh     4   Never   Never   Ever  Never Female
## 3 16-25 HoChiMinh     1   Never   Never  Never  Never   Male
## 4 16-25 HoChiMinh     5   Never    Ever  Never   Ever   Male
## 5 16-25 HoChiMinh     4   Never    Ever  Never   Ever   Male
## 6 16-25 HoChiMinh     4   Never    Ever  Never   Ever Female
dim(dat_PSQP2)
## [1] 858   8
size <- 858
dat_PSQP2$BPE <- rep("PSQP2", size = size) # Tạo biến mới BPE
names(dat_PSQP2)[names(dat_PSQP2) == "PSQP2"] <- "Res" # Đổi tên biến BST thành Res
head(dat_PSQP2)
##     AGE      CITY Res EC_Stop WC_Stop EC_Bus WC_Bus Gender   BPE
## 1 16-25 HoChiMinh   6   Never    Ever  Never   Ever Female PSQP2
## 2 16-25 HoChiMinh   4   Never   Never   Ever  Never Female PSQP2
## 3 16-25 HoChiMinh   1   Never   Never  Never  Never   Male PSQP2
## 4 16-25 HoChiMinh   5   Never    Ever  Never   Ever   Male PSQP2
## 5 16-25 HoChiMinh   4   Never    Ever  Never   Ever   Male PSQP2
## 6 16-25 HoChiMinh   4   Never    Ever  Never   Ever Female PSQP2
## Creat dat_PSQP3 - cot 18 cua SEM5_likert
dat_PSQP3 <- SEM5_likert [, c(1,2,18,45, 46, 47, 48, 49)]
head(dat_PSQP3)
##     AGE      CITY PSQP3 EC_Stop WC_Stop EC_Bus WC_Bus Gender
## 1 16-25 HoChiMinh     5   Never    Ever  Never   Ever Female
## 2 16-25 HoChiMinh     4   Never   Never   Ever  Never Female
## 3 16-25 HoChiMinh     6   Never   Never  Never  Never   Male
## 4 16-25 HoChiMinh     5   Never    Ever  Never   Ever   Male
## 5 16-25 HoChiMinh     4   Never    Ever  Never   Ever   Male
## 6 16-25 HoChiMinh     4   Never    Ever  Never   Ever Female
dim(dat_PSQP3)
## [1] 858   8
size <- 858
dat_PSQP3$BPE <- rep("PSQP3", size = size) # Tạo biến mới BPE
names(dat_PSQP3)[names(dat_PSQP3) == "PSQP3"] <- "Res" # Đổi tên biến BST thành Res
head(dat_PSQP3)
##     AGE      CITY Res EC_Stop WC_Stop EC_Bus WC_Bus Gender   BPE
## 1 16-25 HoChiMinh   5   Never    Ever  Never   Ever Female PSQP3
## 2 16-25 HoChiMinh   4   Never   Never   Ever  Never Female PSQP3
## 3 16-25 HoChiMinh   6   Never   Never  Never  Never   Male PSQP3
## 4 16-25 HoChiMinh   5   Never    Ever  Never   Ever   Male PSQP3
## 5 16-25 HoChiMinh   4   Never    Ever  Never   Ever   Male PSQP3
## 6 16-25 HoChiMinh   4   Never    Ever  Never   Ever Female PSQP3
## Creat dat_PSQP4 - cot 19 cua SEM5_likert
dat_PSQP4 <- SEM5_likert [, c(1,2,19,45, 46, 47, 48, 49)]
head(dat_PSQP4)
##     AGE      CITY PSQP4 EC_Stop WC_Stop EC_Bus WC_Bus Gender
## 1 16-25 HoChiMinh     6   Never    Ever  Never   Ever Female
## 2 16-25 HoChiMinh     5   Never   Never   Ever  Never Female
## 3 16-25 HoChiMinh     6   Never   Never  Never  Never   Male
## 4 16-25 HoChiMinh     5   Never    Ever  Never   Ever   Male
## 5 16-25 HoChiMinh     5   Never    Ever  Never   Ever   Male
## 6 16-25 HoChiMinh     5   Never    Ever  Never   Ever Female
dim(dat_PSQP4)
## [1] 858   8
size <- 858
dat_PSQP4$BPE <- rep("PSQP4", size = size) # Tạo biến mới BPE
names(dat_PSQP4)[names(dat_PSQP4) == "PSQP4"] <- "Res" # Đổi tên biến BST thành Res
head(dat_PSQP4)
##     AGE      CITY Res EC_Stop WC_Stop EC_Bus WC_Bus Gender   BPE
## 1 16-25 HoChiMinh   6   Never    Ever  Never   Ever Female PSQP4
## 2 16-25 HoChiMinh   5   Never   Never   Ever  Never Female PSQP4
## 3 16-25 HoChiMinh   6   Never   Never  Never  Never   Male PSQP4
## 4 16-25 HoChiMinh   5   Never    Ever  Never   Ever   Male PSQP4
## 5 16-25 HoChiMinh   5   Never    Ever  Never   Ever   Male PSQP4
## 6 16-25 HoChiMinh   5   Never    Ever  Never   Ever Female PSQP4
## Creat dat_PSQR1 - cot 20 cua SEM5_likert
dat_PSQR1 <- SEM5_likert [, c(1,2,20,45, 46, 47, 48, 49)]
head(dat_PSQR1)
##     AGE      CITY PSQR1 EC_Stop WC_Stop EC_Bus WC_Bus Gender
## 1 16-25 HoChiMinh     4   Never    Ever  Never   Ever Female
## 2 16-25 HoChiMinh     4   Never   Never   Ever  Never Female
## 3 16-25 HoChiMinh     2   Never   Never  Never  Never   Male
## 4 16-25 HoChiMinh     4   Never    Ever  Never   Ever   Male
## 5 16-25 HoChiMinh     5   Never    Ever  Never   Ever   Male
## 6 16-25 HoChiMinh     3   Never    Ever  Never   Ever Female
dim(dat_PSQR1)
## [1] 858   8
size <- 858
dat_PSQR1$BPE <- rep("PSQR1", size = size) # Tạo biến mới BPE
names(dat_PSQR1)[names(dat_PSQR1) == "PSQR1"] <- "Res" # Đổi tên biến BST thành Res
head(dat_PSQR1)
##     AGE      CITY Res EC_Stop WC_Stop EC_Bus WC_Bus Gender   BPE
## 1 16-25 HoChiMinh   4   Never    Ever  Never   Ever Female PSQR1
## 2 16-25 HoChiMinh   4   Never   Never   Ever  Never Female PSQR1
## 3 16-25 HoChiMinh   2   Never   Never  Never  Never   Male PSQR1
## 4 16-25 HoChiMinh   4   Never    Ever  Never   Ever   Male PSQR1
## 5 16-25 HoChiMinh   5   Never    Ever  Never   Ever   Male PSQR1
## 6 16-25 HoChiMinh   3   Never    Ever  Never   Ever Female PSQR1
## Creat dat_PSQR2 - cot 21 cua SEM5_likert
dat_PSQR2 <- SEM5_likert [, c(1,2,21,45, 46, 47, 48, 49)]
head(dat_PSQR2)
##     AGE      CITY PSQR2 EC_Stop WC_Stop EC_Bus WC_Bus Gender
## 1 16-25 HoChiMinh     4   Never    Ever  Never   Ever Female
## 2 16-25 HoChiMinh     3   Never   Never   Ever  Never Female
## 3 16-25 HoChiMinh     6   Never   Never  Never  Never   Male
## 4 16-25 HoChiMinh     5   Never    Ever  Never   Ever   Male
## 5 16-25 HoChiMinh     3   Never    Ever  Never   Ever   Male
## 6 16-25 HoChiMinh     3   Never    Ever  Never   Ever Female
dim(dat_PSQR2)
## [1] 858   8
size <- 858
dat_PSQR2$BPE <- rep("PSQR2", size = size) # Tạo biến mới BPE
names(dat_PSQR2)[names(dat_PSQR2) == "PSQR2"] <- "Res" # Đổi tên biến BST thành Res
head(dat_PSQR2)
##     AGE      CITY Res EC_Stop WC_Stop EC_Bus WC_Bus Gender   BPE
## 1 16-25 HoChiMinh   4   Never    Ever  Never   Ever Female PSQR2
## 2 16-25 HoChiMinh   3   Never   Never   Ever  Never Female PSQR2
## 3 16-25 HoChiMinh   6   Never   Never  Never  Never   Male PSQR2
## 4 16-25 HoChiMinh   5   Never    Ever  Never   Ever   Male PSQR2
## 5 16-25 HoChiMinh   3   Never    Ever  Never   Ever   Male PSQR2
## 6 16-25 HoChiMinh   3   Never    Ever  Never   Ever Female PSQR2
## Creat dat_PSQR3 - cot 22 cua SEM5_likert
dat_PSQR3 <- SEM5_likert [, c(1,2,22,45, 46, 47, 48, 49)]
head(dat_PSQR3)
##     AGE      CITY PSQR3 EC_Stop WC_Stop EC_Bus WC_Bus Gender
## 1 16-25 HoChiMinh     6   Never    Ever  Never   Ever Female
## 2 16-25 HoChiMinh     4   Never   Never   Ever  Never Female
## 3 16-25 HoChiMinh     2   Never   Never  Never  Never   Male
## 4 16-25 HoChiMinh     5   Never    Ever  Never   Ever   Male
## 5 16-25 HoChiMinh     5   Never    Ever  Never   Ever   Male
## 6 16-25 HoChiMinh     3   Never    Ever  Never   Ever Female
dim(dat_PSQR3)
## [1] 858   8
size <- 858
dat_PSQR3$BPE <- rep("PSQR3", size = size) # Tạo biến mới BPE
names(dat_PSQR3)[names(dat_PSQR3) == "PSQR3"] <- "Res" # Đổi tên biến BST thành Res
head(dat_PSQR3)
##     AGE      CITY Res EC_Stop WC_Stop EC_Bus WC_Bus Gender   BPE
## 1 16-25 HoChiMinh   6   Never    Ever  Never   Ever Female PSQR3
## 2 16-25 HoChiMinh   4   Never   Never   Ever  Never Female PSQR3
## 3 16-25 HoChiMinh   2   Never   Never  Never  Never   Male PSQR3
## 4 16-25 HoChiMinh   5   Never    Ever  Never   Ever   Male PSQR3
## 5 16-25 HoChiMinh   5   Never    Ever  Never   Ever   Male PSQR3
## 6 16-25 HoChiMinh   3   Never    Ever  Never   Ever Female PSQR3
## Creat dat_PSQR4 - cot 23 cua SEM5_likert
dat_PSQR4 <- SEM5_likert [, c(1,2,23,45, 46, 47, 48, 49)]
head(dat_PSQR4)
##     AGE      CITY PSQR4 EC_Stop WC_Stop EC_Bus WC_Bus Gender
## 1 16-25 HoChiMinh     4   Never    Ever  Never   Ever Female
## 2 16-25 HoChiMinh     3   Never   Never   Ever  Never Female
## 3 16-25 HoChiMinh     5   Never   Never  Never  Never   Male
## 4 16-25 HoChiMinh     5   Never    Ever  Never   Ever   Male
## 5 16-25 HoChiMinh     3   Never    Ever  Never   Ever   Male
## 6 16-25 HoChiMinh     3   Never    Ever  Never   Ever Female
dim(dat_PSQR4)
## [1] 858   8
size <- 858
dat_PSQR4$BPE <- rep("PSQR4", size = size) # Tạo biến mới BPE
names(dat_PSQR4)[names(dat_PSQR4) == "PSQR4"] <- "Res" # Đổi tên biến BST thành Res
head(dat_PSQR4)
##     AGE      CITY Res EC_Stop WC_Stop EC_Bus WC_Bus Gender   BPE
## 1 16-25 HoChiMinh   4   Never    Ever  Never   Ever Female PSQR4
## 2 16-25 HoChiMinh   3   Never   Never   Ever  Never Female PSQR4
## 3 16-25 HoChiMinh   5   Never   Never  Never  Never   Male PSQR4
## 4 16-25 HoChiMinh   5   Never    Ever  Never   Ever   Male PSQR4
## 5 16-25 HoChiMinh   3   Never    Ever  Never   Ever   Male PSQR4
## 6 16-25 HoChiMinh   3   Never    Ever  Never   Ever Female PSQR4
## Creat dat_SAT1 - cot 25 cua SEM5_likert
dat_SAT1 <- SEM5_likert [, c(1,2,25,45, 46, 47, 48, 49)]
head(dat_SAT1)
##     AGE      CITY SAT1 EC_Stop WC_Stop EC_Bus WC_Bus Gender
## 1 16-25 HoChiMinh    6   Never    Ever  Never   Ever Female
## 2 16-25 HoChiMinh    5   Never   Never   Ever  Never Female
## 3 16-25 HoChiMinh    2   Never   Never  Never  Never   Male
## 4 16-25 HoChiMinh    5   Never    Ever  Never   Ever   Male
## 5 16-25 HoChiMinh    4   Never    Ever  Never   Ever   Male
## 6 16-25 HoChiMinh    4   Never    Ever  Never   Ever Female
dim(dat_SAT1)
## [1] 858   8
size <- 858
dat_SAT1$BPE <- rep("SAT1", size = size) # Tạo biến mới BPE
names(dat_SAT1)[names(dat_SAT1) == "SAT1"] <- "Res" # Đổi tên biến BST thành Res
head(dat_SAT1)
##     AGE      CITY Res EC_Stop WC_Stop EC_Bus WC_Bus Gender  BPE
## 1 16-25 HoChiMinh   6   Never    Ever  Never   Ever Female SAT1
## 2 16-25 HoChiMinh   5   Never   Never   Ever  Never Female SAT1
## 3 16-25 HoChiMinh   2   Never   Never  Never  Never   Male SAT1
## 4 16-25 HoChiMinh   5   Never    Ever  Never   Ever   Male SAT1
## 5 16-25 HoChiMinh   4   Never    Ever  Never   Ever   Male SAT1
## 6 16-25 HoChiMinh   4   Never    Ever  Never   Ever Female SAT1
## Creat dat_SAT2 - cot 26 cua SEM5_likert
dat_SAT2 <- SEM5_likert [, c(1,2,26,45, 46, 47, 48, 49)]
head(dat_SAT2)
##     AGE      CITY SAT2 EC_Stop WC_Stop EC_Bus WC_Bus Gender
## 1 16-25 HoChiMinh    6   Never    Ever  Never   Ever Female
## 2 16-25 HoChiMinh    5   Never   Never   Ever  Never Female
## 3 16-25 HoChiMinh    2   Never   Never  Never  Never   Male
## 4 16-25 HoChiMinh    5   Never    Ever  Never   Ever   Male
## 5 16-25 HoChiMinh    4   Never    Ever  Never   Ever   Male
## 6 16-25 HoChiMinh    5   Never    Ever  Never   Ever Female
dim(dat_SAT2)
## [1] 858   8
size <- 858
dat_SAT2$BPE <- rep("SAT2", size = size) # Tạo biến mới BPE
names(dat_SAT2)[names(dat_SAT2) == "SAT2"] <- "Res" # Đổi tên biến BST thành Res
head(dat_SAT2)
##     AGE      CITY Res EC_Stop WC_Stop EC_Bus WC_Bus Gender  BPE
## 1 16-25 HoChiMinh   6   Never    Ever  Never   Ever Female SAT2
## 2 16-25 HoChiMinh   5   Never   Never   Ever  Never Female SAT2
## 3 16-25 HoChiMinh   2   Never   Never  Never  Never   Male SAT2
## 4 16-25 HoChiMinh   5   Never    Ever  Never   Ever   Male SAT2
## 5 16-25 HoChiMinh   4   Never    Ever  Never   Ever   Male SAT2
## 6 16-25 HoChiMinh   5   Never    Ever  Never   Ever Female SAT2
## Creat dat_SAT3 - cot 27 cua SEM5_likert
dat_SAT3 <- SEM5_likert [, c(1,2,27,45, 46, 47, 48, 49)]
head(dat_SAT3)
##     AGE      CITY SAT3 EC_Stop WC_Stop EC_Bus WC_Bus Gender
## 1 16-25 HoChiMinh    6   Never    Ever  Never   Ever Female
## 2 16-25 HoChiMinh    4   Never   Never   Ever  Never Female
## 3 16-25 HoChiMinh    2   Never   Never  Never  Never   Male
## 4 16-25 HoChiMinh    5   Never    Ever  Never   Ever   Male
## 5 16-25 HoChiMinh    4   Never    Ever  Never   Ever   Male
## 6 16-25 HoChiMinh    5   Never    Ever  Never   Ever Female
dim(dat_SAT3)
## [1] 858   8
size <- 858
dat_SAT3$BPE <- rep("SAT3", size = size) # Tạo biến mới BPE
names(dat_SAT3)[names(dat_SAT3) == "SAT3"] <- "Res" # Đổi tên biến BST thành Res
head(dat_SAT3)
##     AGE      CITY Res EC_Stop WC_Stop EC_Bus WC_Bus Gender  BPE
## 1 16-25 HoChiMinh   6   Never    Ever  Never   Ever Female SAT3
## 2 16-25 HoChiMinh   4   Never   Never   Ever  Never Female SAT3
## 3 16-25 HoChiMinh   2   Never   Never  Never  Never   Male SAT3
## 4 16-25 HoChiMinh   5   Never    Ever  Never   Ever   Male SAT3
## 5 16-25 HoChiMinh   4   Never    Ever  Never   Ever   Male SAT3
## 6 16-25 HoChiMinh   5   Never    Ever  Never   Ever Female SAT3
## Creat dat_IMA1 - cot 28 cua SEN5_likert
dat_IMA1 <- SEM5_likert [, c(1,2,28,45, 46, 47, 48, 49)]
head(dat_IMA1)
##     AGE      CITY IMA1 EC_Stop WC_Stop EC_Bus WC_Bus Gender
## 1 16-25 HoChiMinh    6   Never    Ever  Never   Ever Female
## 2 16-25 HoChiMinh    4   Never   Never   Ever  Never Female
## 3 16-25 HoChiMinh    4   Never   Never  Never  Never   Male
## 4 16-25 HoChiMinh    5   Never    Ever  Never   Ever   Male
## 5 16-25 HoChiMinh    5   Never    Ever  Never   Ever   Male
## 6 16-25 HoChiMinh    4   Never    Ever  Never   Ever Female
dim(dat_IMA1)
## [1] 858   8
size <- 858
dat_IMA1$BPE <- rep("IMA1", size = size) # Tạo biến mới BPE
names(dat_IMA1)[names(dat_IMA1) == "IMA1"] <- "Res" # Đổi tên biến BST thành Res
head(dat_IMA1)
##     AGE      CITY Res EC_Stop WC_Stop EC_Bus WC_Bus Gender  BPE
## 1 16-25 HoChiMinh   6   Never    Ever  Never   Ever Female IMA1
## 2 16-25 HoChiMinh   4   Never   Never   Ever  Never Female IMA1
## 3 16-25 HoChiMinh   4   Never   Never  Never  Never   Male IMA1
## 4 16-25 HoChiMinh   5   Never    Ever  Never   Ever   Male IMA1
## 5 16-25 HoChiMinh   5   Never    Ever  Never   Ever   Male IMA1
## 6 16-25 HoChiMinh   4   Never    Ever  Never   Ever Female IMA1
## Creat dat_IMA2 - cot 29 cua SEM5_likert
dat_IMA2 <- SEM5_likert [, c(1,2,29,45, 46, 47, 48, 49)]
head(dat_IMA2)
##     AGE      CITY IMA2 EC_Stop WC_Stop EC_Bus WC_Bus Gender
## 1 16-25 HoChiMinh    6   Never    Ever  Never   Ever Female
## 2 16-25 HoChiMinh    5   Never   Never   Ever  Never Female
## 3 16-25 HoChiMinh    2   Never   Never  Never  Never   Male
## 4 16-25 HoChiMinh    5   Never    Ever  Never   Ever   Male
## 5 16-25 HoChiMinh    4   Never    Ever  Never   Ever   Male
## 6 16-25 HoChiMinh    3   Never    Ever  Never   Ever Female
dim(dat_IMA2)
## [1] 858   8
size <- 858
dat_IMA2$BPE <- rep("IMA2", size = size) # Tạo biến mới BPE
names(dat_IMA2)[names(dat_IMA2) == "IMA2"] <- "Res" # Đổi tên biến BST thành Res
head(dat_IMA2)
##     AGE      CITY Res EC_Stop WC_Stop EC_Bus WC_Bus Gender  BPE
## 1 16-25 HoChiMinh   6   Never    Ever  Never   Ever Female IMA2
## 2 16-25 HoChiMinh   5   Never   Never   Ever  Never Female IMA2
## 3 16-25 HoChiMinh   2   Never   Never  Never  Never   Male IMA2
## 4 16-25 HoChiMinh   5   Never    Ever  Never   Ever   Male IMA2
## 5 16-25 HoChiMinh   4   Never    Ever  Never   Ever   Male IMA2
## 6 16-25 HoChiMinh   3   Never    Ever  Never   Ever Female IMA2
## Creat dat_IMA3 - cot 30 cua SEM5_likert
dat_IMA3 <- SEM5_likert [, c(1,2,30,45, 46, 47, 48, 49)]
head(dat_IMA3)
##     AGE      CITY IMA3 EC_Stop WC_Stop EC_Bus WC_Bus Gender
## 1 16-25 HoChiMinh    6   Never    Ever  Never   Ever Female
## 2 16-25 HoChiMinh    6   Never   Never   Ever  Never Female
## 3 16-25 HoChiMinh    5   Never   Never  Never  Never   Male
## 4 16-25 HoChiMinh    5   Never    Ever  Never   Ever   Male
## 5 16-25 HoChiMinh    5   Never    Ever  Never   Ever   Male
## 6 16-25 HoChiMinh    2   Never    Ever  Never   Ever Female
dim(dat_IMA3)
## [1] 858   8
size <- 858
dat_IMA3$BPE <- rep("IMA3", size = size) # Tạo biến mới BPE
names(dat_IMA3)[names(dat_IMA3) == "IMA3"] <- "Res" # Đổi tên biến BST thành Res
head(dat_IMA3)
##     AGE      CITY Res EC_Stop WC_Stop EC_Bus WC_Bus Gender  BPE
## 1 16-25 HoChiMinh   6   Never    Ever  Never   Ever Female IMA3
## 2 16-25 HoChiMinh   6   Never   Never   Ever  Never Female IMA3
## 3 16-25 HoChiMinh   5   Never   Never  Never  Never   Male IMA3
## 4 16-25 HoChiMinh   5   Never    Ever  Never   Ever   Male IMA3
## 5 16-25 HoChiMinh   5   Never    Ever  Never   Ever   Male IMA3
## 6 16-25 HoChiMinh   2   Never    Ever  Never   Ever Female IMA3
## Creat dat_IMA4 - cot 31 cua SEM5_likert
dat_IMA4 <- SEM5_likert [, c(1,2,31,45, 46, 47, 48, 49)]
head(dat_IMA4)
##     AGE      CITY IMA4 EC_Stop WC_Stop EC_Bus WC_Bus Gender
## 1 16-25 HoChiMinh    4   Never    Ever  Never   Ever Female
## 2 16-25 HoChiMinh    5   Never   Never   Ever  Never Female
## 3 16-25 HoChiMinh    2   Never   Never  Never  Never   Male
## 4 16-25 HoChiMinh    5   Never    Ever  Never   Ever   Male
## 5 16-25 HoChiMinh    4   Never    Ever  Never   Ever   Male
## 6 16-25 HoChiMinh    2   Never    Ever  Never   Ever Female
dim(dat_IMA4)
## [1] 858   8
size <- 858
dat_IMA4$BPE <- rep("IMA4", size = size) # Tạo biến mới BPE
names(dat_IMA4)[names(dat_IMA4) == "IMA4"] <- "Res" # Đổi tên biến BST thành Res
head(dat_IMA4)
##     AGE      CITY Res EC_Stop WC_Stop EC_Bus WC_Bus Gender  BPE
## 1 16-25 HoChiMinh   4   Never    Ever  Never   Ever Female IMA4
## 2 16-25 HoChiMinh   5   Never   Never   Ever  Never Female IMA4
## 3 16-25 HoChiMinh   2   Never   Never  Never  Never   Male IMA4
## 4 16-25 HoChiMinh   5   Never    Ever  Never   Ever   Male IMA4
## 5 16-25 HoChiMinh   4   Never    Ever  Never   Ever   Male IMA4
## 6 16-25 HoChiMinh   2   Never    Ever  Never   Ever Female IMA4
dim(dat_IMA4)
## [1] 858   9
## Creat dat_IMA5 - cot 32 cua SEM5_likert
dat_IMA5 <- SEM5_likert [, c(1,2,32,45, 46, 47, 48, 49)]
head(dat_IMA5)
##     AGE      CITY IMA5 EC_Stop WC_Stop EC_Bus WC_Bus Gender
## 1 16-25 HoChiMinh    6   Never    Ever  Never   Ever Female
## 2 16-25 HoChiMinh    4   Never   Never   Ever  Never Female
## 3 16-25 HoChiMinh    2   Never   Never  Never  Never   Male
## 4 16-25 HoChiMinh    5   Never    Ever  Never   Ever   Male
## 5 16-25 HoChiMinh    5   Never    Ever  Never   Ever   Male
## 6 16-25 HoChiMinh    4   Never    Ever  Never   Ever Female
dim(dat_IMA5)
## [1] 858   8
size <- 858
dat_IMA5$BPE <- rep("IMA5", size = size) # Tạo biến mới BPE
names(dat_IMA5)[names(dat_IMA5) == "IMA5"] <- "Res" # Đổi tên biến BST thành Res
head(dat_IMA5)
##     AGE      CITY Res EC_Stop WC_Stop EC_Bus WC_Bus Gender  BPE
## 1 16-25 HoChiMinh   6   Never    Ever  Never   Ever Female IMA5
## 2 16-25 HoChiMinh   4   Never   Never   Ever  Never Female IMA5
## 3 16-25 HoChiMinh   2   Never   Never  Never  Never   Male IMA5
## 4 16-25 HoChiMinh   5   Never    Ever  Never   Ever   Male IMA5
## 5 16-25 HoChiMinh   5   Never    Ever  Never   Ever   Male IMA5
## 6 16-25 HoChiMinh   4   Never    Ever  Never   Ever Female IMA5
dim(dat_IMA5)
## [1] 858   9
## Creat dat_PHB1 - cot 33 cua SEM5_likert
dat_PHB1 <- SEM5_likert [, c(1,2,33,45, 46, 47, 48, 49)]
head(dat_PHB1)
##     AGE      CITY PHB1 EC_Stop WC_Stop EC_Bus WC_Bus Gender
## 1 16-25 HoChiMinh    6   Never    Ever  Never   Ever Female
## 2 16-25 HoChiMinh    3   Never   Never   Ever  Never Female
## 3 16-25 HoChiMinh    5   Never   Never  Never  Never   Male
## 4 16-25 HoChiMinh    5   Never    Ever  Never   Ever   Male
## 5 16-25 HoChiMinh    5   Never    Ever  Never   Ever   Male
## 6 16-25 HoChiMinh    4   Never    Ever  Never   Ever Female
dim(dat_PHB1)
## [1] 858   8
size <- 858
dat_PHB1$BPE <- rep("PHB1", size = size) # Tạo biến mới BPE
names(dat_PHB1)[names(dat_PHB1) == "PHB1"] <- "Res" # Đổi tên biến BST thành Res
head(dat_PHB1)
##     AGE      CITY Res EC_Stop WC_Stop EC_Bus WC_Bus Gender  BPE
## 1 16-25 HoChiMinh   6   Never    Ever  Never   Ever Female PHB1
## 2 16-25 HoChiMinh   3   Never   Never   Ever  Never Female PHB1
## 3 16-25 HoChiMinh   5   Never   Never  Never  Never   Male PHB1
## 4 16-25 HoChiMinh   5   Never    Ever  Never   Ever   Male PHB1
## 5 16-25 HoChiMinh   5   Never    Ever  Never   Ever   Male PHB1
## 6 16-25 HoChiMinh   4   Never    Ever  Never   Ever Female PHB1
dim(dat_PHB1)
## [1] 858   9
## Creat dat_PHB2 - cot 34 cua SEM5_likert
dat_PHB2 <- SEM5_likert [, c(1,2,34,45, 46, 47, 48, 49)]
head(dat_PHB2)
##     AGE      CITY PHB2 EC_Stop WC_Stop EC_Bus WC_Bus Gender
## 1 16-25 HoChiMinh    7   Never    Ever  Never   Ever Female
## 2 16-25 HoChiMinh    4   Never   Never   Ever  Never Female
## 3 16-25 HoChiMinh    2   Never   Never  Never  Never   Male
## 4 16-25 HoChiMinh    5   Never    Ever  Never   Ever   Male
## 5 16-25 HoChiMinh    6   Never    Ever  Never   Ever   Male
## 6 16-25 HoChiMinh    6   Never    Ever  Never   Ever Female
dim(dat_PHB2)
## [1] 858   8
size <- 858
dat_PHB2$BPE <- rep("PHB2", size = size) # Tạo biến mới BPE
names(dat_PHB2)[names(dat_PHB2) == "PHB2"] <- "Res" # Đổi tên biến BST thành Res
head(dat_PHB2)
##     AGE      CITY Res EC_Stop WC_Stop EC_Bus WC_Bus Gender  BPE
## 1 16-25 HoChiMinh   7   Never    Ever  Never   Ever Female PHB2
## 2 16-25 HoChiMinh   4   Never   Never   Ever  Never Female PHB2
## 3 16-25 HoChiMinh   2   Never   Never  Never  Never   Male PHB2
## 4 16-25 HoChiMinh   5   Never    Ever  Never   Ever   Male PHB2
## 5 16-25 HoChiMinh   6   Never    Ever  Never   Ever   Male PHB2
## 6 16-25 HoChiMinh   6   Never    Ever  Never   Ever Female PHB2
dim(dat_PHB2)
## [1] 858   9
## Creat dat_PHB3 - cot 35 cua SEM5_likert
dat_PHB3 <- SEM5_likert [, c(1,2,35,45, 46, 47, 48, 49)]
head(dat_PHB3)
##     AGE      CITY PHB3 EC_Stop WC_Stop EC_Bus WC_Bus Gender
## 1 16-25 HoChiMinh    6   Never    Ever  Never   Ever Female
## 2 16-25 HoChiMinh    3   Never   Never   Ever  Never Female
## 3 16-25 HoChiMinh    6   Never   Never  Never  Never   Male
## 4 16-25 HoChiMinh    5   Never    Ever  Never   Ever   Male
## 5 16-25 HoChiMinh    6   Never    Ever  Never   Ever   Male
## 6 16-25 HoChiMinh    7   Never    Ever  Never   Ever Female
dim(dat_PHB3)
## [1] 858   8
size <- 858
dat_PHB3$BPE <- rep("PHB3", size = size) # Tạo biến mới BPE
names(dat_PHB3)[names(dat_PHB3) == "PHB3"] <- "Res" # Đổi tên biến BST thành Res
head(dat_PHB3)
##     AGE      CITY Res EC_Stop WC_Stop EC_Bus WC_Bus Gender  BPE
## 1 16-25 HoChiMinh   6   Never    Ever  Never   Ever Female PHB3
## 2 16-25 HoChiMinh   3   Never   Never   Ever  Never Female PHB3
## 3 16-25 HoChiMinh   6   Never   Never  Never  Never   Male PHB3
## 4 16-25 HoChiMinh   5   Never    Ever  Never   Ever   Male PHB3
## 5 16-25 HoChiMinh   6   Never    Ever  Never   Ever   Male PHB3
## 6 16-25 HoChiMinh   7   Never    Ever  Never   Ever Female PHB3
dim(dat_PHB3)
## [1] 858   9
## Creat dat_PHB4 - cot 36 cua SEM5_likert
dat_PHB4 <- SEM5_likert [, c(1,2,36,45, 46, 47, 48, 49)]
head(dat_PHB4)
##     AGE      CITY PHB4 EC_Stop WC_Stop EC_Bus WC_Bus Gender
## 1 16-25 HoChiMinh    7   Never    Ever  Never   Ever Female
## 2 16-25 HoChiMinh    4   Never   Never   Ever  Never Female
## 3 16-25 HoChiMinh    6   Never   Never  Never  Never   Male
## 4 16-25 HoChiMinh    5   Never    Ever  Never   Ever   Male
## 5 16-25 HoChiMinh    6   Never    Ever  Never   Ever   Male
## 6 16-25 HoChiMinh    6   Never    Ever  Never   Ever Female
dim(dat_PHB4)
## [1] 858   8
size <- 858
dat_PHB4$BPE <- rep("PHB4", size = size) # Tạo biến mới BPE
names(dat_PHB4)[names(dat_PHB4) == "PHB4"] <- "Res" # Đổi tên biến BST thành Res
head(dat_PHB4)
##     AGE      CITY Res EC_Stop WC_Stop EC_Bus WC_Bus Gender  BPE
## 1 16-25 HoChiMinh   7   Never    Ever  Never   Ever Female PHB4
## 2 16-25 HoChiMinh   4   Never   Never   Ever  Never Female PHB4
## 3 16-25 HoChiMinh   6   Never   Never  Never  Never   Male PHB4
## 4 16-25 HoChiMinh   5   Never    Ever  Never   Ever   Male PHB4
## 5 16-25 HoChiMinh   6   Never    Ever  Never   Ever   Male PHB4
## 6 16-25 HoChiMinh   6   Never    Ever  Never   Ever Female PHB4
dim(dat_PHB4)
## [1] 858   9
## Creat dat_PHB5 - cot 37 cua SEM5_likert
dat_PHB5 <- SEM5_likert [, c(1,2,37,45, 46, 47, 48, 49)]
head(dat_PHB5)
##     AGE      CITY PHB5 EC_Stop WC_Stop EC_Bus WC_Bus Gender
## 1 16-25 HoChiMinh    7   Never    Ever  Never   Ever Female
## 2 16-25 HoChiMinh    6   Never   Never   Ever  Never Female
## 3 16-25 HoChiMinh    6   Never   Never  Never  Never   Male
## 4 16-25 HoChiMinh    5   Never    Ever  Never   Ever   Male
## 5 16-25 HoChiMinh    5   Never    Ever  Never   Ever   Male
## 6 16-25 HoChiMinh    4   Never    Ever  Never   Ever Female
dim(dat_PHB5)
## [1] 858   8
size <- 858
dat_PHB5$BPE <- rep("PHB5", size = size) # Tạo biến mới BPE
names(dat_PHB5)[names(dat_PHB5) == "PHB5"] <- "Res" # Đổi tên biến BST thành Res
head(dat_PHB5)
##     AGE      CITY Res EC_Stop WC_Stop EC_Bus WC_Bus Gender  BPE
## 1 16-25 HoChiMinh   7   Never    Ever  Never   Ever Female PHB5
## 2 16-25 HoChiMinh   6   Never   Never   Ever  Never Female PHB5
## 3 16-25 HoChiMinh   6   Never   Never  Never  Never   Male PHB5
## 4 16-25 HoChiMinh   5   Never    Ever  Never   Ever   Male PHB5
## 5 16-25 HoChiMinh   5   Never    Ever  Never   Ever   Male PHB5
## 6 16-25 HoChiMinh   4   Never    Ever  Never   Ever Female PHB5
dim(dat_PHB5)
## [1] 858   9
## Creat dat_PEB1 - cot 38 cua SEM5_likert
dat_PEB1 <- SEM5_likert [, c(1,2,38,45, 46, 47, 48, 49)]
head(dat_PEB1)
##     AGE      CITY PEB1 EC_Stop WC_Stop EC_Bus WC_Bus Gender
## 1 16-25 HoChiMinh    4   Never    Ever  Never   Ever Female
## 2 16-25 HoChiMinh    5   Never   Never   Ever  Never Female
## 3 16-25 HoChiMinh    6   Never   Never  Never  Never   Male
## 4 16-25 HoChiMinh    5   Never    Ever  Never   Ever   Male
## 5 16-25 HoChiMinh    6   Never    Ever  Never   Ever   Male
## 6 16-25 HoChiMinh    7   Never    Ever  Never   Ever Female
dim(dat_PEB1)
## [1] 858   8
size <- 858
dat_PEB1$BPE <- rep("PEB1", size = size) # Tạo biến mới BPE
names(dat_PEB1)[names(dat_PEB1) == "PEB1"] <- "Res" # Đổi tên biến BST thành Res
head(dat_PEB1)
##     AGE      CITY Res EC_Stop WC_Stop EC_Bus WC_Bus Gender  BPE
## 1 16-25 HoChiMinh   4   Never    Ever  Never   Ever Female PEB1
## 2 16-25 HoChiMinh   5   Never   Never   Ever  Never Female PEB1
## 3 16-25 HoChiMinh   6   Never   Never  Never  Never   Male PEB1
## 4 16-25 HoChiMinh   5   Never    Ever  Never   Ever   Male PEB1
## 5 16-25 HoChiMinh   6   Never    Ever  Never   Ever   Male PEB1
## 6 16-25 HoChiMinh   7   Never    Ever  Never   Ever Female PEB1
dim(dat_PEB1)
## [1] 858   9
## Creat dat_PEB2 - cot 39 cua SEM5_likert
dat_PEB2 <- SEM5_likert [, c(1,2,39,45, 46, 47, 48, 49)]
head(dat_PEB2)
##     AGE      CITY PEB2 EC_Stop WC_Stop EC_Bus WC_Bus Gender
## 1 16-25 HoChiMinh    4   Never    Ever  Never   Ever Female
## 2 16-25 HoChiMinh    6   Never   Never   Ever  Never Female
## 3 16-25 HoChiMinh    5   Never   Never  Never  Never   Male
## 4 16-25 HoChiMinh    5   Never    Ever  Never   Ever   Male
## 5 16-25 HoChiMinh    6   Never    Ever  Never   Ever   Male
## 6 16-25 HoChiMinh    7   Never    Ever  Never   Ever Female
dim(dat_PEB2)
## [1] 858   8
size <- 858
dat_PEB2$BPE <- rep("PEB2", size = size) # Tạo biến mới BPE
names(dat_PEB2)[names(dat_PEB2) == "PEB2"] <- "Res" # Đổi tên biến BST thành Res
head(dat_PEB2)
##     AGE      CITY Res EC_Stop WC_Stop EC_Bus WC_Bus Gender  BPE
## 1 16-25 HoChiMinh   4   Never    Ever  Never   Ever Female PEB2
## 2 16-25 HoChiMinh   6   Never   Never   Ever  Never Female PEB2
## 3 16-25 HoChiMinh   5   Never   Never  Never  Never   Male PEB2
## 4 16-25 HoChiMinh   5   Never    Ever  Never   Ever   Male PEB2
## 5 16-25 HoChiMinh   6   Never    Ever  Never   Ever   Male PEB2
## 6 16-25 HoChiMinh   7   Never    Ever  Never   Ever Female PEB2
dim(dat_PEB2)
## [1] 858   9
## Creat dat_PEB3 - cot 40 cua SEM5_likert
dat_PEB3 <- SEM5_likert [, c(1,2,40,45, 46, 47, 48, 49)]
head(dat_PEB3)
##     AGE      CITY PEB3 EC_Stop WC_Stop EC_Bus WC_Bus Gender
## 1 16-25 HoChiMinh    4   Never    Ever  Never   Ever Female
## 2 16-25 HoChiMinh    6   Never   Never   Ever  Never Female
## 3 16-25 HoChiMinh    6   Never   Never  Never  Never   Male
## 4 16-25 HoChiMinh    5   Never    Ever  Never   Ever   Male
## 5 16-25 HoChiMinh    6   Never    Ever  Never   Ever   Male
## 6 16-25 HoChiMinh    5   Never    Ever  Never   Ever Female
dim(dat_PEB3)
## [1] 858   8
size <- 858
dat_PEB3$BPE <- rep("PEB3", size = size) # Tạo biến mới BPE
names(dat_PEB3)[names(dat_PEB3) == "PEB3"] <- "Res" # Đổi tên biến BST thành Res
head(dat_PEB3)
##     AGE      CITY Res EC_Stop WC_Stop EC_Bus WC_Bus Gender  BPE
## 1 16-25 HoChiMinh   4   Never    Ever  Never   Ever Female PEB3
## 2 16-25 HoChiMinh   6   Never   Never   Ever  Never Female PEB3
## 3 16-25 HoChiMinh   6   Never   Never  Never  Never   Male PEB3
## 4 16-25 HoChiMinh   5   Never    Ever  Never   Ever   Male PEB3
## 5 16-25 HoChiMinh   6   Never    Ever  Never   Ever   Male PEB3
## 6 16-25 HoChiMinh   5   Never    Ever  Never   Ever Female PEB3
dim(dat_PEB3)
## [1] 858   9
## Creat dat_PEB4 - cot 41 cua SEM5_likert
dat_PEB4 <- SEM5_likert [, c(1,2,41,45, 46, 47, 48, 49)]
head(dat_PEB4)
##     AGE      CITY PEB4 EC_Stop WC_Stop EC_Bus WC_Bus Gender
## 1 16-25 HoChiMinh    4   Never    Ever  Never   Ever Female
## 2 16-25 HoChiMinh    4   Never   Never   Ever  Never Female
## 3 16-25 HoChiMinh    6   Never   Never  Never  Never   Male
## 4 16-25 HoChiMinh    5   Never    Ever  Never   Ever   Male
## 5 16-25 HoChiMinh    6   Never    Ever  Never   Ever   Male
## 6 16-25 HoChiMinh    2   Never    Ever  Never   Ever Female
dim(dat_PEB4)
## [1] 858   8
size <- 858
dat_PEB4$BPE <- rep("PEB4", size = size) # Tạo biến mới BPE
names(dat_PEB4)[names(dat_PEB4) == "PEB4"] <- "Res" # Đổi tên biến BST thành Res
head(dat_PEB4)
##     AGE      CITY Res EC_Stop WC_Stop EC_Bus WC_Bus Gender  BPE
## 1 16-25 HoChiMinh   4   Never    Ever  Never   Ever Female PEB4
## 2 16-25 HoChiMinh   4   Never   Never   Ever  Never Female PEB4
## 3 16-25 HoChiMinh   6   Never   Never  Never  Never   Male PEB4
## 4 16-25 HoChiMinh   5   Never    Ever  Never   Ever   Male PEB4
## 5 16-25 HoChiMinh   6   Never    Ever  Never   Ever   Male PEB4
## 6 16-25 HoChiMinh   2   Never    Ever  Never   Ever Female PEB4
dim(dat_PEB4)
## [1] 858   9
## Creat dat_PVA1 - cot 42 cua SEM5_likert
dat_PVA1 <- SEM5_likert [, c(1,2,42,45, 46, 47, 48, 49)]
head(dat_PVA1)
##     AGE      CITY PVA1 EC_Stop WC_Stop EC_Bus WC_Bus Gender
## 1 16-25 HoChiMinh    6   Never    Ever  Never   Ever Female
## 2 16-25 HoChiMinh    5   Never   Never   Ever  Never Female
## 3 16-25 HoChiMinh    6   Never   Never  Never  Never   Male
## 4 16-25 HoChiMinh    5   Never    Ever  Never   Ever   Male
## 5 16-25 HoChiMinh    6   Never    Ever  Never   Ever   Male
## 6 16-25 HoChiMinh    6   Never    Ever  Never   Ever Female
dim(dat_PVA1)
## [1] 858   8
size <- 858
dat_PVA1$BPE <- rep("PVA1", size = size) # Tạo biến mới BPE
names(dat_PVA1)[names(dat_PVA1) == "PVA1"] <- "Res" # Đổi tên biến BST thành Res
head(dat_PVA1)
##     AGE      CITY Res EC_Stop WC_Stop EC_Bus WC_Bus Gender  BPE
## 1 16-25 HoChiMinh   6   Never    Ever  Never   Ever Female PVA1
## 2 16-25 HoChiMinh   5   Never   Never   Ever  Never Female PVA1
## 3 16-25 HoChiMinh   6   Never   Never  Never  Never   Male PVA1
## 4 16-25 HoChiMinh   5   Never    Ever  Never   Ever   Male PVA1
## 5 16-25 HoChiMinh   6   Never    Ever  Never   Ever   Male PVA1
## 6 16-25 HoChiMinh   6   Never    Ever  Never   Ever Female PVA1
dim(dat_PVA1)
## [1] 858   9
## Creat dat_PVA2 - cot 43 cua SEM5_likert
dat_PVA2 <- SEM5_likert [, c(1,2,43,45, 46, 47, 48, 49)]
head(dat_PVA2)
##     AGE      CITY PVA2 EC_Stop WC_Stop EC_Bus WC_Bus Gender
## 1 16-25 HoChiMinh    6   Never    Ever  Never   Ever Female
## 2 16-25 HoChiMinh    5   Never   Never   Ever  Never Female
## 3 16-25 HoChiMinh    2   Never   Never  Never  Never   Male
## 4 16-25 HoChiMinh    5   Never    Ever  Never   Ever   Male
## 5 16-25 HoChiMinh    2   Never    Ever  Never   Ever   Male
## 6 16-25 HoChiMinh    5   Never    Ever  Never   Ever Female
dim(dat_PVA2)
## [1] 858   8
size <- 858
dat_PVA2$BPE <- rep("PVA2", size = size) # Tạo biến mới BPE
names(dat_PVA2)[names(dat_PVA2) == "PVA2"] <- "Res" # Đổi tên biến BST thành Res
head(dat_PVA2)
##     AGE      CITY Res EC_Stop WC_Stop EC_Bus WC_Bus Gender  BPE
## 1 16-25 HoChiMinh   6   Never    Ever  Never   Ever Female PVA2
## 2 16-25 HoChiMinh   5   Never   Never   Ever  Never Female PVA2
## 3 16-25 HoChiMinh   2   Never   Never  Never  Never   Male PVA2
## 4 16-25 HoChiMinh   5   Never    Ever  Never   Ever   Male PVA2
## 5 16-25 HoChiMinh   2   Never    Ever  Never   Ever   Male PVA2
## 6 16-25 HoChiMinh   5   Never    Ever  Never   Ever Female PVA2
dim(dat_PVA2)
## [1] 858   9
## Creat dat_PVA3 - cot 44 cua SEM5_likert
dat_PVA3 <- SEM5_likert [, c(1,2,44,45, 46, 47, 48, 49)]
head(dat_PVA3)
##     AGE      CITY PVA3 EC_Stop WC_Stop EC_Bus WC_Bus Gender
## 1 16-25 HoChiMinh    6   Never    Ever  Never   Ever Female
## 2 16-25 HoChiMinh    3   Never   Never   Ever  Never Female
## 3 16-25 HoChiMinh    4   Never   Never  Never  Never   Male
## 4 16-25 HoChiMinh    5   Never    Ever  Never   Ever   Male
## 5 16-25 HoChiMinh    3   Never    Ever  Never   Ever   Male
## 6 16-25 HoChiMinh    5   Never    Ever  Never   Ever Female
dim(dat_PVA3)
## [1] 858   8
size <- 858
dat_PVA3$BPE <- rep("PVA3", size = size) # Tạo biến mới BPE
names(dat_PVA3)[names(dat_PVA3) == "PVA3"] <- "Res" # Đổi tên biến BST thành Res
head(dat_PVA3)
##     AGE      CITY Res EC_Stop WC_Stop EC_Bus WC_Bus Gender  BPE
## 1 16-25 HoChiMinh   6   Never    Ever  Never   Ever Female PVA3
## 2 16-25 HoChiMinh   3   Never   Never   Ever  Never Female PVA3
## 3 16-25 HoChiMinh   4   Never   Never  Never  Never   Male PVA3
## 4 16-25 HoChiMinh   5   Never    Ever  Never   Ever   Male PVA3
## 5 16-25 HoChiMinh   3   Never    Ever  Never   Ever   Male PVA3
## 6 16-25 HoChiMinh   5   Never    Ever  Never   Ever Female PVA3
dim(dat_PVA3)
## [1] 858   9
## Tạo dữ liệu likert từ 42 dữ liệu: dat_PSB1-4,dat_PSQT1-4, dat_PSQTC-6, dat_PSQP1-4, dat_PSQR1-4, dat_SAT1-3, dat_IMA1-5, dat_PHB1-5, dat_PEB1-4, dat_PVA1-3 
B.Per <- rbind(dat_PSB1, dat_PSB2, dat_PSB3, dat_PSB4, dat_PSQT1, dat_PSQT2, dat_PSQT3, dat_PSQT4, dat_PSQC1, dat_PSQC2, dat_PSQC3, dat_PSQC4, dat_PSQC5, dat_PSQC6, dat_PSQP1, dat_PSQP2, dat_PSQP3, dat_PSQP4, dat_PSQR1, dat_PSQR2, dat_PSQR3, dat_PSQR4, dat_SAT1, dat_SAT2, dat_SAT3, dat_IMA1, dat_IMA2, dat_IMA3, dat_IMA4, dat_IMA5, dat_PHB1, dat_PHB2, dat_PHB3, dat_PHB4, dat_PHB5, dat_PEB1, dat_PEB2, dat_PEB3, dat_PEB4, dat_PVA1, dat_PVA2, dat_PVA3)
head(B.Per)
##     AGE      CITY Res EC_Stop WC_Stop EC_Bus WC_Bus Gender  BPE
## 1 16-25 HoChiMinh   6   Never    Ever  Never   Ever Female PSB1
## 2 16-25 HoChiMinh   3   Never   Never   Ever  Never Female PSB1
## 3 16-25 HoChiMinh   2   Never   Never  Never  Never   Male PSB1
## 4 16-25 HoChiMinh   5   Never    Ever  Never   Ever   Male PSB1
## 5 16-25 HoChiMinh   2   Never    Ever  Never   Ever   Male PSB1
## 6 16-25 HoChiMinh   2   Never    Ever  Never   Ever Female PSB1
str(B.Per)
## 'data.frame':    36036 obs. of  9 variables:
##  $ AGE    : Factor w/ 5 levels "16-25","26-35",..: 1 1 1 1 1 1 1 3 1 1 ...
##  $ CITY   : Factor w/ 2 levels "DaNang","HoChiMinh": 2 2 2 2 2 2 2 2 2 2 ...
##  $ Res    : int  6 3 2 5 2 2 1 6 2 4 ...
##  $ EC_Stop: Factor w/ 2 levels "Never","Ever": 1 1 1 1 1 1 1 1 1 1 ...
##  $ WC_Stop: Factor w/ 2 levels "Never","Ever": 2 1 1 2 2 2 1 1 2 1 ...
##  $ EC_Bus : Factor w/ 2 levels "Never","Ever": 1 2 1 1 1 1 1 1 1 1 ...
##  $ WC_Bus : Factor w/ 2 levels "Never","Ever": 2 1 1 2 2 2 1 1 2 1 ...
##  $ Gender : Factor w/ 2 levels "Female","Male": 1 1 2 2 2 1 1 1 1 1 ...
##  $ BPE    : chr  "PSB1" "PSB1" "PSB1" "PSB1" ...
dim(B.Per)
## [1] 36036     9
## Tạo dữ liệu likert theo constructs
B.Per_PSB <- rbind(dat_PSB1, dat_PSB2, dat_PSB3, dat_PSB4)
head(B.Per_PSB)
##     AGE      CITY Res EC_Stop WC_Stop EC_Bus WC_Bus Gender  BPE
## 1 16-25 HoChiMinh   6   Never    Ever  Never   Ever Female PSB1
## 2 16-25 HoChiMinh   3   Never   Never   Ever  Never Female PSB1
## 3 16-25 HoChiMinh   2   Never   Never  Never  Never   Male PSB1
## 4 16-25 HoChiMinh   5   Never    Ever  Never   Ever   Male PSB1
## 5 16-25 HoChiMinh   2   Never    Ever  Never   Ever   Male PSB1
## 6 16-25 HoChiMinh   2   Never    Ever  Never   Ever Female PSB1
str(B.Per_PSB)
## 'data.frame':    3432 obs. of  9 variables:
##  $ AGE    : Factor w/ 5 levels "16-25","26-35",..: 1 1 1 1 1 1 1 3 1 1 ...
##  $ CITY   : Factor w/ 2 levels "DaNang","HoChiMinh": 2 2 2 2 2 2 2 2 2 2 ...
##  $ Res    : int  6 3 2 5 2 2 1 6 2 4 ...
##  $ EC_Stop: Factor w/ 2 levels "Never","Ever": 1 1 1 1 1 1 1 1 1 1 ...
##  $ WC_Stop: Factor w/ 2 levels "Never","Ever": 2 1 1 2 2 2 1 1 2 1 ...
##  $ EC_Bus : Factor w/ 2 levels "Never","Ever": 1 2 1 1 1 1 1 1 1 1 ...
##  $ WC_Bus : Factor w/ 2 levels "Never","Ever": 2 1 1 2 2 2 1 1 2 1 ...
##  $ Gender : Factor w/ 2 levels "Female","Male": 1 1 2 2 2 1 1 1 1 1 ...
##  $ BPE    : chr  "PSB1" "PSB1" "PSB1" "PSB1" ...
dim(B.Per_PSB)
## [1] 3432    9
B.Per_PSQT <- rbind(dat_PSQT1, dat_PSQT2, dat_PSQT3, dat_PSQT4)
head(B.Per_PSQT)
##     AGE      CITY Res EC_Stop WC_Stop EC_Bus WC_Bus Gender   BPE
## 1 16-25 HoChiMinh   6   Never    Ever  Never   Ever Female PSQT1
## 2 16-25 HoChiMinh   4   Never   Never   Ever  Never Female PSQT1
## 3 16-25 HoChiMinh   2   Never   Never  Never  Never   Male PSQT1
## 4 16-25 HoChiMinh   6   Never    Ever  Never   Ever   Male PSQT1
## 5 16-25 HoChiMinh   6   Never    Ever  Never   Ever   Male PSQT1
## 6 16-25 HoChiMinh   4   Never    Ever  Never   Ever Female PSQT1
str(B.Per_PSQT)
## 'data.frame':    3432 obs. of  9 variables:
##  $ AGE    : Factor w/ 5 levels "16-25","26-35",..: 1 1 1 1 1 1 1 3 1 1 ...
##  $ CITY   : Factor w/ 2 levels "DaNang","HoChiMinh": 2 2 2 2 2 2 2 2 2 2 ...
##  $ Res    : int  6 4 2 6 6 4 2 5 5 7 ...
##  $ EC_Stop: Factor w/ 2 levels "Never","Ever": 1 1 1 1 1 1 1 1 1 1 ...
##  $ WC_Stop: Factor w/ 2 levels "Never","Ever": 2 1 1 2 2 2 1 1 2 1 ...
##  $ EC_Bus : Factor w/ 2 levels "Never","Ever": 1 2 1 1 1 1 1 1 1 1 ...
##  $ WC_Bus : Factor w/ 2 levels "Never","Ever": 2 1 1 2 2 2 1 1 2 1 ...
##  $ Gender : Factor w/ 2 levels "Female","Male": 1 1 2 2 2 1 1 1 1 1 ...
##  $ BPE    : chr  "PSQT1" "PSQT1" "PSQT1" "PSQT1" ...
dim(B.Per_PSQT)
## [1] 3432    9
B.Per_PSQC <- rbind(dat_PSQC1, dat_PSQC2, dat_PSQC3, dat_PSQC4, dat_PSQC5, dat_PSQC6)
head(B.Per_PSQC)
##     AGE      CITY Res EC_Stop WC_Stop EC_Bus WC_Bus Gender   BPE
## 1 16-25 HoChiMinh   6   Never    Ever  Never   Ever Female PSQC1
## 2 16-25 HoChiMinh   4   Never   Never   Ever  Never Female PSQC1
## 3 16-25 HoChiMinh   2   Never   Never  Never  Never   Male PSQC1
## 4 16-25 HoChiMinh   5   Never    Ever  Never   Ever   Male PSQC1
## 5 16-25 HoChiMinh   6   Never    Ever  Never   Ever   Male PSQC1
## 6 16-25 HoChiMinh   5   Never    Ever  Never   Ever Female PSQC1
str(B.Per_PSQC)
## 'data.frame':    5148 obs. of  9 variables:
##  $ AGE    : Factor w/ 5 levels "16-25","26-35",..: 1 1 1 1 1 1 1 3 1 1 ...
##  $ CITY   : Factor w/ 2 levels "DaNang","HoChiMinh": 2 2 2 2 2 2 2 2 2 2 ...
##  $ Res    : int  6 4 2 5 6 5 2 6 3 7 ...
##  $ EC_Stop: Factor w/ 2 levels "Never","Ever": 1 1 1 1 1 1 1 1 1 1 ...
##  $ WC_Stop: Factor w/ 2 levels "Never","Ever": 2 1 1 2 2 2 1 1 2 1 ...
##  $ EC_Bus : Factor w/ 2 levels "Never","Ever": 1 2 1 1 1 1 1 1 1 1 ...
##  $ WC_Bus : Factor w/ 2 levels "Never","Ever": 2 1 1 2 2 2 1 1 2 1 ...
##  $ Gender : Factor w/ 2 levels "Female","Male": 1 1 2 2 2 1 1 1 1 1 ...
##  $ BPE    : chr  "PSQC1" "PSQC1" "PSQC1" "PSQC1" ...
dim(B.Per_PSQC)
## [1] 5148    9
B.Per_PSQP <- rbind(dat_PSQP1, dat_PSQP2, dat_PSQP3, dat_PSQP4)
head(B.Per_PSQP)
##     AGE      CITY Res EC_Stop WC_Stop EC_Bus WC_Bus Gender   BPE
## 1 16-25 HoChiMinh   6   Never    Ever  Never   Ever Female PSQP1
## 2 16-25 HoChiMinh   6   Never   Never   Ever  Never Female PSQP1
## 3 16-25 HoChiMinh   1   Never   Never  Never  Never   Male PSQP1
## 4 16-25 HoChiMinh   5   Never    Ever  Never   Ever   Male PSQP1
## 5 16-25 HoChiMinh   4   Never    Ever  Never   Ever   Male PSQP1
## 6 16-25 HoChiMinh   4   Never    Ever  Never   Ever Female PSQP1
str(B.Per_PSQP)
## 'data.frame':    3432 obs. of  9 variables:
##  $ AGE    : Factor w/ 5 levels "16-25","26-35",..: 1 1 1 1 1 1 1 3 1 1 ...
##  $ CITY   : Factor w/ 2 levels "DaNang","HoChiMinh": 2 2 2 2 2 2 2 2 2 2 ...
##  $ Res    : int  6 6 1 5 4 4 4 4 3 4 ...
##  $ EC_Stop: Factor w/ 2 levels "Never","Ever": 1 1 1 1 1 1 1 1 1 1 ...
##  $ WC_Stop: Factor w/ 2 levels "Never","Ever": 2 1 1 2 2 2 1 1 2 1 ...
##  $ EC_Bus : Factor w/ 2 levels "Never","Ever": 1 2 1 1 1 1 1 1 1 1 ...
##  $ WC_Bus : Factor w/ 2 levels "Never","Ever": 2 1 1 2 2 2 1 1 2 1 ...
##  $ Gender : Factor w/ 2 levels "Female","Male": 1 1 2 2 2 1 1 1 1 1 ...
##  $ BPE    : chr  "PSQP1" "PSQP1" "PSQP1" "PSQP1" ...
dim(B.Per_PSQP)
## [1] 3432    9
B.Per_PSQR <- rbind(dat_PSQR1, dat_PSQR2, dat_PSQR3, dat_PSQR4)
head(B.Per_PSQR)
##     AGE      CITY Res EC_Stop WC_Stop EC_Bus WC_Bus Gender   BPE
## 1 16-25 HoChiMinh   4   Never    Ever  Never   Ever Female PSQR1
## 2 16-25 HoChiMinh   4   Never   Never   Ever  Never Female PSQR1
## 3 16-25 HoChiMinh   2   Never   Never  Never  Never   Male PSQR1
## 4 16-25 HoChiMinh   4   Never    Ever  Never   Ever   Male PSQR1
## 5 16-25 HoChiMinh   5   Never    Ever  Never   Ever   Male PSQR1
## 6 16-25 HoChiMinh   3   Never    Ever  Never   Ever Female PSQR1
str(B.Per_PSQR)
## 'data.frame':    3432 obs. of  9 variables:
##  $ AGE    : Factor w/ 5 levels "16-25","26-35",..: 1 1 1 1 1 1 1 3 1 1 ...
##  $ CITY   : Factor w/ 2 levels "DaNang","HoChiMinh": 2 2 2 2 2 2 2 2 2 2 ...
##  $ Res    : int  4 4 2 4 5 3 2 5 3 4 ...
##  $ EC_Stop: Factor w/ 2 levels "Never","Ever": 1 1 1 1 1 1 1 1 1 1 ...
##  $ WC_Stop: Factor w/ 2 levels "Never","Ever": 2 1 1 2 2 2 1 1 2 1 ...
##  $ EC_Bus : Factor w/ 2 levels "Never","Ever": 1 2 1 1 1 1 1 1 1 1 ...
##  $ WC_Bus : Factor w/ 2 levels "Never","Ever": 2 1 1 2 2 2 1 1 2 1 ...
##  $ Gender : Factor w/ 2 levels "Female","Male": 1 1 2 2 2 1 1 1 1 1 ...
##  $ BPE    : chr  "PSQR1" "PSQR1" "PSQR1" "PSQR1" ...
dim(B.Per_PSQR)
## [1] 3432    9
B.Per_SAT <- rbind(dat_SAT1, dat_SAT2, dat_SAT3)
head(B.Per_SAT)
##     AGE      CITY Res EC_Stop WC_Stop EC_Bus WC_Bus Gender  BPE
## 1 16-25 HoChiMinh   6   Never    Ever  Never   Ever Female SAT1
## 2 16-25 HoChiMinh   5   Never   Never   Ever  Never Female SAT1
## 3 16-25 HoChiMinh   2   Never   Never  Never  Never   Male SAT1
## 4 16-25 HoChiMinh   5   Never    Ever  Never   Ever   Male SAT1
## 5 16-25 HoChiMinh   4   Never    Ever  Never   Ever   Male SAT1
## 6 16-25 HoChiMinh   4   Never    Ever  Never   Ever Female SAT1
str(B.Per_SAT)
## 'data.frame':    2574 obs. of  9 variables:
##  $ AGE    : Factor w/ 5 levels "16-25","26-35",..: 1 1 1 1 1 1 1 3 1 1 ...
##  $ CITY   : Factor w/ 2 levels "DaNang","HoChiMinh": 2 2 2 2 2 2 2 2 2 2 ...
##  $ Res    : int  6 5 2 5 4 4 2 7 5 7 ...
##  $ EC_Stop: Factor w/ 2 levels "Never","Ever": 1 1 1 1 1 1 1 1 1 1 ...
##  $ WC_Stop: Factor w/ 2 levels "Never","Ever": 2 1 1 2 2 2 1 1 2 1 ...
##  $ EC_Bus : Factor w/ 2 levels "Never","Ever": 1 2 1 1 1 1 1 1 1 1 ...
##  $ WC_Bus : Factor w/ 2 levels "Never","Ever": 2 1 1 2 2 2 1 1 2 1 ...
##  $ Gender : Factor w/ 2 levels "Female","Male": 1 1 2 2 2 1 1 1 1 1 ...
##  $ BPE    : chr  "SAT1" "SAT1" "SAT1" "SAT1" ...
dim(B.Per_SAT)
## [1] 2574    9
B.Per_IMA <- rbind(dat_IMA1, dat_IMA2, dat_IMA3, dat_IMA4, dat_IMA5)
head(B.Per_IMA)
##     AGE      CITY Res EC_Stop WC_Stop EC_Bus WC_Bus Gender  BPE
## 1 16-25 HoChiMinh   6   Never    Ever  Never   Ever Female IMA1
## 2 16-25 HoChiMinh   4   Never   Never   Ever  Never Female IMA1
## 3 16-25 HoChiMinh   4   Never   Never  Never  Never   Male IMA1
## 4 16-25 HoChiMinh   5   Never    Ever  Never   Ever   Male IMA1
## 5 16-25 HoChiMinh   5   Never    Ever  Never   Ever   Male IMA1
## 6 16-25 HoChiMinh   4   Never    Ever  Never   Ever Female IMA1
str(B.Per_IMA)
## 'data.frame':    4290 obs. of  9 variables:
##  $ AGE    : Factor w/ 5 levels "16-25","26-35",..: 1 1 1 1 1 1 1 3 1 1 ...
##  $ CITY   : Factor w/ 2 levels "DaNang","HoChiMinh": 2 2 2 2 2 2 2 2 2 2 ...
##  $ Res    : int  6 4 4 5 5 4 2 6 5 6 ...
##  $ EC_Stop: Factor w/ 2 levels "Never","Ever": 1 1 1 1 1 1 1 1 1 1 ...
##  $ WC_Stop: Factor w/ 2 levels "Never","Ever": 2 1 1 2 2 2 1 1 2 1 ...
##  $ EC_Bus : Factor w/ 2 levels "Never","Ever": 1 2 1 1 1 1 1 1 1 1 ...
##  $ WC_Bus : Factor w/ 2 levels "Never","Ever": 2 1 1 2 2 2 1 1 2 1 ...
##  $ Gender : Factor w/ 2 levels "Female","Male": 1 1 2 2 2 1 1 1 1 1 ...
##  $ BPE    : chr  "IMA1" "IMA1" "IMA1" "IMA1" ...
dim(B.Per_IMA)
## [1] 4290    9
B.Per_PHB <- rbind(dat_PHB1, dat_PHB2, dat_PHB3, dat_PHB4, dat_PHB5)
head(B.Per_PHB)
##     AGE      CITY Res EC_Stop WC_Stop EC_Bus WC_Bus Gender  BPE
## 1 16-25 HoChiMinh   6   Never    Ever  Never   Ever Female PHB1
## 2 16-25 HoChiMinh   3   Never   Never   Ever  Never Female PHB1
## 3 16-25 HoChiMinh   5   Never   Never  Never  Never   Male PHB1
## 4 16-25 HoChiMinh   5   Never    Ever  Never   Ever   Male PHB1
## 5 16-25 HoChiMinh   5   Never    Ever  Never   Ever   Male PHB1
## 6 16-25 HoChiMinh   4   Never    Ever  Never   Ever Female PHB1
str(B.Per_PHB)
## 'data.frame':    4290 obs. of  9 variables:
##  $ AGE    : Factor w/ 5 levels "16-25","26-35",..: 1 1 1 1 1 1 1 3 1 1 ...
##  $ CITY   : Factor w/ 2 levels "DaNang","HoChiMinh": 2 2 2 2 2 2 2 2 2 2 ...
##  $ Res    : int  6 3 5 5 5 4 3 6 6 7 ...
##  $ EC_Stop: Factor w/ 2 levels "Never","Ever": 1 1 1 1 1 1 1 1 1 1 ...
##  $ WC_Stop: Factor w/ 2 levels "Never","Ever": 2 1 1 2 2 2 1 1 2 1 ...
##  $ EC_Bus : Factor w/ 2 levels "Never","Ever": 1 2 1 1 1 1 1 1 1 1 ...
##  $ WC_Bus : Factor w/ 2 levels "Never","Ever": 2 1 1 2 2 2 1 1 2 1 ...
##  $ Gender : Factor w/ 2 levels "Female","Male": 1 1 2 2 2 1 1 1 1 1 ...
##  $ BPE    : chr  "PHB1" "PHB1" "PHB1" "PHB1" ...
dim(B.Per_PHB)
## [1] 4290    9
B.Per_PEB <- rbind(dat_PEB1, dat_PEB2, dat_PEB3, dat_PEB4)
head(B.Per_PEB)
##     AGE      CITY Res EC_Stop WC_Stop EC_Bus WC_Bus Gender  BPE
## 1 16-25 HoChiMinh   4   Never    Ever  Never   Ever Female PEB1
## 2 16-25 HoChiMinh   5   Never   Never   Ever  Never Female PEB1
## 3 16-25 HoChiMinh   6   Never   Never  Never  Never   Male PEB1
## 4 16-25 HoChiMinh   5   Never    Ever  Never   Ever   Male PEB1
## 5 16-25 HoChiMinh   6   Never    Ever  Never   Ever   Male PEB1
## 6 16-25 HoChiMinh   7   Never    Ever  Never   Ever Female PEB1
str(B.Per_PEB)
## 'data.frame':    3432 obs. of  9 variables:
##  $ AGE    : Factor w/ 5 levels "16-25","26-35",..: 1 1 1 1 1 1 1 3 1 1 ...
##  $ CITY   : Factor w/ 2 levels "DaNang","HoChiMinh": 2 2 2 2 2 2 2 2 2 2 ...
##  $ Res    : int  4 5 6 5 6 7 4 6 7 7 ...
##  $ EC_Stop: Factor w/ 2 levels "Never","Ever": 1 1 1 1 1 1 1 1 1 1 ...
##  $ WC_Stop: Factor w/ 2 levels "Never","Ever": 2 1 1 2 2 2 1 1 2 1 ...
##  $ EC_Bus : Factor w/ 2 levels "Never","Ever": 1 2 1 1 1 1 1 1 1 1 ...
##  $ WC_Bus : Factor w/ 2 levels "Never","Ever": 2 1 1 2 2 2 1 1 2 1 ...
##  $ Gender : Factor w/ 2 levels "Female","Male": 1 1 2 2 2 1 1 1 1 1 ...
##  $ BPE    : chr  "PEB1" "PEB1" "PEB1" "PEB1" ...
dim(B.Per_PEB)
## [1] 3432    9
B.Per_PVA <- rbind(dat_PVA1, dat_PVA2, dat_PVA3)
head(B.Per_PVA)
##     AGE      CITY Res EC_Stop WC_Stop EC_Bus WC_Bus Gender  BPE
## 1 16-25 HoChiMinh   6   Never    Ever  Never   Ever Female PVA1
## 2 16-25 HoChiMinh   5   Never   Never   Ever  Never Female PVA1
## 3 16-25 HoChiMinh   6   Never   Never  Never  Never   Male PVA1
## 4 16-25 HoChiMinh   5   Never    Ever  Never   Ever   Male PVA1
## 5 16-25 HoChiMinh   6   Never    Ever  Never   Ever   Male PVA1
## 6 16-25 HoChiMinh   6   Never    Ever  Never   Ever Female PVA1
str(B.Per_PVA)
## 'data.frame':    2574 obs. of  9 variables:
##  $ AGE    : Factor w/ 5 levels "16-25","26-35",..: 1 1 1 1 1 1 1 3 1 1 ...
##  $ CITY   : Factor w/ 2 levels "DaNang","HoChiMinh": 2 2 2 2 2 2 2 2 2 2 ...
##  $ Res    : int  6 5 6 5 6 6 6 6 6 6 ...
##  $ EC_Stop: Factor w/ 2 levels "Never","Ever": 1 1 1 1 1 1 1 1 1 1 ...
##  $ WC_Stop: Factor w/ 2 levels "Never","Ever": 2 1 1 2 2 2 1 1 2 1 ...
##  $ EC_Bus : Factor w/ 2 levels "Never","Ever": 1 2 1 1 1 1 1 1 1 1 ...
##  $ WC_Bus : Factor w/ 2 levels "Never","Ever": 2 1 1 2 2 2 1 1 2 1 ...
##  $ Gender : Factor w/ 2 levels "Female","Male": 1 1 2 2 2 1 1 1 1 1 ...
##  $ BPE    : chr  "PVA1" "PVA1" "PVA1" "PVA1" ...
dim(B.Per_PVA)
## [1] 2574    9
# Cách 2: Tạo dữ liệu thủ công trên excel với các cột BPE, Res, BUB, MSI, SBM, SBS: t_likert = "F:\\NGHIEN CUU SINH\\NCS - PHUONG ANH\\Part 3-Mode shift\\So lieu mode choice tu phan 1\\8. MS-Bieu do Likert.csv" ; BP_likert = read.csv(t_likert, header = T, sep = ";")

# Data Bus perception of people in Da Nang
DN_SEM5 = subset(B.Per, CITY == "DaNang")
head(DN_SEM5)
##       AGE   CITY Res EC_Stop WC_Stop EC_Bus WC_Bus Gender  BPE
## 449 26-35 DaNang   6   Never   Never  Never  Never   Male PSB1
## 450 46-55 DaNang   6   Never   Never  Never  Never Female PSB1
## 451 46-55 DaNang   6   Never   Never  Never  Never Female PSB1
## 452 26-35 DaNang   5   Never   Never  Never  Never Female PSB1
## 453 46-55 DaNang   6   Never   Never  Never  Never Female PSB1
## 454 16-25 DaNang   6   Never   Never  Never  Never Female PSB1
str(DN_SEM5)
## 'data.frame':    17220 obs. of  9 variables:
##  $ AGE    : Factor w/ 5 levels "16-25","26-35",..: 2 4 4 2 4 1 1 2 1 2 ...
##  $ CITY   : Factor w/ 2 levels "DaNang","HoChiMinh": 1 1 1 1 1 1 1 1 1 1 ...
##  $ Res    : int  6 6 6 5 6 6 6 7 4 6 ...
##  $ EC_Stop: Factor w/ 2 levels "Never","Ever": 1 1 1 1 1 1 1 1 1 1 ...
##  $ WC_Stop: Factor w/ 2 levels "Never","Ever": 1 1 1 1 1 1 1 1 1 1 ...
##  $ EC_Bus : Factor w/ 2 levels "Never","Ever": 1 1 1 1 1 1 1 1 1 1 ...
##  $ WC_Bus : Factor w/ 2 levels "Never","Ever": 1 1 1 1 1 1 1 1 1 1 ...
##  $ Gender : Factor w/ 2 levels "Female","Male": 2 1 1 1 1 1 1 2 2 1 ...
##  $ BPE    : chr  "PSB1" "PSB1" "PSB1" "PSB1" ...
dim(DN_SEM5)
## [1] 17220     9
DN_SEM5 = DN_SEM5[ , c(3, 9)]
dim(DN_SEM5)
## [1] 17220     2
head(DN_SEM5)
##     Res  BPE
## 449   6 PSB1
## 450   6 PSB1
## 451   6 PSB1
## 452   5 PSB1
## 453   6 PSB1
## 454   6 PSB1
# Data Bus perception of people in Ho Chi Minh
HCM_SEM5 = subset(B.Per, CITY == "HoChiMinh")
head(HCM_SEM5)
##     AGE      CITY Res EC_Stop WC_Stop EC_Bus WC_Bus Gender  BPE
## 1 16-25 HoChiMinh   6   Never    Ever  Never   Ever Female PSB1
## 2 16-25 HoChiMinh   3   Never   Never   Ever  Never Female PSB1
## 3 16-25 HoChiMinh   2   Never   Never  Never  Never   Male PSB1
## 4 16-25 HoChiMinh   5   Never    Ever  Never   Ever   Male PSB1
## 5 16-25 HoChiMinh   2   Never    Ever  Never   Ever   Male PSB1
## 6 16-25 HoChiMinh   2   Never    Ever  Never   Ever Female PSB1
str(HCM_SEM5)
## 'data.frame':    18816 obs. of  9 variables:
##  $ AGE    : Factor w/ 5 levels "16-25","26-35",..: 1 1 1 1 1 1 1 3 1 1 ...
##  $ CITY   : Factor w/ 2 levels "DaNang","HoChiMinh": 2 2 2 2 2 2 2 2 2 2 ...
##  $ Res    : int  6 3 2 5 2 2 1 6 2 4 ...
##  $ EC_Stop: Factor w/ 2 levels "Never","Ever": 1 1 1 1 1 1 1 1 1 1 ...
##  $ WC_Stop: Factor w/ 2 levels "Never","Ever": 2 1 1 2 2 2 1 1 2 1 ...
##  $ EC_Bus : Factor w/ 2 levels "Never","Ever": 1 2 1 1 1 1 1 1 1 1 ...
##  $ WC_Bus : Factor w/ 2 levels "Never","Ever": 2 1 1 2 2 2 1 1 2 1 ...
##  $ Gender : Factor w/ 2 levels "Female","Male": 1 1 2 2 2 1 1 1 1 1 ...
##  $ BPE    : chr  "PSB1" "PSB1" "PSB1" "PSB1" ...
dim(HCM_SEM5)
## [1] 18816     9
HCM_SEM5 = HCM_SEM5[ , c(3, 9)]
dim(HCM_SEM5)
## [1] 18816     2
head(HCM_SEM5)
##   Res  BPE
## 1   6 PSB1
## 2   3 PSB1
## 3   2 PSB1
## 4   5 PSB1
## 5   2 PSB1
## 6   2 PSB1
# Data Bus perception of people in both Da Nang and Ho Chi Minh cities
DN_HCM_SEM5 = B.Per[, c(3, 9)]
str(DN_HCM_SEM5)
## 'data.frame':    36036 obs. of  2 variables:
##  $ Res: int  6 3 2 5 2 2 1 6 2 4 ...
##  $ BPE: chr  "PSB1" "PSB1" "PSB1" "PSB1" ...
dim(DN_HCM_SEM5)
## [1] 36036     2
head(DN_HCM_SEM5)
##   Res  BPE
## 1   6 PSB1
## 2   3 PSB1
## 3   2 PSB1
## 4   5 PSB1
## 5   2 PSB1
## 6   2 PSB1
# Data bus perception of people in both Da Nang and Ho Chi Minh cities - according constructs 
## Construct PSB
DN_HCM_SEM5_PSB = B.Per_PSB[ , c(3, 9)]
dim(DN_HCM_SEM5_PSB)
## [1] 3432    2
head(DN_HCM_SEM5_PSB)
##   Res  BPE
## 1   6 PSB1
## 2   3 PSB1
## 3   2 PSB1
## 4   5 PSB1
## 5   2 PSB1
## 6   2 PSB1
## Construct PSQT
DN_HCM_SEM5_PSQT = B.Per_PSQT[ , c(3, 9)]
dim(DN_HCM_SEM5_PSQT)
## [1] 3432    2
head(DN_HCM_SEM5_PSQT)
##   Res   BPE
## 1   6 PSQT1
## 2   4 PSQT1
## 3   2 PSQT1
## 4   6 PSQT1
## 5   6 PSQT1
## 6   4 PSQT1
## Construct PSQC
DN_HCM_SEM5_PSQC = B.Per_PSQC[ , c(3, 9)]
dim(DN_HCM_SEM5_PSQC)
## [1] 5148    2
head(DN_HCM_SEM5_PSQC)
##   Res   BPE
## 1   6 PSQC1
## 2   4 PSQC1
## 3   2 PSQC1
## 4   5 PSQC1
## 5   6 PSQC1
## 6   5 PSQC1
## Construct PSQP
DN_HCM_SEM5_PSQP = B.Per_PSQP[ , c(3, 9)]
dim(DN_HCM_SEM5_PSQP)
## [1] 3432    2
head(DN_HCM_SEM5_PSQP)
##   Res   BPE
## 1   6 PSQP1
## 2   6 PSQP1
## 3   1 PSQP1
## 4   5 PSQP1
## 5   4 PSQP1
## 6   4 PSQP1
## Construct PSQR
DN_HCM_SEM5_PSQR = B.Per_PSQR[ , c(3, 9)]
dim(DN_HCM_SEM5_PSQR)
## [1] 3432    2
head(DN_HCM_SEM5_PSQR)
##   Res   BPE
## 1   4 PSQR1
## 2   4 PSQR1
## 3   2 PSQR1
## 4   4 PSQR1
## 5   5 PSQR1
## 6   3 PSQR1
## Construct SAT
DN_HCM_SEM5_SAT = B.Per_SAT[ , c(3, 9)]
dim(DN_HCM_SEM5_SAT)
## [1] 2574    2
head(DN_HCM_SEM5_SAT)
##   Res  BPE
## 1   6 SAT1
## 2   5 SAT1
## 3   2 SAT1
## 4   5 SAT1
## 5   4 SAT1
## 6   4 SAT1
## Construct IMA
DN_HCM_SEM5_IMA = B.Per_IMA[ , c(3, 9)]
dim(DN_HCM_SEM5_IMA)
## [1] 4290    2
head(DN_HCM_SEM5_IMA)
##   Res  BPE
## 1   6 IMA1
## 2   4 IMA1
## 3   4 IMA1
## 4   5 IMA1
## 5   5 IMA1
## 6   4 IMA1
## Construct PHB
DN_HCM_SEM5_PHB = B.Per_PHB[ , c(3, 9)]
dim(DN_HCM_SEM5_PHB)
## [1] 4290    2
head(DN_HCM_SEM5_PHB)
##   Res  BPE
## 1   6 PHB1
## 2   3 PHB1
## 3   5 PHB1
## 4   5 PHB1
## 5   5 PHB1
## 6   4 PHB1
## Construct PEB
DN_HCM_SEM5_PEB = B.Per_PEB[ , c(3, 9)]
dim(DN_HCM_SEM5_PEB)
## [1] 3432    2
head(DN_HCM_SEM5_PEB)
##   Res  BPE
## 1   4 PEB1
## 2   5 PEB1
## 3   6 PEB1
## 4   5 PEB1
## 5   6 PEB1
## 6   7 PEB1
## Construct PVA
DN_HCM_SEM5_PVA = B.Per_PVA[ , c(3, 9)]
dim(DN_HCM_SEM5_PVA)
## [1] 2574    2
head(DN_HCM_SEM5_PVA)
##   Res  BPE
## 1   6 PVA1
## 2   5 PVA1
## 3   6 PVA1
## 4   5 PVA1
## 5   6 PVA1
## 6   6 PVA1

3.2. Vẽ biểu đồ likert với dữ liệu chung Đà Nẵng và Hồ Chí Minh - Nhãn tiếng anh

# Plot Likert graph for people in both Da Nang and Ho Chi Minh cities
library(tidyverse)
## -- Attaching packages --------------------------------------- tidyverse 1.3.0 --
## v ggplot2 3.3.2     v purrr   0.3.4
## v tibble  3.0.4     v dplyr   1.0.2
## v tidyr   1.1.2     v stringr 1.4.0
## v readr   1.4.0     v forcats 0.5.0
## -- Conflicts ------------------------------------------ tidyverse_conflicts() --
## x tidyr::extract()   masks magrittr::extract()
## x dplyr::filter()    masks stats::filter()
## x dplyr::lag()       masks stats::lag()
## x purrr::set_names() masks magrittr::set_names()
library(compareGroups)
head(DN_HCM_SEM5)
##   Res  BPE
## 1   6 PSB1
## 2   3 PSB1
## 3   2 PSB1
## 4   5 PSB1
## 5   2 PSB1
## 6   2 PSB1
dim(DN_HCM_SEM5)
## [1] 36036     2
attach(DN_HCM_SEM5)
DN_HCM_SEM5 = within(DN_HCM_SEM5, {
  Res = factor(Res, labels = c("Very Disagree", "Disagree", "Quite Disagree", "Normal", "Quite Agree", "Agree", "Very Agree"))
  BPE = factor(BPE, labels = c("PSB1", "PSB2", "PSB3", "PSB4", "PSQT1", "PSQT2", "PSQT3", "PSQT4", "PSQC1", "PSQC2", "PSQC3", "PSQC4", "PSQC5", "PSQC6", "PSQP1", "PSQP2", "PSQP3", "PSQP4", "PSQR1", "PSQR2", "PSQR3", "PSQR4", "SAT1", "SAT2", "SAT3", "IMA1", "IMA2", "IMA3", "IMA4", "IMA5", "PHB1", "PHB2", "PHB3", "PHB4", "PHB5", "PEB1", "PEB2", "PEB3", "PEB4", "PVA1", "PVA2", "PVA3"))
  })
str(DN_HCM_SEM5)
## 'data.frame':    36036 obs. of  2 variables:
##  $ Res: Factor w/ 7 levels "Very Disagree",..: 6 3 2 5 2 2 1 6 2 4 ...
##  $ BPE: Factor w/ 42 levels "PSB1","PSB2",..: 15 15 15 15 15 15 15 15 15 15 ...
summary(DN_HCM_SEM5)
##              Res             BPE       
##  Very Disagree :  697   PSB1   :  858  
##  Disagree      : 1317   PSB2   :  858  
##  Quite Disagree: 1502   PSB3   :  858  
##  Normal        : 4150   PSB4   :  858  
##  Quite Agree   : 7478   PSQT1  :  858  
##  Agree         :15674   PSQT2  :  858  
##  Very Agree    : 5218   (Other):30888
    ## t <- compareGroups(Res ~ BPE, data = DN_HCM_SEM1)
    ## createTable(t)
DN_HCM_SEM5 %>% 
  group_by(BPE, Res) %>% 
  count() %>% 
  ungroup() %>% 
  group_by(BPE) %>% 
  mutate(percent = 100*n / sum(n)) %>% 
  mutate(percent = round(percent, 2)) %>% 
  mutate(bar_text = paste0(percent, "%")) %>% 
  ungroup() -> df_for_ploting
df_for_ploting %>% 
  filter(Res == Res[7]) %>% 
  # arrange(percent) %>% # sắp xếp theo %
  pull(BPE) -> order_x
order_x
##  [1] PSB1  PSB2  PSB3  PSB4  PSQT1 PSQT2 PSQT3 PSQT4 PSQC1 PSQC2 PSQC3 PSQC4
## [13] PSQC5 PSQC6 PSQP1 PSQP2 PSQP3 PSQP4 PSQR1 PSQR2 PSQR3 PSQR4 SAT1  SAT2 
## [25] SAT3  IMA1  IMA2  IMA3  IMA4  IMA5  PHB1  PHB2  PHB3  PHB4  PHB5  PEB1 
## [37] PEB2  PEB3  PEB4  PVA1  PVA2  PVA3 
## 42 Levels: PSB1 PSB2 PSB3 PSB4 PSQT1 PSQT2 PSQT3 PSQT4 PSQC1 PSQC2 ... PVA3
# Make a draft plot: 
my_colors <- c("#3e6487", "#829cb2", "pink", "pink3", "palevioletred", "rosybrown2", "rosybrown3")
my_font <- "Roboto Condensed"

df_for_ploting %>% 
  mutate(BPE = factor(BPE, levels = order_x), Res = factor(Res, levels = Res[7:1])) -> df_odered
df_odered
## # A tibble: 294 x 5
##    BPE   Res                n percent bar_text
##    <fct> <fct>          <int>   <dbl> <chr>   
##  1 PSB1  Very Disagree      6    0.7  0.7%    
##  2 PSB1  Disagree          19    2.21 2.21%   
##  3 PSB1  Quite Disagree    33    3.85 3.85%   
##  4 PSB1  Normal           154   18.0  17.95%  
##  5 PSB1  Quite Agree      230   26.8  26.81%  
##  6 PSB1  Agree            351   40.9  40.91%  
##  7 PSB1  Very Agree        65    7.58 7.58%   
##  8 PSB2  Very Disagree     11    1.28 1.28%   
##  9 PSB2  Disagree          18    2.1  2.1%    
## 10 PSB2  Quite Disagree    26    3.03 3.03%   
## # ... with 284 more rows
library(extrafont)
## Registering fonts with R
theme_set(theme_minimal())
gg <- df_odered %>% 
  ggplot(aes(x = BPE, y = percent, fill = Res)) + 
  geom_col(width = 0.8) + 
  coord_flip() + 
  scale_fill_manual(values = my_colors[7:1], name = "") + 
  theme(legend.position = "top") + 
  theme(text = element_text(family = my_font)) + 
  guides(fill = guide_legend(reverse = TRUE)) + 
  scale_y_continuous(labels = paste0(seq(0, 100, 25), "%"), expand = c(0, 0)) + 
  theme(plot.title = element_text(size = 18), plot.subtitle = element_text(size = 11, color = "grey20")) + 
  theme(axis.text = element_text(color = "grey20", size = 10.2)) + 
  theme(plot.margin = unit(rep(0.7, 4), "cm")) + 
  theme(panel.grid.major.y = element_blank(), panel.grid.minor.x = element_blank()) + 
  theme(legend.key.height = unit(0.15, "mm")) + 
  labs(x = NULL, y = NULL, 
       title = "Perception of passengers towards bus systems in urban areas of Viet Nam", 
       subtitle = "Likert scale is a type of rating scale commonly used in surveys. When responding to a Likert type question,\nrespondents simply state their level of agreement or disagreement on a symmetric agree-disagree scale.")
gg
## Warning in grid.Call(C_stringMetric, as.graphicsAnnot(x$label)): font family not
## found in Windows font database

## Warning in grid.Call(C_stringMetric, as.graphicsAnnot(x$label)): font family not
## found in Windows font database

## Warning in grid.Call(C_stringMetric, as.graphicsAnnot(x$label)): font family not
## found in Windows font database

## Warning in grid.Call(C_stringMetric, as.graphicsAnnot(x$label)): font family not
## found in Windows font database
## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

# For displaying percent of "Very Disagree": Điều chỉnh percent để thể hiện giá trị của %
df_odered %>% 
  filter(Res == "Very Disagree") %>% 
  filter(percent >= 0) -> df_for_text1
df_for_text1
## # A tibble: 42 x 5
##    BPE   Res               n percent bar_text
##    <fct> <fct>         <int>   <dbl> <chr>   
##  1 PSB1  Very Disagree     6    0.7  0.7%    
##  2 PSB2  Very Disagree    11    1.28 1.28%   
##  3 PSB3  Very Disagree    11    1.28 1.28%   
##  4 PSB4  Very Disagree    13    1.52 1.52%   
##  5 PSQT1 Very Disagree     6    0.7  0.7%    
##  6 PSQT2 Very Disagree    24    2.8  2.8%    
##  7 PSQT3 Very Disagree    25    2.91 2.91%   
##  8 PSQT4 Very Disagree    25    2.91 2.91%   
##  9 PSQC1 Very Disagree    24    2.8  2.8%    
## 10 PSQC2 Very Disagree    25    2.91 2.91%   
## # ... with 32 more rows
# For displaying percent of "Disagree": 
df_odered %>% 
  filter(Res == "Disagree") %>% 
  filter(percent >= 0) -> df_for_text2
df_for_text2
## # A tibble: 42 x 5
##    BPE   Res          n percent bar_text
##    <fct> <fct>    <int>   <dbl> <chr>   
##  1 PSB1  Disagree    19    2.21 2.21%   
##  2 PSB2  Disagree    18    2.1  2.1%    
##  3 PSB3  Disagree    10    1.17 1.17%   
##  4 PSB4  Disagree    15    1.75 1.75%   
##  5 PSQT1 Disagree    20    2.33 2.33%   
##  6 PSQT2 Disagree     8    0.93 0.93%   
##  7 PSQT3 Disagree    17    1.98 1.98%   
##  8 PSQT4 Disagree    20    2.33 2.33%   
##  9 PSQC1 Disagree    19    2.21 2.21%   
## 10 PSQC2 Disagree    18    2.1  2.1%    
## # ... with 32 more rows
# For displaying percent of "Quite Disagree": 
df_odered %>% 
  filter(Res == "Quite Disagree") %>% 
  filter(percent >= 0) -> df_for_text3
df_for_text3
## # A tibble: 42 x 5
##    BPE   Res                n percent bar_text
##    <fct> <fct>          <int>   <dbl> <chr>   
##  1 PSB1  Quite Disagree    33    3.85 3.85%   
##  2 PSB2  Quite Disagree    26    3.03 3.03%   
##  3 PSB3  Quite Disagree    21    2.45 2.45%   
##  4 PSB4  Quite Disagree    26    3.03 3.03%   
##  5 PSQT1 Quite Disagree    20    2.33 2.33%   
##  6 PSQT2 Quite Disagree    13    1.52 1.52%   
##  7 PSQT3 Quite Disagree    21    2.45 2.45%   
##  8 PSQT4 Quite Disagree    22    2.56 2.56%   
##  9 PSQC1 Quite Disagree    22    2.56 2.56%   
## 10 PSQC2 Quite Disagree    37    4.31 4.31%   
## # ... with 32 more rows
# For displaying percent of "Normal": 
df_odered %>% 
  filter(Res == "Normal") %>% 
  filter(percent >= 0) -> df_for_text4
df_for_text4
## # A tibble: 42 x 5
##    BPE   Res        n percent bar_text
##    <fct> <fct>  <int>   <dbl> <chr>   
##  1 PSB1  Normal   154   18.0  17.95%  
##  2 PSB2  Normal   158   18.4  18.41%  
##  3 PSB3  Normal   128   14.9  14.92%  
##  4 PSB4  Normal   113   13.2  13.17%  
##  5 PSQT1 Normal   104   12.1  12.12%  
##  6 PSQT2 Normal    60    6.99 6.99%   
##  7 PSQT3 Normal    67    7.81 7.81%   
##  8 PSQT4 Normal    77    8.97 8.97%   
##  9 PSQC1 Normal    93   10.8  10.84%  
## 10 PSQC2 Normal    97   11.3  11.31%  
## # ... with 32 more rows
# For displaying percent of "Quite Agree": 
df_odered %>% 
  filter(Res == "Quite Agree") %>% 
  filter(percent >= 0) -> df_for_text5
df_for_text5
## # A tibble: 42 x 5
##    BPE   Res             n percent bar_text
##    <fct> <fct>       <int>   <dbl> <chr>   
##  1 PSB1  Quite Agree   230    26.8 26.81%  
##  2 PSB2  Quite Agree   214    24.9 24.94%  
##  3 PSB3  Quite Agree   207    24.1 24.13%  
##  4 PSB4  Quite Agree   201    23.4 23.43%  
##  5 PSQT1 Quite Agree   204    23.8 23.78%  
##  6 PSQT2 Quite Agree   127    14.8 14.8%   
##  7 PSQT3 Quite Agree   170    19.8 19.81%  
##  8 PSQT4 Quite Agree   168    19.6 19.58%  
##  9 PSQC1 Quite Agree   167    19.5 19.46%  
## 10 PSQC2 Quite Agree   215    25.1 25.06%  
## # ... with 32 more rows
# For displaying percent of "Agree": 
df_odered %>% 
  filter(Res == "Agree") %>% 
  filter(percent >= 0) -> df_for_text6
df_for_text6
## # A tibble: 42 x 5
##    BPE   Res       n percent bar_text
##    <fct> <fct> <int>   <dbl> <chr>   
##  1 PSB1  Agree   351    40.9 40.91%  
##  2 PSB2  Agree   365    42.5 42.54%  
##  3 PSB3  Agree   403    47.0 46.97%  
##  4 PSB4  Agree   406    47.3 47.32%  
##  5 PSQT1 Agree   420    49.0 48.95%  
##  6 PSQT2 Agree   391    45.6 45.57%  
##  7 PSQT3 Agree   353    41.1 41.14%  
##  8 PSQT4 Agree   354    41.3 41.26%  
##  9 PSQC1 Agree   358    41.7 41.72%  
## 10 PSQC2 Agree   352    41.0 41.03%  
## # ... with 32 more rows
# For displaying percent of "Very Agree": 
df_odered %>% 
  filter(Res == "Very Agree") %>% 
  filter(percent >= 0) -> df_for_text7
df_for_text7
## # A tibble: 42 x 5
##    BPE   Res            n percent bar_text
##    <fct> <fct>      <int>   <dbl> <chr>   
##  1 PSB1  Very Agree    65    7.58 7.58%   
##  2 PSB2  Very Agree    66    7.69 7.69%   
##  3 PSB3  Very Agree    78    9.09 9.09%   
##  4 PSB4  Very Agree    84    9.79 9.79%   
##  5 PSQT1 Very Agree    84    9.79 9.79%   
##  6 PSQT2 Very Agree   235   27.4  27.39%  
##  7 PSQT3 Very Agree   205   23.9  23.89%  
##  8 PSQT4 Very Agree   192   22.4  22.38%  
##  9 PSQC1 Very Agree   175   20.4  20.4%   
## 10 PSQC2 Very Agree   114   13.3  13.29%  
## # ... with 32 more rows
# For displaying percent of "Very Agree": 
df_odered %>% 
  filter(Res == "Very Agree") -> df_for_text
df_for_text
## # A tibble: 42 x 5
##    BPE   Res            n percent bar_text
##    <fct> <fct>      <int>   <dbl> <chr>   
##  1 PSB1  Very Agree    65    7.58 7.58%   
##  2 PSB2  Very Agree    66    7.69 7.69%   
##  3 PSB3  Very Agree    78    9.09 9.09%   
##  4 PSB4  Very Agree    84    9.79 9.79%   
##  5 PSQT1 Very Agree    84    9.79 9.79%   
##  6 PSQT2 Very Agree   235   27.4  27.39%  
##  7 PSQT3 Very Agree   205   23.9  23.89%  
##  8 PSQT4 Very Agree   192   22.4  22.38%  
##  9 PSQC1 Very Agree   175   20.4  20.4%   
## 10 PSQC2 Very Agree   114   13.3  13.29%  
## # ... with 32 more rows
# Ad text layers-thay đổi giá trị y để thể hiện vị trí ghi text phù hợp
gg + 
  geom_text(data = df_for_text1, aes(x = BPE, y = 2, label = bar_text), size = 4, color = "white", family = my_font) + 
  geom_text(data = df_for_text6, aes(x = BPE, y = 100-35, label = bar_text), size = 4, color = "white", family = my_font) +
  geom_text(data = df_for_text7, aes(x = BPE, y = 100-4, label = bar_text), size = 4, color = "white", family = my_font)
## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database
## Warning in grid.Call.graphics(C_text, as.graphicsAnnot(x$label), x$x, x$y, :
## font family not found in Windows font database
## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

3.3. Vẽ biểu đồ likert với dữ liệu chung Đà Nẵng và Hồ Chí Minh - Nhãn tiếng việt

# Nhan tieng viet
DN_HCM_SEM5_v = within(DN_HCM_SEM5, {
  Res = factor(Res, labels = c("R\u1EA5t kh\u00F4ng \u0111\u1ED3ng \u00FD", "Kh\u00F4ng \u0111\u1ED3ng \u00FD", "Kh\u00E1 kh\u00F4ng \u0111\u1ED3ng \u00FD", "B\u00ECnh th\u01B0\u1EDDng", "Kh\u00E1 \u0111\u1ED3ng \u00FD", "\u0110\u1ED3ng \u00FD", "R\u1EA5t \u0111\u1ED3ng \u00FD"))
  BPE = factor(BPE, labels = c("PSB1", "PSB2", "PSB3", "PSB4", "PSQT1", "PSQT2", "PSQT3", "PSQT4", "PSQC1", "PSQC2", "PSQC3", "PSQC4", "PSQC5", "PSQC6", "PSQP1", "PSQP2", "PSQP3", "PSQP4", "PSQR1", "PSQR2", "PSQR3", "PSQR4", "SAT1", "SAT2", "SAT3", "IMA1", "IMA2", "IMA3", "IMA4", "IMA5", "PHB1", "PHB2", "PHB3", "PHB4", "PHB5", "PEB1", "PEB2", "PEB3", "PEB4", "PVA1", "PVA2", "PVA3"))
  })
str(DN_HCM_SEM5_v)
## 'data.frame':    36036 obs. of  2 variables:
##  $ Res: Factor w/ 7 levels "R<U+1EA5>t không d<U+1ED3>ng ý",..: 6 3 2 5 2 2 1 6 2 4 ...
##  $ BPE: Factor w/ 42 levels "PSB1","PSB2",..: 15 15 15 15 15 15 15 15 15 15 ...
summary(DN_HCM_SEM5_v)
##                              Res             BPE       
##  R<U+1EA5>t không d<U+1ED3>ng ý:  697   PSB1   :  858  
##  Không d<U+1ED3>ng ý           : 1317   PSB2   :  858  
##  Khá không d<U+1ED3>ng ý       : 1502   PSB3   :  858  
##  Bình thu<U+1EDD>ng            : 4150   PSB4   :  858  
##  Khá d<U+1ED3>ng ý             : 7478   PSQT1  :  858  
##  Ð<U+1ED3>ng ý                 :15674   PSQT2  :  858  
##  R<U+1EA5>t d<U+1ED3>ng ý      : 5218   (Other):30888
    ## t <- compareGroups(Res ~ BPE, data = DN_HCM_SEM1)
    ## createTable(t)
DN_HCM_SEM5_v %>% 
  group_by(BPE, Res) %>% 
  count() %>% 
  ungroup() %>% 
  group_by(BPE) %>% 
  mutate(percent = 100*n / sum(n)) %>% 
  mutate(percent = round(percent, 2)) %>% 
  mutate(bar_text = paste0(percent, "%")) %>% 
  ungroup() -> df_for_ploting
df_for_ploting %>% 
  filter(Res == Res[7]) %>% 
  # arrange(percent) %>% # sắp xếp theo %
  pull(BPE) -> order_x
order_x
##  [1] PSB1  PSB2  PSB3  PSB4  PSQT1 PSQT2 PSQT3 PSQT4 PSQC1 PSQC2 PSQC3 PSQC4
## [13] PSQC5 PSQC6 PSQP1 PSQP2 PSQP3 PSQP4 PSQR1 PSQR2 PSQR3 PSQR4 SAT1  SAT2 
## [25] SAT3  IMA1  IMA2  IMA3  IMA4  IMA5  PHB1  PHB2  PHB3  PHB4  PHB5  PEB1 
## [37] PEB2  PEB3  PEB4  PVA1  PVA2  PVA3 
## 42 Levels: PSB1 PSB2 PSB3 PSB4 PSQT1 PSQT2 PSQT3 PSQT4 PSQC1 PSQC2 ... PVA3
# Make a draft plot: 
my_colors <- c("#3e6487", "#829cb2", "pink", "pink3", "palevioletred", "rosybrown2", "rosybrown3")
my_font <- "Roboto Condensed"

df_for_ploting %>% 
  mutate(BPE = factor(BPE, levels = order_x), Res = factor(Res, levels = Res[7:1])) -> df_odered
df_odered
## # A tibble: 294 x 5
##    BPE   Res                  n percent bar_text
##    <fct> <fct>            <int>   <dbl> <chr>   
##  1 PSB1  R<U+1EA5>t không d<U+1ED3>ng ý     6    0.7  0.7%    
##  2 PSB1  Không d<U+1ED3>ng ý        19    2.21 2.21%   
##  3 PSB1  Khá không d<U+1ED3>ng ý    33    3.85 3.85%   
##  4 PSB1  Bình thu<U+1EDD>ng        154   18.0  17.95%  
##  5 PSB1  Khá d<U+1ED3>ng ý         230   26.8  26.81%  
##  6 PSB1  Ð<U+1ED3>ng ý             351   40.9  40.91%  
##  7 PSB1  R<U+1EA5>t d<U+1ED3>ng ý          65    7.58 7.58%   
##  8 PSB2  R<U+1EA5>t không d<U+1ED3>ng ý    11    1.28 1.28%   
##  9 PSB2  Không d<U+1ED3>ng ý        18    2.1  2.1%    
## 10 PSB2  Khá không d<U+1ED3>ng ý    26    3.03 3.03%   
## # ... with 284 more rows
library(extrafont)
theme_set(theme_minimal())
gg_viet <- df_odered %>% 
  ggplot(aes(x = BPE, y = percent, fill = Res)) + 
  geom_col(width = 0.8) + 
  coord_flip() + 
  scale_fill_manual(values = my_colors[7:1], name = "") + 
  theme(legend.position = "top") + 
  theme(text = element_text(family = my_font)) + 
  guides(fill = guide_legend(reverse = TRUE)) + 
  scale_y_continuous(labels = paste0(seq(0, 100, 25), "%"), expand = c(0, 0)) + 
  theme(plot.title = element_text(size = 18), plot.subtitle = element_text(size = 11, color = "grey20")) + 
  theme(axis.text = element_text(color = "grey20", size = 10.2)) + 
  theme(plot.margin = unit(rep(0.7, 4), "cm")) + 
  theme(panel.grid.major.y = element_blank(), panel.grid.minor.x = element_blank()) + 
  theme(legend.key.height = unit(0.15, "mm")) + 
  labs(x = NULL, y = NULL, 
       title = "C\u1EA3m nh\u1EADn c\u1EE7a h\u00E0nh kh\u00E1ch v\u1EC1 h\u1EC7 th\u1ED1ng xe bu\u00FDt \u0111\u00F4 th\u1ECB Vi\u1EC7t Nam", 
       subtitle = "Thang \u0111o Likert l\u00E0 lo\u1EA1i thang \u0111o \u0111i\u1EC3m \u0111\u00E1nh gi\u00E1 \u0111\u01B0\u1EE3c s\u1EED d\u1EE5ng ph\u1ED5 bi\u1EBFn trong kh\u1EA3o s\u00E1t. Nghi\u00EAn c\u1EE9u s\u1EED d\u1EE5ng thang \u0111o 7 m\u1EE9c \u0111\u1ED9 t\u01B0\u01A1ng \u1EE9ng v\u1EDBi 1 - R\u1EA5t kh\u00F4ng \u0111\u1ED3ng \u00FD \u0111\u1EBFn 7 - R\u1EA5t \u0111\u1ED3ng \u00FD.")
gg_viet
## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

# For displaying percent of "Very Disagree": Điều chỉnh percent để thể hiện giá trị của %
df_odered %>% 
  filter(Res == "R\u1EA5t kh\u00F4ng \u0111\u1ED3ng \u00FD") %>% 
  filter(percent >= 0) -> df_for_text1
df_for_text1
## # A tibble: 42 x 5
##    BPE   Res                  n percent bar_text
##    <fct> <fct>            <int>   <dbl> <chr>   
##  1 PSB1  R<U+1EA5>t không d<U+1ED3>ng ý     6    0.7  0.7%    
##  2 PSB2  R<U+1EA5>t không d<U+1ED3>ng ý    11    1.28 1.28%   
##  3 PSB3  R<U+1EA5>t không d<U+1ED3>ng ý    11    1.28 1.28%   
##  4 PSB4  R<U+1EA5>t không d<U+1ED3>ng ý    13    1.52 1.52%   
##  5 PSQT1 R<U+1EA5>t không d<U+1ED3>ng ý     6    0.7  0.7%    
##  6 PSQT2 R<U+1EA5>t không d<U+1ED3>ng ý    24    2.8  2.8%    
##  7 PSQT3 R<U+1EA5>t không d<U+1ED3>ng ý    25    2.91 2.91%   
##  8 PSQT4 R<U+1EA5>t không d<U+1ED3>ng ý    25    2.91 2.91%   
##  9 PSQC1 R<U+1EA5>t không d<U+1ED3>ng ý    24    2.8  2.8%    
## 10 PSQC2 R<U+1EA5>t không d<U+1ED3>ng ý    25    2.91 2.91%   
## # ... with 32 more rows
# For displaying percent of "Disagree": 
df_odered %>% 
  filter(Res == "Kh\u00F4ng \u0111\u1ED3ng \u00FD") %>% 
  filter(percent >= 0) -> df_for_text2
df_for_text2
## # A tibble: 42 x 5
##    BPE   Res              n percent bar_text
##    <fct> <fct>        <int>   <dbl> <chr>   
##  1 PSB1  Không d<U+1ED3>ng ý    19    2.21 2.21%   
##  2 PSB2  Không d<U+1ED3>ng ý    18    2.1  2.1%    
##  3 PSB3  Không d<U+1ED3>ng ý    10    1.17 1.17%   
##  4 PSB4  Không d<U+1ED3>ng ý    15    1.75 1.75%   
##  5 PSQT1 Không d<U+1ED3>ng ý    20    2.33 2.33%   
##  6 PSQT2 Không d<U+1ED3>ng ý     8    0.93 0.93%   
##  7 PSQT3 Không d<U+1ED3>ng ý    17    1.98 1.98%   
##  8 PSQT4 Không d<U+1ED3>ng ý    20    2.33 2.33%   
##  9 PSQC1 Không d<U+1ED3>ng ý    19    2.21 2.21%   
## 10 PSQC2 Không d<U+1ED3>ng ý    18    2.1  2.1%    
## # ... with 32 more rows
# For displaying percent of "Quite Disagree": 
df_odered %>% 
  filter(Res == "Kh\u00E1 kh\u00F4ng \u0111\u1ED3ng \u00FD") %>% 
  filter(percent >= 0) -> df_for_text3
df_for_text3
## # A tibble: 42 x 5
##    BPE   Res                  n percent bar_text
##    <fct> <fct>            <int>   <dbl> <chr>   
##  1 PSB1  Khá không d<U+1ED3>ng ý    33    3.85 3.85%   
##  2 PSB2  Khá không d<U+1ED3>ng ý    26    3.03 3.03%   
##  3 PSB3  Khá không d<U+1ED3>ng ý    21    2.45 2.45%   
##  4 PSB4  Khá không d<U+1ED3>ng ý    26    3.03 3.03%   
##  5 PSQT1 Khá không d<U+1ED3>ng ý    20    2.33 2.33%   
##  6 PSQT2 Khá không d<U+1ED3>ng ý    13    1.52 1.52%   
##  7 PSQT3 Khá không d<U+1ED3>ng ý    21    2.45 2.45%   
##  8 PSQT4 Khá không d<U+1ED3>ng ý    22    2.56 2.56%   
##  9 PSQC1 Khá không d<U+1ED3>ng ý    22    2.56 2.56%   
## 10 PSQC2 Khá không d<U+1ED3>ng ý    37    4.31 4.31%   
## # ... with 32 more rows
# For displaying percent of "Normal": 
df_odered %>% 
  filter(Res == "B\u00ECnh th\u01B0\u1EDDng") %>% 
  filter(percent >= 0) -> df_for_text4
df_for_text4
## # A tibble: 42 x 5
##    BPE   Res             n percent bar_text
##    <fct> <fct>       <int>   <dbl> <chr>   
##  1 PSB1  Bình thu<U+1EDD>ng   154   18.0  17.95%  
##  2 PSB2  Bình thu<U+1EDD>ng   158   18.4  18.41%  
##  3 PSB3  Bình thu<U+1EDD>ng   128   14.9  14.92%  
##  4 PSB4  Bình thu<U+1EDD>ng   113   13.2  13.17%  
##  5 PSQT1 Bình thu<U+1EDD>ng   104   12.1  12.12%  
##  6 PSQT2 Bình thu<U+1EDD>ng    60    6.99 6.99%   
##  7 PSQT3 Bình thu<U+1EDD>ng    67    7.81 7.81%   
##  8 PSQT4 Bình thu<U+1EDD>ng    77    8.97 8.97%   
##  9 PSQC1 Bình thu<U+1EDD>ng    93   10.8  10.84%  
## 10 PSQC2 Bình thu<U+1EDD>ng    97   11.3  11.31%  
## # ... with 32 more rows
# For displaying percent of "Quite Agree": 
df_odered %>% 
  filter(Res == "Kh\u00E1 \u0111\u1ED3ng \u00FD") %>% 
  filter(percent >= 0) -> df_for_text5
df_for_text5
## # A tibble: 42 x 5
##    BPE   Res            n percent bar_text
##    <fct> <fct>      <int>   <dbl> <chr>   
##  1 PSB1  Khá d<U+1ED3>ng ý   230    26.8 26.81%  
##  2 PSB2  Khá d<U+1ED3>ng ý   214    24.9 24.94%  
##  3 PSB3  Khá d<U+1ED3>ng ý   207    24.1 24.13%  
##  4 PSB4  Khá d<U+1ED3>ng ý   201    23.4 23.43%  
##  5 PSQT1 Khá d<U+1ED3>ng ý   204    23.8 23.78%  
##  6 PSQT2 Khá d<U+1ED3>ng ý   127    14.8 14.8%   
##  7 PSQT3 Khá d<U+1ED3>ng ý   170    19.8 19.81%  
##  8 PSQT4 Khá d<U+1ED3>ng ý   168    19.6 19.58%  
##  9 PSQC1 Khá d<U+1ED3>ng ý   167    19.5 19.46%  
## 10 PSQC2 Khá d<U+1ED3>ng ý   215    25.1 25.06%  
## # ... with 32 more rows
# For displaying percent of "Agree": 
df_odered %>% 
  filter(Res == "\u0110\u1ED3ng \u00FD") %>% 
  filter(percent >= 0) -> df_for_text6
df_for_text6
## # A tibble: 42 x 5
##    BPE   Res        n percent bar_text
##    <fct> <fct>  <int>   <dbl> <chr>   
##  1 PSB1  Ð<U+1ED3>ng ý   351    40.9 40.91%  
##  2 PSB2  Ð<U+1ED3>ng ý   365    42.5 42.54%  
##  3 PSB3  Ð<U+1ED3>ng ý   403    47.0 46.97%  
##  4 PSB4  Ð<U+1ED3>ng ý   406    47.3 47.32%  
##  5 PSQT1 Ð<U+1ED3>ng ý   420    49.0 48.95%  
##  6 PSQT2 Ð<U+1ED3>ng ý   391    45.6 45.57%  
##  7 PSQT3 Ð<U+1ED3>ng ý   353    41.1 41.14%  
##  8 PSQT4 Ð<U+1ED3>ng ý   354    41.3 41.26%  
##  9 PSQC1 Ð<U+1ED3>ng ý   358    41.7 41.72%  
## 10 PSQC2 Ð<U+1ED3>ng ý   352    41.0 41.03%  
## # ... with 32 more rows
# For displaying percent of "Very Agree": 
df_odered %>% 
  filter(Res == "R\u1EA5t \u0111\u1ED3ng \u00FD") %>% 
  filter(percent >= 0) -> df_for_text7
df_for_text7
## # A tibble: 42 x 5
##    BPE   Res            n percent bar_text
##    <fct> <fct>      <int>   <dbl> <chr>   
##  1 PSB1  R<U+1EA5>t d<U+1ED3>ng ý    65    7.58 7.58%   
##  2 PSB2  R<U+1EA5>t d<U+1ED3>ng ý    66    7.69 7.69%   
##  3 PSB3  R<U+1EA5>t d<U+1ED3>ng ý    78    9.09 9.09%   
##  4 PSB4  R<U+1EA5>t d<U+1ED3>ng ý    84    9.79 9.79%   
##  5 PSQT1 R<U+1EA5>t d<U+1ED3>ng ý    84    9.79 9.79%   
##  6 PSQT2 R<U+1EA5>t d<U+1ED3>ng ý   235   27.4  27.39%  
##  7 PSQT3 R<U+1EA5>t d<U+1ED3>ng ý   205   23.9  23.89%  
##  8 PSQT4 R<U+1EA5>t d<U+1ED3>ng ý   192   22.4  22.38%  
##  9 PSQC1 R<U+1EA5>t d<U+1ED3>ng ý   175   20.4  20.4%   
## 10 PSQC2 R<U+1EA5>t d<U+1ED3>ng ý   114   13.3  13.29%  
## # ... with 32 more rows
# For displaying percent of "Very Agree": 
df_odered %>% 
  filter(Res == "R\u1EA5t \u0111\u1ED3ng \u00FD") -> df_for_text
df_for_text
## # A tibble: 42 x 5
##    BPE   Res            n percent bar_text
##    <fct> <fct>      <int>   <dbl> <chr>   
##  1 PSB1  R<U+1EA5>t d<U+1ED3>ng ý    65    7.58 7.58%   
##  2 PSB2  R<U+1EA5>t d<U+1ED3>ng ý    66    7.69 7.69%   
##  3 PSB3  R<U+1EA5>t d<U+1ED3>ng ý    78    9.09 9.09%   
##  4 PSB4  R<U+1EA5>t d<U+1ED3>ng ý    84    9.79 9.79%   
##  5 PSQT1 R<U+1EA5>t d<U+1ED3>ng ý    84    9.79 9.79%   
##  6 PSQT2 R<U+1EA5>t d<U+1ED3>ng ý   235   27.4  27.39%  
##  7 PSQT3 R<U+1EA5>t d<U+1ED3>ng ý   205   23.9  23.89%  
##  8 PSQT4 R<U+1EA5>t d<U+1ED3>ng ý   192   22.4  22.38%  
##  9 PSQC1 R<U+1EA5>t d<U+1ED3>ng ý   175   20.4  20.4%   
## 10 PSQC2 R<U+1EA5>t d<U+1ED3>ng ý   114   13.3  13.29%  
## # ... with 32 more rows
# Ad text layers-thay đổi giá trị y để thể hiện vị trí ghi text phù hợp
gg_viet + 
  geom_text(data = df_for_text1, aes(x = BPE, y = 2, label = bar_text), size = 4, color = "white", family = my_font) + 
  geom_text(data = df_for_text6, aes(x = BPE, y = 100-35, label = bar_text), size = 4, color = "white", family = my_font) +
  geom_text(data = df_for_text7, aes(x = BPE, y = 100-4, label = bar_text), size = 4, color = "white", family = my_font)
## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database
## Warning in grid.Call.graphics(C_text, as.graphicsAnnot(x$label), x$x, x$y, :
## font family not found in Windows font database
## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

3.4. Vẽ biểu đồ likert cho dữ liệu Đà Nẵng - Nhãn tiếng anh

# Plot Likert graph for people in Da Nang 
library(tidyverse)
library(compareGroups)
head(DN_SEM5)
##     Res  BPE
## 449   6 PSB1
## 450   6 PSB1
## 451   6 PSB1
## 452   5 PSB1
## 453   6 PSB1
## 454   6 PSB1
dim(DN_SEM5)
## [1] 17220     2
attach(DN_SEM5)
## The following objects are masked from DN_HCM_SEM5:
## 
##     BPE, Res
DN_SEM5 = within(DN_SEM5, {
  Res = factor(Res, labels = c("Very Disagree", "Disagree", "Quite Disagree", "Normal", "Quite Agree", "Agree", "Very Agree"))
  BPE = factor(BPE, labels = c("PSB1", "PSB2", "PSB3", "PSB4", "PSQT1", "PSQT2", "PSQT3", "PSQT4", "PSQC1", "PSQC2", "PSQC3", "PSQC4", "PSQC5", "PSQC6", "PSQP1", "PSQP2", "PSQP3", "PSQP4", "PSQR1", "PSQR2", "PSQR3", "PSQR4", "SAT1", "SAT2", "SAT3", "IMA1", "IMA2", "IMA3", "IMA4", "IMA5", "PHB1", "PHB2", "PHB3", "PHB4", "PHB5", "PEB1", "PEB2", "PEB3", "PEB4", "PVA1", "PVA2", "PVA3"))
  })
str(DN_SEM5)
## 'data.frame':    17220 obs. of  2 variables:
##  $ Res: Factor w/ 7 levels "Very Disagree",..: 6 6 6 5 6 6 6 7 4 6 ...
##  $ BPE: Factor w/ 42 levels "PSB1","PSB2",..: 15 15 15 15 15 15 15 15 15 15 ...
summary(DN_SEM5)
##              Res            BPE       
##  Very Disagree :  93   PSB1   :  410  
##  Disagree      : 237   PSB2   :  410  
##  Quite Disagree: 617   PSB3   :  410  
##  Normal        :1286   PSB4   :  410  
##  Quite Agree   :4005   PSQT1  :  410  
##  Agree         :7994   PSQT2  :  410  
##  Very Agree    :2988   (Other):14760
    ## t <- compareGroups(Res ~ BPE, data = DN_SEM1)
    ## createTable(t)
DN_SEM5 %>% 
  group_by(BPE, Res) %>% 
  count() %>% 
  ungroup() %>% 
  group_by(BPE) %>% 
  mutate(percent = 100*n / sum(n)) %>% 
  mutate(percent = round(percent, 2)) %>% 
  mutate(bar_text = paste0(percent, "%")) %>% 
  ungroup() -> df_for_ploting
df_for_ploting %>% 
  filter(Res == Res[7]) %>% 
  # arrange(percent) %>% # sắp xếp theo %
  pull(BPE) -> order_x
order_x
##  [1] PSB1  PSB2  PSB3  PSB4  PSQT1 PSQT2 PSQT3 PSQT4 PSQC1 PSQC2 PSQC3 PSQC4
## [13] PSQC5 PSQC6 PSQP1 PSQP2 PSQP3 PSQP4 PSQR1 PSQR2 PSQR3 PSQR4 SAT1  SAT2 
## [25] SAT3  IMA1  IMA2  IMA3  IMA4  IMA5  PHB1  PHB2  PHB3  PHB4  PHB5  PEB1 
## [37] PEB2  PEB3  PEB4  PVA1  PVA2  PVA3 
## 42 Levels: PSB1 PSB2 PSB3 PSB4 PSQT1 PSQT2 PSQT3 PSQT4 PSQC1 PSQC2 ... PVA3
# Make a draft plot: 
my_colors <- c("#3e6487", "#829cb2", "pink", "pink3", "palevioletred", "rosybrown2", "rosybrown3")
my_font <- "Roboto Condensed"

df_for_ploting %>% 
  mutate(BPE = factor(BPE, levels = order_x), Res = factor(Res, levels = Res[7:1])) -> df_odered
df_odered
## # A tibble: 272 x 5
##    BPE   Res                n percent bar_text
##    <fct> <fct>          <int>   <dbl> <chr>   
##  1 PSB1  Very Disagree      1    0.24 0.24%   
##  2 PSB1  Disagree           2    0.49 0.49%   
##  3 PSB1  Quite Disagree    12    2.93 2.93%   
##  4 PSB1  Normal            54   13.2  13.17%  
##  5 PSB1  Quite Agree      137   33.4  33.41%  
##  6 PSB1  Agree            171   41.7  41.71%  
##  7 PSB1  Very Agree        33    8.05 8.05%   
##  8 PSB2  Quite Disagree     8    1.95 1.95%   
##  9 PSB2  Normal            47   11.5  11.46%  
## 10 PSB2  Quite Agree      114   27.8  27.8%   
## # ... with 262 more rows
library(extrafont)
theme_set(theme_minimal())
gg <- df_odered %>% 
  ggplot(aes(x = BPE, y = percent, fill = Res)) + 
  geom_col(width = 0.8) + 
  coord_flip() + 
  scale_fill_manual(values = my_colors[7:1], name = "") + 
  theme(legend.position = "top") + 
  theme(text = element_text(family = my_font)) + 
  guides(fill = guide_legend(reverse = TRUE)) + 
  scale_y_continuous(labels = paste0(seq(0, 100, 25), "%"), expand = c(0, 0)) + 
  theme(plot.title = element_text(size = 18), plot.subtitle = element_text(size = 11, color = "grey20")) + 
  theme(axis.text = element_text(color = "grey20", size = 10.2)) + 
  theme(plot.margin = unit(rep(0.7, 4), "cm")) + 
  theme(panel.grid.major.y = element_blank(), panel.grid.minor.x = element_blank()) + 
  theme(legend.key.height = unit(0.15, "mm")) + 
  labs(x = NULL, y = NULL, 
       title = "Perception of passengers towards bus systems in Da Nang", 
       subtitle = "Likert scale is a type of rating scale commonly used in surveys. When responding to a Likert type question,\nrespondents simply state their level of agreement or disagreement on a symmetric agree-disagree scale.")
gg
## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

# For displaying percent of "Very Disagree": Điều chỉnh percent để thể hiện giá trị của %
df_odered %>% 
  filter(Res == "Very Disagree") %>% 
  filter(percent >= 0) -> df_for_text1
df_for_text1
## # A tibble: 27 x 5
##    BPE   Res               n percent bar_text
##    <fct> <fct>         <int>   <dbl> <chr>   
##  1 PSB1  Very Disagree     1    0.24 0.24%   
##  2 PSQT2 Very Disagree     1    0.24 0.24%   
##  3 PSQT3 Very Disagree     1    0.24 0.24%   
##  4 PSQC2 Very Disagree     2    0.49 0.49%   
##  5 PSQP1 Very Disagree     7    1.71 1.71%   
##  6 PSQP2 Very Disagree     4    0.98 0.98%   
##  7 PSQP3 Very Disagree     1    0.24 0.24%   
##  8 PSQP4 Very Disagree     4    0.98 0.98%   
##  9 PSQR1 Very Disagree     4    0.98 0.98%   
## 10 PSQR2 Very Disagree     3    0.73 0.73%   
## # ... with 17 more rows
# For displaying percent of "Disagree": 
df_odered %>% 
  filter(Res == "Disagree") %>% 
  filter(percent >= 0) -> df_for_text2
df_for_text2
## # A tibble: 35 x 5
##    BPE   Res          n percent bar_text
##    <fct> <fct>    <int>   <dbl> <chr>   
##  1 PSB1  Disagree     2    0.49 0.49%   
##  2 PSB4  Disagree     1    0.24 0.24%   
##  3 PSQT3 Disagree     4    0.98 0.98%   
##  4 PSQT4 Disagree     6    1.46 1.46%   
##  5 PSQC1 Disagree     5    1.22 1.22%   
##  6 PSQC2 Disagree     6    1.46 1.46%   
##  7 PSQC3 Disagree     5    1.22 1.22%   
##  8 PSQC4 Disagree    11    2.68 2.68%   
##  9 PSQC6 Disagree     1    0.24 0.24%   
## 10 PSQP1 Disagree     9    2.2  2.2%    
## # ... with 25 more rows
# For displaying percent of "Quite Disagree": 
df_odered %>% 
  filter(Res == "Quite Disagree") %>% 
  filter(percent >= 0) -> df_for_text3
df_for_text3
## # A tibble: 42 x 5
##    BPE   Res                n percent bar_text
##    <fct> <fct>          <int>   <dbl> <chr>   
##  1 PSB1  Quite Disagree    12    2.93 2.93%   
##  2 PSB2  Quite Disagree     8    1.95 1.95%   
##  3 PSB3  Quite Disagree     5    1.22 1.22%   
##  4 PSB4  Quite Disagree     8    1.95 1.95%   
##  5 PSQT1 Quite Disagree     5    1.22 1.22%   
##  6 PSQT2 Quite Disagree     3    0.73 0.73%   
##  7 PSQT3 Quite Disagree     9    2.2  2.2%    
##  8 PSQT4 Quite Disagree    14    3.41 3.41%   
##  9 PSQC1 Quite Disagree    15    3.66 3.66%   
## 10 PSQC2 Quite Disagree    17    4.15 4.15%   
## # ... with 32 more rows
# For displaying percent of "Normal": 
df_odered %>% 
  filter(Res == "Normal") %>% 
  filter(percent >= 0) -> df_for_text4
df_for_text4
## # A tibble: 42 x 5
##    BPE   Res        n percent bar_text
##    <fct> <fct>  <int>   <dbl> <chr>   
##  1 PSB1  Normal    54   13.2  13.17%  
##  2 PSB2  Normal    47   11.5  11.46%  
##  3 PSB3  Normal    39    9.51 9.51%   
##  4 PSB4  Normal    25    6.1  6.1%    
##  5 PSQT1 Normal    23    5.61 5.61%   
##  6 PSQT2 Normal    14    3.41 3.41%   
##  7 PSQT3 Normal    17    4.15 4.15%   
##  8 PSQT4 Normal    25    6.1  6.1%    
##  9 PSQC1 Normal    26    6.34 6.34%   
## 10 PSQC2 Normal    34    8.29 8.29%   
## # ... with 32 more rows
# For displaying percent of "Quite Agree": 
df_odered %>% 
  filter(Res == "Quite Agree") %>% 
  filter(percent >= 0) -> df_for_text5
df_for_text5
## # A tibble: 42 x 5
##    BPE   Res             n percent bar_text
##    <fct> <fct>       <int>   <dbl> <chr>   
##  1 PSB1  Quite Agree   137    33.4 33.41%  
##  2 PSB2  Quite Agree   114    27.8 27.8%   
##  3 PSB3  Quite Agree   107    26.1 26.1%   
##  4 PSB4  Quite Agree   104    25.4 25.37%  
##  5 PSQT1 Quite Agree    97    23.7 23.66%  
##  6 PSQT2 Quite Agree    77    18.8 18.78%  
##  7 PSQT3 Quite Agree    98    23.9 23.9%   
##  8 PSQT4 Quite Agree    86    21.0 20.98%  
##  9 PSQC1 Quite Agree    89    21.7 21.71%  
## 10 PSQC2 Quite Agree   139    33.9 33.9%   
## # ... with 32 more rows
# For displaying percent of "Agree": 
df_odered %>% 
  filter(Res == "Agree") %>% 
  filter(percent >= 0) -> df_for_text6
df_for_text6
## # A tibble: 42 x 5
##    BPE   Res       n percent bar_text
##    <fct> <fct> <int>   <dbl> <chr>   
##  1 PSB1  Agree   171    41.7 41.71%  
##  2 PSB2  Agree   207    50.5 50.49%  
##  3 PSB3  Agree   216    52.7 52.68%  
##  4 PSB4  Agree   221    53.9 53.9%   
##  5 PSQT1 Agree   233    56.8 56.83%  
##  6 PSQT2 Agree   210    51.2 51.22%  
##  7 PSQT3 Agree   187    45.6 45.61%  
##  8 PSQT4 Agree   193    47.1 47.07%  
##  9 PSQC1 Agree   193    47.1 47.07%  
## 10 PSQC2 Agree   159    38.8 38.78%  
## # ... with 32 more rows
# For displaying percent of "Very Agree": 
df_odered %>% 
  filter(Res == "Very Agree") %>% 
  filter(percent >= 0) -> df_for_text7
df_for_text7
## # A tibble: 42 x 5
##    BPE   Res            n percent bar_text
##    <fct> <fct>      <int>   <dbl> <chr>   
##  1 PSB1  Very Agree    33    8.05 8.05%   
##  2 PSB2  Very Agree    34    8.29 8.29%   
##  3 PSB3  Very Agree    43   10.5  10.49%  
##  4 PSB4  Very Agree    51   12.4  12.44%  
##  5 PSQT1 Very Agree    52   12.7  12.68%  
##  6 PSQT2 Very Agree   105   25.6  25.61%  
##  7 PSQT3 Very Agree    94   22.9  22.93%  
##  8 PSQT4 Very Agree    86   21.0  20.98%  
##  9 PSQC1 Very Agree    82   20    20%     
## 10 PSQC2 Very Agree    53   12.9  12.93%  
## # ... with 32 more rows
# For displaying percent of "Very Agree": 
df_odered %>% 
  filter(Res == "Very Agree") -> df_for_text
df_for_text
## # A tibble: 42 x 5
##    BPE   Res            n percent bar_text
##    <fct> <fct>      <int>   <dbl> <chr>   
##  1 PSB1  Very Agree    33    8.05 8.05%   
##  2 PSB2  Very Agree    34    8.29 8.29%   
##  3 PSB3  Very Agree    43   10.5  10.49%  
##  4 PSB4  Very Agree    51   12.4  12.44%  
##  5 PSQT1 Very Agree    52   12.7  12.68%  
##  6 PSQT2 Very Agree   105   25.6  25.61%  
##  7 PSQT3 Very Agree    94   22.9  22.93%  
##  8 PSQT4 Very Agree    86   21.0  20.98%  
##  9 PSQC1 Very Agree    82   20    20%     
## 10 PSQC2 Very Agree    53   12.9  12.93%  
## # ... with 32 more rows
# Ad text layers-thay đổi giá trị y để thể hiện vị trí ghi text phù hợp
gg + 
  geom_text(data = df_for_text1, aes(x = BPE, y = 2, label = bar_text), size = 4, color = "white", family = my_font) + 
  geom_text(data = df_for_text6, aes(x = BPE, y = 100-40, label = bar_text), size = 4, color = "white", family = my_font) +
  geom_text(data = df_for_text7, aes(x = BPE, y = 100-4, label = bar_text), size = 4, color = "white", family = my_font)
## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database
## Warning in grid.Call.graphics(C_text, as.graphicsAnnot(x$label), x$x, x$y, :
## font family not found in Windows font database
## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

3.5. Vẽ biểu đồ likert cho dữ liệu Đà Nẵng - Nhãn tiếng việt

# Nhãm tiếng việt
DN_SEM5_viet = within(DN_SEM5, {
  Res = factor(Res, labels = c("R\u1EA5t kh\u00F4ng \u0111\u1ED3ng \u00FD", "Kh\u00F4ng \u0111\u1ED3ng \u00FD", "Kh\u00E1 kh\u00F4ng \u0111\u1ED3ng \u00FD", "B\u00ECnh th\u01B0\u1EDDng", "Kh\u00E1 \u0111\u1ED3ng \u00FD", "\u0110\u1ED3ng \u00FD", "R\u1EA5t \u0111\u1ED3ng \u00FD"))
  BPE = factor(BPE, labels = c("PSB1", "PSB2", "PSB3", "PSB4", "PSQT1", "PSQT2", "PSQT3", "PSQT4", "PSQC1", "PSQC2", "PSQC3", "PSQC4", "PSQC5", "PSQC6", "PSQP1", "PSQP2", "PSQP3", "PSQP4", "PSQR1", "PSQR2", "PSQR3", "PSQR4", "SAT1", "SAT2", "SAT3", "IMA1", "IMA2", "IMA3", "IMA4", "IMA5", "PHB1", "PHB2", "PHB3", "PHB4", "PHB5", "PEB1", "PEB2", "PEB3", "PEB4", "PVA1", "PVA2", "PVA3"))
  })
str(DN_SEM5_viet)
## 'data.frame':    17220 obs. of  2 variables:
##  $ Res: Factor w/ 7 levels "R<U+1EA5>t không d<U+1ED3>ng ý",..: 6 6 6 5 6 6 6 7 4 6 ...
##  $ BPE: Factor w/ 42 levels "PSB1","PSB2",..: 15 15 15 15 15 15 15 15 15 15 ...
summary(DN_SEM5_viet)
##                              Res            BPE       
##  R<U+1EA5>t không d<U+1ED3>ng ý:  93   PSB1   :  410  
##  Không d<U+1ED3>ng ý           : 237   PSB2   :  410  
##  Khá không d<U+1ED3>ng ý       : 617   PSB3   :  410  
##  Bình thu<U+1EDD>ng            :1286   PSB4   :  410  
##  Khá d<U+1ED3>ng ý             :4005   PSQT1  :  410  
##  Ð<U+1ED3>ng ý                 :7994   PSQT2  :  410  
##  R<U+1EA5>t d<U+1ED3>ng ý      :2988   (Other):14760
    ## t <- compareGroups(Res ~ BPE, data = DN_SEM1)
    ## createTable(t)
DN_SEM5_viet %>% 
  group_by(BPE, Res) %>% 
  count() %>% 
  ungroup() %>% 
  group_by(BPE) %>% 
  mutate(percent = 100*n / sum(n)) %>% 
  mutate(percent = round(percent, 2)) %>% 
  mutate(bar_text = paste0(percent, "%")) %>% 
  ungroup() -> df_for_ploting
df_for_ploting %>% 
  filter(Res == Res[7]) %>% 
  # arrange(percent) %>% # sắp xếp theo %
  pull(BPE) -> order_x
order_x
##  [1] PSB1  PSB2  PSB3  PSB4  PSQT1 PSQT2 PSQT3 PSQT4 PSQC1 PSQC2 PSQC3 PSQC4
## [13] PSQC5 PSQC6 PSQP1 PSQP2 PSQP3 PSQP4 PSQR1 PSQR2 PSQR3 PSQR4 SAT1  SAT2 
## [25] SAT3  IMA1  IMA2  IMA3  IMA4  IMA5  PHB1  PHB2  PHB3  PHB4  PHB5  PEB1 
## [37] PEB2  PEB3  PEB4  PVA1  PVA2  PVA3 
## 42 Levels: PSB1 PSB2 PSB3 PSB4 PSQT1 PSQT2 PSQT3 PSQT4 PSQC1 PSQC2 ... PVA3
# Make a draft plot: 
my_colors <- c("#3e6487", "#829cb2", "pink", "pink3", "palevioletred", "rosybrown2", "rosybrown3")
my_font <- "Roboto Condensed"

df_for_ploting %>% 
  mutate(BPE = factor(BPE, levels = order_x), Res = factor(Res, levels = Res[7:1])) -> df_odered
df_odered
## # A tibble: 272 x 5
##    BPE   Res                  n percent bar_text
##    <fct> <fct>            <int>   <dbl> <chr>   
##  1 PSB1  R<U+1EA5>t không d<U+1ED3>ng ý     1    0.24 0.24%   
##  2 PSB1  Không d<U+1ED3>ng ý         2    0.49 0.49%   
##  3 PSB1  Khá không d<U+1ED3>ng ý    12    2.93 2.93%   
##  4 PSB1  Bình thu<U+1EDD>ng         54   13.2  13.17%  
##  5 PSB1  Khá d<U+1ED3>ng ý         137   33.4  33.41%  
##  6 PSB1  Ð<U+1ED3>ng ý             171   41.7  41.71%  
##  7 PSB1  R<U+1EA5>t d<U+1ED3>ng ý          33    8.05 8.05%   
##  8 PSB2  Khá không d<U+1ED3>ng ý     8    1.95 1.95%   
##  9 PSB2  Bình thu<U+1EDD>ng         47   11.5  11.46%  
## 10 PSB2  Khá d<U+1ED3>ng ý         114   27.8  27.8%   
## # ... with 262 more rows
library(extrafont)
theme_set(theme_minimal())
gg_viet <- df_odered %>% 
  ggplot(aes(x = BPE, y = percent, fill = Res)) + 
  geom_col(width = 0.8) + 
  coord_flip() + 
  scale_fill_manual(values = my_colors[7:1], name = "") + 
  theme(legend.position = "top") + 
  theme(text = element_text(family = my_font)) + 
  guides(fill = guide_legend(reverse = TRUE)) + 
  scale_y_continuous(labels = paste0(seq(0, 100, 25), "%"), expand = c(0, 0)) + 
  theme(plot.title = element_text(size = 18), plot.subtitle = element_text(size = 11, color = "grey20")) + 
  theme(axis.text = element_text(color = "grey20", size = 10.2)) + 
  theme(plot.margin = unit(rep(0.7, 4), "cm")) + 
  theme(panel.grid.major.y = element_blank(), panel.grid.minor.x = element_blank()) + 
  theme(legend.key.height = unit(0.15, "mm")) + 
  labs(x = NULL, y = NULL, 
       title = "C\u1EA3m nh\u1EADn c\u1EE7a h\u00E0nh kh\u00E1ch \u0111\u1ED1i v\u1EDBi h\u1EC7 th\u1ED1ng xe bu\u00FDt \u0111\u00F4 th\u1ECB \u0110\u00E0 N\u1EB5ng", 
       subtitle = "Thang \u0111o Likert l\u00E0 lo\u1EA1i thang \u0111o \u0111i\u1EC3m \u0111\u00E1nh gi\u00E1 \u0111\u01B0\u1EE3c s\u1EED d\u1EE5ng ph\u1ED5 bi\u1EBFn trong kh\u1EA3o s\u00E1t. Nghi\u00EAn c\u1EE9u s\u1EED d\u1EE5ng thang \u0111o 7 m\u1EE9c \u0111\u1ED9 t\u01B0\u01A1ng \u1EE9ng v\u1EDBi 1 - R\u1EA5t kh\u00F4ng \u0111\u1ED3ng \u00FD \u0111\u1EBFn 7 - R\u1EA5t \u0111\u1ED3ng \u00FD.")
gg_viet
## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

# For displaying percent of "Very Disagree": Điều chỉnh percent để thể hiện giá trị của %
df_odered %>% 
  filter(Res == "R\u1EA5t kh\u00F4ng \u0111\u1ED3ng \u00FD") %>% 
  filter(percent >= 0) -> df_for_text1
df_for_text1
## # A tibble: 27 x 5
##    BPE   Res                  n percent bar_text
##    <fct> <fct>            <int>   <dbl> <chr>   
##  1 PSB1  R<U+1EA5>t không d<U+1ED3>ng ý     1    0.24 0.24%   
##  2 PSQT2 R<U+1EA5>t không d<U+1ED3>ng ý     1    0.24 0.24%   
##  3 PSQT3 R<U+1EA5>t không d<U+1ED3>ng ý     1    0.24 0.24%   
##  4 PSQC2 R<U+1EA5>t không d<U+1ED3>ng ý     2    0.49 0.49%   
##  5 PSQP1 R<U+1EA5>t không d<U+1ED3>ng ý     7    1.71 1.71%   
##  6 PSQP2 R<U+1EA5>t không d<U+1ED3>ng ý     4    0.98 0.98%   
##  7 PSQP3 R<U+1EA5>t không d<U+1ED3>ng ý     1    0.24 0.24%   
##  8 PSQP4 R<U+1EA5>t không d<U+1ED3>ng ý     4    0.98 0.98%   
##  9 PSQR1 R<U+1EA5>t không d<U+1ED3>ng ý     4    0.98 0.98%   
## 10 PSQR2 R<U+1EA5>t không d<U+1ED3>ng ý     3    0.73 0.73%   
## # ... with 17 more rows
# For displaying percent of "Disagree": 
df_odered %>% 
  filter(Res == "Kh\u00F4ng \u0111\u1ED3ng \u00FD") %>% 
  filter(percent >= 0) -> df_for_text2
df_for_text2
## # A tibble: 35 x 5
##    BPE   Res              n percent bar_text
##    <fct> <fct>        <int>   <dbl> <chr>   
##  1 PSB1  Không d<U+1ED3>ng ý     2    0.49 0.49%   
##  2 PSB4  Không d<U+1ED3>ng ý     1    0.24 0.24%   
##  3 PSQT3 Không d<U+1ED3>ng ý     4    0.98 0.98%   
##  4 PSQT4 Không d<U+1ED3>ng ý     6    1.46 1.46%   
##  5 PSQC1 Không d<U+1ED3>ng ý     5    1.22 1.22%   
##  6 PSQC2 Không d<U+1ED3>ng ý     6    1.46 1.46%   
##  7 PSQC3 Không d<U+1ED3>ng ý     5    1.22 1.22%   
##  8 PSQC4 Không d<U+1ED3>ng ý    11    2.68 2.68%   
##  9 PSQC6 Không d<U+1ED3>ng ý     1    0.24 0.24%   
## 10 PSQP1 Không d<U+1ED3>ng ý     9    2.2  2.2%    
## # ... with 25 more rows
# For displaying percent of "Quite Disagree": 
df_odered %>% 
  filter(Res == "Kh\u00E1 kh\u00F4ng \u0111\u1ED3ng \u00FD") %>% 
  filter(percent >= 0) -> df_for_text3
df_for_text3
## # A tibble: 42 x 5
##    BPE   Res                  n percent bar_text
##    <fct> <fct>            <int>   <dbl> <chr>   
##  1 PSB1  Khá không d<U+1ED3>ng ý    12    2.93 2.93%   
##  2 PSB2  Khá không d<U+1ED3>ng ý     8    1.95 1.95%   
##  3 PSB3  Khá không d<U+1ED3>ng ý     5    1.22 1.22%   
##  4 PSB4  Khá không d<U+1ED3>ng ý     8    1.95 1.95%   
##  5 PSQT1 Khá không d<U+1ED3>ng ý     5    1.22 1.22%   
##  6 PSQT2 Khá không d<U+1ED3>ng ý     3    0.73 0.73%   
##  7 PSQT3 Khá không d<U+1ED3>ng ý     9    2.2  2.2%    
##  8 PSQT4 Khá không d<U+1ED3>ng ý    14    3.41 3.41%   
##  9 PSQC1 Khá không d<U+1ED3>ng ý    15    3.66 3.66%   
## 10 PSQC2 Khá không d<U+1ED3>ng ý    17    4.15 4.15%   
## # ... with 32 more rows
# For displaying percent of "Normal": 
df_odered %>% 
  filter(Res == "B\u00ECnh th\u01B0\u1EDDng") %>% 
  filter(percent >= 0) -> df_for_text4
df_for_text4
## # A tibble: 42 x 5
##    BPE   Res             n percent bar_text
##    <fct> <fct>       <int>   <dbl> <chr>   
##  1 PSB1  Bình thu<U+1EDD>ng    54   13.2  13.17%  
##  2 PSB2  Bình thu<U+1EDD>ng    47   11.5  11.46%  
##  3 PSB3  Bình thu<U+1EDD>ng    39    9.51 9.51%   
##  4 PSB4  Bình thu<U+1EDD>ng    25    6.1  6.1%    
##  5 PSQT1 Bình thu<U+1EDD>ng    23    5.61 5.61%   
##  6 PSQT2 Bình thu<U+1EDD>ng    14    3.41 3.41%   
##  7 PSQT3 Bình thu<U+1EDD>ng    17    4.15 4.15%   
##  8 PSQT4 Bình thu<U+1EDD>ng    25    6.1  6.1%    
##  9 PSQC1 Bình thu<U+1EDD>ng    26    6.34 6.34%   
## 10 PSQC2 Bình thu<U+1EDD>ng    34    8.29 8.29%   
## # ... with 32 more rows
# For displaying percent of "Quite Agree": 
df_odered %>% 
  filter(Res == "Kh\u00E1 \u0111\u1ED3ng \u00FD") %>% 
  filter(percent >= 0) -> df_for_text5
df_for_text5
## # A tibble: 42 x 5
##    BPE   Res            n percent bar_text
##    <fct> <fct>      <int>   <dbl> <chr>   
##  1 PSB1  Khá d<U+1ED3>ng ý   137    33.4 33.41%  
##  2 PSB2  Khá d<U+1ED3>ng ý   114    27.8 27.8%   
##  3 PSB3  Khá d<U+1ED3>ng ý   107    26.1 26.1%   
##  4 PSB4  Khá d<U+1ED3>ng ý   104    25.4 25.37%  
##  5 PSQT1 Khá d<U+1ED3>ng ý    97    23.7 23.66%  
##  6 PSQT2 Khá d<U+1ED3>ng ý    77    18.8 18.78%  
##  7 PSQT3 Khá d<U+1ED3>ng ý    98    23.9 23.9%   
##  8 PSQT4 Khá d<U+1ED3>ng ý    86    21.0 20.98%  
##  9 PSQC1 Khá d<U+1ED3>ng ý    89    21.7 21.71%  
## 10 PSQC2 Khá d<U+1ED3>ng ý   139    33.9 33.9%   
## # ... with 32 more rows
# For displaying percent of "Agree": 
df_odered %>% 
  filter(Res == "\u0110\u1ED3ng \u00FD") %>% 
  filter(percent >= 0) -> df_for_text6
df_for_text6
## # A tibble: 42 x 5
##    BPE   Res        n percent bar_text
##    <fct> <fct>  <int>   <dbl> <chr>   
##  1 PSB1  Ð<U+1ED3>ng ý   171    41.7 41.71%  
##  2 PSB2  Ð<U+1ED3>ng ý   207    50.5 50.49%  
##  3 PSB3  Ð<U+1ED3>ng ý   216    52.7 52.68%  
##  4 PSB4  Ð<U+1ED3>ng ý   221    53.9 53.9%   
##  5 PSQT1 Ð<U+1ED3>ng ý   233    56.8 56.83%  
##  6 PSQT2 Ð<U+1ED3>ng ý   210    51.2 51.22%  
##  7 PSQT3 Ð<U+1ED3>ng ý   187    45.6 45.61%  
##  8 PSQT4 Ð<U+1ED3>ng ý   193    47.1 47.07%  
##  9 PSQC1 Ð<U+1ED3>ng ý   193    47.1 47.07%  
## 10 PSQC2 Ð<U+1ED3>ng ý   159    38.8 38.78%  
## # ... with 32 more rows
# For displaying percent of "Very Agree": 
df_odered %>% 
  filter(Res == "R\u1EA5t \u0111\u1ED3ng \u00FD") %>% 
  filter(percent >= 0) -> df_for_text7
df_for_text7
## # A tibble: 42 x 5
##    BPE   Res            n percent bar_text
##    <fct> <fct>      <int>   <dbl> <chr>   
##  1 PSB1  R<U+1EA5>t d<U+1ED3>ng ý    33    8.05 8.05%   
##  2 PSB2  R<U+1EA5>t d<U+1ED3>ng ý    34    8.29 8.29%   
##  3 PSB3  R<U+1EA5>t d<U+1ED3>ng ý    43   10.5  10.49%  
##  4 PSB4  R<U+1EA5>t d<U+1ED3>ng ý    51   12.4  12.44%  
##  5 PSQT1 R<U+1EA5>t d<U+1ED3>ng ý    52   12.7  12.68%  
##  6 PSQT2 R<U+1EA5>t d<U+1ED3>ng ý   105   25.6  25.61%  
##  7 PSQT3 R<U+1EA5>t d<U+1ED3>ng ý    94   22.9  22.93%  
##  8 PSQT4 R<U+1EA5>t d<U+1ED3>ng ý    86   21.0  20.98%  
##  9 PSQC1 R<U+1EA5>t d<U+1ED3>ng ý    82   20    20%     
## 10 PSQC2 R<U+1EA5>t d<U+1ED3>ng ý    53   12.9  12.93%  
## # ... with 32 more rows
# For displaying percent of "Very Agree": 
df_odered %>% 
  filter(Res == "R\u1EA5t \u0111\u1ED3ng \u00FD") -> df_for_text
df_for_text
## # A tibble: 42 x 5
##    BPE   Res            n percent bar_text
##    <fct> <fct>      <int>   <dbl> <chr>   
##  1 PSB1  R<U+1EA5>t d<U+1ED3>ng ý    33    8.05 8.05%   
##  2 PSB2  R<U+1EA5>t d<U+1ED3>ng ý    34    8.29 8.29%   
##  3 PSB3  R<U+1EA5>t d<U+1ED3>ng ý    43   10.5  10.49%  
##  4 PSB4  R<U+1EA5>t d<U+1ED3>ng ý    51   12.4  12.44%  
##  5 PSQT1 R<U+1EA5>t d<U+1ED3>ng ý    52   12.7  12.68%  
##  6 PSQT2 R<U+1EA5>t d<U+1ED3>ng ý   105   25.6  25.61%  
##  7 PSQT3 R<U+1EA5>t d<U+1ED3>ng ý    94   22.9  22.93%  
##  8 PSQT4 R<U+1EA5>t d<U+1ED3>ng ý    86   21.0  20.98%  
##  9 PSQC1 R<U+1EA5>t d<U+1ED3>ng ý    82   20    20%     
## 10 PSQC2 R<U+1EA5>t d<U+1ED3>ng ý    53   12.9  12.93%  
## # ... with 32 more rows
# Ad text layers-thay đổi giá trị y để thể hiện vị trí ghi text phù hợp
gg_viet + 
  geom_text(data = df_for_text1, aes(x = BPE, y = 2, label = bar_text), size = 4, color = "white", family = my_font) + 
  geom_text(data = df_for_text6, aes(x = BPE, y = 100-40, label = bar_text), size = 4, color = "white", family = my_font) +
  geom_text(data = df_for_text7, aes(x = BPE, y = 100-4, label = bar_text), size = 4, color = "white", family = my_font)
## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database
## Warning in grid.Call.graphics(C_text, as.graphicsAnnot(x$label), x$x, x$y, :
## font family not found in Windows font database
## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

3.6. Vẽ biểu đồ likert cho dữ liệu Hồ Chí Minh-Nhãn tiếng anh

# Plot Likert graph for people in Ho Chi Minh 
library(tidyverse)
library(compareGroups)
head(HCM_SEM5)
##   Res  BPE
## 1   6 PSB1
## 2   3 PSB1
## 3   2 PSB1
## 4   5 PSB1
## 5   2 PSB1
## 6   2 PSB1
dim(HCM_SEM5)
## [1] 18816     2
attach(HCM_SEM5)
## The following objects are masked from DN_SEM5:
## 
##     BPE, Res
## The following objects are masked from DN_HCM_SEM5:
## 
##     BPE, Res
HCM_SEM5 = within(HCM_SEM5, {
  Res = factor(Res, labels = c("Very Disagree", "Disagree", "Quite Disagree", "Normal", "Quite Agree", "Agree", "Very Agree"))
  BPE = factor(BPE, labels = c("PSB1", "PSB2", "PSB3", "PSB4", "PSQT1", "PSQT2", "PSQT3", "PSQT4", "PSQC1", "PSQC2", "PSQC3", "PSQC4", "PSQC5", "PSQC6", "PSQP1", "PSQP2", "PSQP3", "PSQP4", "PSQR1", "PSQR2", "PSQR3", "PSQR4", "SAT1", "SAT2", "SAT3", "IMA1", "IMA2", "IMA3", "IMA4", "IMA5", "PHB1", "PHB2", "PHB3", "PHB4", "PHB5", "PEB1", "PEB2", "PEB3", "PEB4", "PVA1", "PVA2", "PVA3"))
  })
str(HCM_SEM5)
## 'data.frame':    18816 obs. of  2 variables:
##  $ Res: Factor w/ 7 levels "Very Disagree",..: 6 3 2 5 2 2 1 6 2 4 ...
##  $ BPE: Factor w/ 42 levels "PSB1","PSB2",..: 15 15 15 15 15 15 15 15 15 15 ...
summary(HCM_SEM5)
##              Res            BPE       
##  Very Disagree : 604   PSB1   :  448  
##  Disagree      :1080   PSB2   :  448  
##  Quite Disagree: 885   PSB3   :  448  
##  Normal        :2864   PSB4   :  448  
##  Quite Agree   :3473   PSQT1  :  448  
##  Agree         :7680   PSQT2  :  448  
##  Very Agree    :2230   (Other):16128
    ## t <- compareGroups(Res ~ BPE, data = DN_SEM1)
    ## createTable(t)
HCM_SEM5 %>% 
  group_by(BPE, Res) %>% 
  count() %>% 
  ungroup() %>% 
  group_by(BPE) %>% 
  mutate(percent = 100*n / sum(n)) %>% 
  mutate(percent = round(percent, 2)) %>% 
  mutate(bar_text = paste0(percent, "%")) %>% 
  ungroup() -> df_for_ploting
df_for_ploting %>% 
  filter(Res == Res[7]) %>% 
  # arrange(percent) %>% # sắp xếp theo %
  pull(BPE) -> order_x
order_x
##  [1] PSB1  PSB2  PSB3  PSB4  PSQT1 PSQT2 PSQT3 PSQT4 PSQC1 PSQC2 PSQC3 PSQC4
## [13] PSQC5 PSQC6 PSQP1 PSQP2 PSQP3 PSQP4 PSQR1 PSQR2 PSQR3 PSQR4 SAT1  SAT2 
## [25] SAT3  IMA1  IMA2  IMA3  IMA4  IMA5  PHB1  PHB2  PHB3  PHB4  PHB5  PEB1 
## [37] PEB2  PEB3  PEB4  PVA1  PVA2  PVA3 
## 42 Levels: PSB1 PSB2 PSB3 PSB4 PSQT1 PSQT2 PSQT3 PSQT4 PSQC1 PSQC2 ... PVA3
# Make a draft plot: 
my_colors <- c("#3e6487", "#829cb2", "pink", "pink3", "palevioletred", "rosybrown2", "rosybrown3")
my_font <- "Roboto Condensed"

df_for_ploting %>% 
  mutate(BPE = factor(BPE, levels = order_x), Res = factor(Res, levels = Res[7:1])) -> df_odered
df_odered
## # A tibble: 294 x 5
##    BPE   Res                n percent bar_text
##    <fct> <fct>          <int>   <dbl> <chr>   
##  1 PSB1  Very Disagree      5    1.12 1.12%   
##  2 PSB1  Disagree          17    3.79 3.79%   
##  3 PSB1  Quite Disagree    21    4.69 4.69%   
##  4 PSB1  Normal           100   22.3  22.32%  
##  5 PSB1  Quite Agree       93   20.8  20.76%  
##  6 PSB1  Agree            180   40.2  40.18%  
##  7 PSB1  Very Agree        32    7.14 7.14%   
##  8 PSB2  Very Disagree     11    2.46 2.46%   
##  9 PSB2  Disagree          18    4.02 4.02%   
## 10 PSB2  Quite Disagree    18    4.02 4.02%   
## # ... with 284 more rows
library(extrafont)
theme_set(theme_minimal())
gg <- df_odered %>% 
  ggplot(aes(x = BPE, y = percent, fill = Res)) + 
  geom_col(width = 0.8) + 
  coord_flip() + 
  scale_fill_manual(values = my_colors[7:1], name = "") + 
  theme(legend.position = "top") + 
  theme(text = element_text(family = my_font)) + 
  guides(fill = guide_legend(reverse = TRUE)) + 
  scale_y_continuous(labels = paste0(seq(0, 100, 25), "%"), expand = c(0, 0)) + 
  theme(plot.title = element_text(size = 18), plot.subtitle = element_text(size = 11, color = "grey20")) + 
  theme(axis.text = element_text(color = "grey20", size = 10.2)) + 
  theme(plot.margin = unit(rep(0.7, 4), "cm")) + 
  theme(panel.grid.major.y = element_blank(), panel.grid.minor.x = element_blank()) + 
  theme(legend.key.height = unit(0.15, "mm")) + 
  labs(x = NULL, y = NULL, 
       title = "Perception of passengers towards bus systems in Ho Chi Minh", 
       subtitle = "Likert scale is a type of rating scale commonly used in surveys. When responding to a Likert type question,\nrespondents simply state their level of agreement or disagreement on a symmetric agree-disagree scale.")
gg
## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

# For displaying percent of "Very Disagree": Điều chỉnh percent để thể hiện giá trị của %
df_odered %>% 
  filter(Res == "Very Disagree") %>% 
  filter(percent >= 0) -> df_for_text1
df_for_text1
## # A tibble: 42 x 5
##    BPE   Res               n percent bar_text
##    <fct> <fct>         <int>   <dbl> <chr>   
##  1 PSB1  Very Disagree     5    1.12 1.12%   
##  2 PSB2  Very Disagree    11    2.46 2.46%   
##  3 PSB3  Very Disagree    11    2.46 2.46%   
##  4 PSB4  Very Disagree    13    2.9  2.9%    
##  5 PSQT1 Very Disagree     6    1.34 1.34%   
##  6 PSQT2 Very Disagree    23    5.13 5.13%   
##  7 PSQT3 Very Disagree    24    5.36 5.36%   
##  8 PSQT4 Very Disagree    25    5.58 5.58%   
##  9 PSQC1 Very Disagree    24    5.36 5.36%   
## 10 PSQC2 Very Disagree    23    5.13 5.13%   
## # ... with 32 more rows
# For displaying percent of "Disagree": 
df_odered %>% 
  filter(Res == "Disagree") %>% 
  filter(percent >= 0) -> df_for_text2
df_for_text2
## # A tibble: 42 x 5
##    BPE   Res          n percent bar_text
##    <fct> <fct>    <int>   <dbl> <chr>   
##  1 PSB1  Disagree    17    3.79 3.79%   
##  2 PSB2  Disagree    18    4.02 4.02%   
##  3 PSB3  Disagree    10    2.23 2.23%   
##  4 PSB4  Disagree    14    3.12 3.12%   
##  5 PSQT1 Disagree    20    4.46 4.46%   
##  6 PSQT2 Disagree     8    1.79 1.79%   
##  7 PSQT3 Disagree    13    2.9  2.9%    
##  8 PSQT4 Disagree    14    3.12 3.12%   
##  9 PSQC1 Disagree    14    3.12 3.12%   
## 10 PSQC2 Disagree    12    2.68 2.68%   
## # ... with 32 more rows
# For displaying percent of "Quite Disagree": 
df_odered %>% 
  filter(Res == "Quite Disagree") %>% 
  filter(percent >= 0) -> df_for_text3
df_for_text3
## # A tibble: 42 x 5
##    BPE   Res                n percent bar_text
##    <fct> <fct>          <int>   <dbl> <chr>   
##  1 PSB1  Quite Disagree    21    4.69 4.69%   
##  2 PSB2  Quite Disagree    18    4.02 4.02%   
##  3 PSB3  Quite Disagree    16    3.57 3.57%   
##  4 PSB4  Quite Disagree    18    4.02 4.02%   
##  5 PSQT1 Quite Disagree    15    3.35 3.35%   
##  6 PSQT2 Quite Disagree    10    2.23 2.23%   
##  7 PSQT3 Quite Disagree    12    2.68 2.68%   
##  8 PSQT4 Quite Disagree     8    1.79 1.79%   
##  9 PSQC1 Quite Disagree     7    1.56 1.56%   
## 10 PSQC2 Quite Disagree    20    4.46 4.46%   
## # ... with 32 more rows
# For displaying percent of "Normal": 
df_odered %>% 
  filter(Res == "Normal") %>% 
  filter(percent >= 0) -> df_for_text4
df_for_text4
## # A tibble: 42 x 5
##    BPE   Res        n percent bar_text
##    <fct> <fct>  <int>   <dbl> <chr>   
##  1 PSB1  Normal   100    22.3 22.32%  
##  2 PSB2  Normal   111    24.8 24.78%  
##  3 PSB3  Normal    89    19.9 19.87%  
##  4 PSB4  Normal    88    19.6 19.64%  
##  5 PSQT1 Normal    81    18.1 18.08%  
##  6 PSQT2 Normal    46    10.3 10.27%  
##  7 PSQT3 Normal    50    11.2 11.16%  
##  8 PSQT4 Normal    52    11.6 11.61%  
##  9 PSQC1 Normal    67    15.0 14.96%  
## 10 PSQC2 Normal    63    14.1 14.06%  
## # ... with 32 more rows
# For displaying percent of "Quite Agree": 
df_odered %>% 
  filter(Res == "Quite Agree") %>% 
  filter(percent >= 0) -> df_for_text5
df_for_text5
## # A tibble: 42 x 5
##    BPE   Res             n percent bar_text
##    <fct> <fct>       <int>   <dbl> <chr>   
##  1 PSB1  Quite Agree    93    20.8 20.76%  
##  2 PSB2  Quite Agree   100    22.3 22.32%  
##  3 PSB3  Quite Agree   100    22.3 22.32%  
##  4 PSB4  Quite Agree    97    21.6 21.65%  
##  5 PSQT1 Quite Agree   107    23.9 23.88%  
##  6 PSQT2 Quite Agree    50    11.2 11.16%  
##  7 PSQT3 Quite Agree    72    16.1 16.07%  
##  8 PSQT4 Quite Agree    82    18.3 18.3%   
##  9 PSQC1 Quite Agree    78    17.4 17.41%  
## 10 PSQC2 Quite Agree    76    17.0 16.96%  
## # ... with 32 more rows
# For displaying percent of "Agree": 
df_odered %>% 
  filter(Res == "Agree") %>% 
  filter(percent >= 0) -> df_for_text6
df_for_text6
## # A tibble: 42 x 5
##    BPE   Res       n percent bar_text
##    <fct> <fct> <int>   <dbl> <chr>   
##  1 PSB1  Agree   180    40.2 40.18%  
##  2 PSB2  Agree   158    35.3 35.27%  
##  3 PSB3  Agree   187    41.7 41.74%  
##  4 PSB4  Agree   185    41.3 41.29%  
##  5 PSQT1 Agree   187    41.7 41.74%  
##  6 PSQT2 Agree   181    40.4 40.4%   
##  7 PSQT3 Agree   166    37.0 37.05%  
##  8 PSQT4 Agree   161    35.9 35.94%  
##  9 PSQC1 Agree   165    36.8 36.83%  
## 10 PSQC2 Agree   193    43.1 43.08%  
## # ... with 32 more rows
# For displaying percent of "Very Agree": 
df_odered %>% 
  filter(Res == "Very Agree") %>% 
  filter(percent >= 0) -> df_for_text7
df_for_text7
## # A tibble: 42 x 5
##    BPE   Res            n percent bar_text
##    <fct> <fct>      <int>   <dbl> <chr>   
##  1 PSB1  Very Agree    32    7.14 7.14%   
##  2 PSB2  Very Agree    32    7.14 7.14%   
##  3 PSB3  Very Agree    35    7.81 7.81%   
##  4 PSB4  Very Agree    33    7.37 7.37%   
##  5 PSQT1 Very Agree    32    7.14 7.14%   
##  6 PSQT2 Very Agree   130   29.0  29.02%  
##  7 PSQT3 Very Agree   111   24.8  24.78%  
##  8 PSQT4 Very Agree   106   23.7  23.66%  
##  9 PSQC1 Very Agree    93   20.8  20.76%  
## 10 PSQC2 Very Agree    61   13.6  13.62%  
## # ... with 32 more rows
# For displaying percent of "Very Agree": 
df_odered %>% 
  filter(Res == "Very Agree") -> df_for_text
df_for_text
## # A tibble: 42 x 5
##    BPE   Res            n percent bar_text
##    <fct> <fct>      <int>   <dbl> <chr>   
##  1 PSB1  Very Agree    32    7.14 7.14%   
##  2 PSB2  Very Agree    32    7.14 7.14%   
##  3 PSB3  Very Agree    35    7.81 7.81%   
##  4 PSB4  Very Agree    33    7.37 7.37%   
##  5 PSQT1 Very Agree    32    7.14 7.14%   
##  6 PSQT2 Very Agree   130   29.0  29.02%  
##  7 PSQT3 Very Agree   111   24.8  24.78%  
##  8 PSQT4 Very Agree   106   23.7  23.66%  
##  9 PSQC1 Very Agree    93   20.8  20.76%  
## 10 PSQC2 Very Agree    61   13.6  13.62%  
## # ... with 32 more rows
# Ad text layers-thay đổi giá trị y để thể hiện vị trí ghi text phù hợp
gg + 
  geom_text(data = df_for_text1, aes(x = BPE, y = 4, label = bar_text), size = 4, color = "white", family = my_font) + 
  geom_text(data = df_for_text6, aes(x = BPE, y = 100-30, label = bar_text), size = 4, color = "white", family = my_font) +
  geom_text(data = df_for_text7, aes(x = BPE, y = 100-2, label = bar_text), size = 4, color = "white", family = my_font)
## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database
## Warning in grid.Call.graphics(C_text, as.graphicsAnnot(x$label), x$x, x$y, :
## font family not found in Windows font database
## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

3.7. Vẽ biểu đồ likert cho dữ liệu Hồ Chí Minh-Nhãn tiếng việt

HCM_SEM5_viet = within(HCM_SEM5, {
  Res = factor(Res, labels = c("R\u1EA5t kh\u00F4ng \u0111\u1ED3ng \u00FD", "Kh\u00F4ng \u0111\u1ED3ng \u00FD", "Kh\u00E1 kh\u00F4ng \u0111\u1ED3ng \u00FD", "B\u00ECnh th\u01B0\u1EDDng", "Kh\u00E1 \u0111\u1ED3ng \u00FD", "\u0110\u1ED3ng \u00FD", "R\u1EA5t \u0111\u1ED3ng \u00FD"))
  BPE = factor(BPE, labels = c("PSB1", "PSB2", "PSB3", "PSB4", "PSQT1", "PSQT2", "PSQT3", "PSQT4", "PSQC1", "PSQC2", "PSQC3", "PSQC4", "PSQC5", "PSQC6", "PSQP1", "PSQP2", "PSQP3", "PSQP4", "PSQR1", "PSQR2", "PSQR3", "PSQR4", "SAT1", "SAT2", "SAT3", "IMA1", "IMA2", "IMA3", "IMA4", "IMA5", "PHB1", "PHB2", "PHB3", "PHB4", "PHB5", "PEB1", "PEB2", "PEB3", "PEB4", "PVA1", "PVA2", "PVA3"))
  })
str(HCM_SEM5_viet)
## 'data.frame':    18816 obs. of  2 variables:
##  $ Res: Factor w/ 7 levels "R<U+1EA5>t không d<U+1ED3>ng ý",..: 6 3 2 5 2 2 1 6 2 4 ...
##  $ BPE: Factor w/ 42 levels "PSB1","PSB2",..: 15 15 15 15 15 15 15 15 15 15 ...
summary(HCM_SEM5_viet)
##                              Res            BPE       
##  R<U+1EA5>t không d<U+1ED3>ng ý: 604   PSB1   :  448  
##  Không d<U+1ED3>ng ý           :1080   PSB2   :  448  
##  Khá không d<U+1ED3>ng ý       : 885   PSB3   :  448  
##  Bình thu<U+1EDD>ng            :2864   PSB4   :  448  
##  Khá d<U+1ED3>ng ý             :3473   PSQT1  :  448  
##  Ð<U+1ED3>ng ý                 :7680   PSQT2  :  448  
##  R<U+1EA5>t d<U+1ED3>ng ý      :2230   (Other):16128
    ## t <- compareGroups(Res ~ BPE, data = DN_SEM1)
    ## createTable(t)
HCM_SEM5_viet %>% 
  group_by(BPE, Res) %>% 
  count() %>% 
  ungroup() %>% 
  group_by(BPE) %>% 
  mutate(percent = 100*n / sum(n)) %>% 
  mutate(percent = round(percent, 2)) %>% 
  mutate(bar_text = paste0(percent, "%")) %>% 
  ungroup() -> df_for_ploting
df_for_ploting %>% 
  filter(Res == Res[7]) %>% 
  # arrange(percent) %>% # sắp xếp theo %
  pull(BPE) -> order_x
order_x
##  [1] PSB1  PSB2  PSB3  PSB4  PSQT1 PSQT2 PSQT3 PSQT4 PSQC1 PSQC2 PSQC3 PSQC4
## [13] PSQC5 PSQC6 PSQP1 PSQP2 PSQP3 PSQP4 PSQR1 PSQR2 PSQR3 PSQR4 SAT1  SAT2 
## [25] SAT3  IMA1  IMA2  IMA3  IMA4  IMA5  PHB1  PHB2  PHB3  PHB4  PHB5  PEB1 
## [37] PEB2  PEB3  PEB4  PVA1  PVA2  PVA3 
## 42 Levels: PSB1 PSB2 PSB3 PSB4 PSQT1 PSQT2 PSQT3 PSQT4 PSQC1 PSQC2 ... PVA3
# Make a draft plot: 
my_colors <- c("#3e6487", "#829cb2", "pink", "pink3", "palevioletred", "rosybrown2", "rosybrown3")
my_font <- "Roboto Condensed"

df_for_ploting %>% 
  mutate(BPE = factor(BPE, levels = order_x), Res = factor(Res, levels = Res[7:1])) -> df_odered
df_odered
## # A tibble: 294 x 5
##    BPE   Res                  n percent bar_text
##    <fct> <fct>            <int>   <dbl> <chr>   
##  1 PSB1  R<U+1EA5>t không d<U+1ED3>ng ý     5    1.12 1.12%   
##  2 PSB1  Không d<U+1ED3>ng ý        17    3.79 3.79%   
##  3 PSB1  Khá không d<U+1ED3>ng ý    21    4.69 4.69%   
##  4 PSB1  Bình thu<U+1EDD>ng        100   22.3  22.32%  
##  5 PSB1  Khá d<U+1ED3>ng ý          93   20.8  20.76%  
##  6 PSB1  Ð<U+1ED3>ng ý             180   40.2  40.18%  
##  7 PSB1  R<U+1EA5>t d<U+1ED3>ng ý          32    7.14 7.14%   
##  8 PSB2  R<U+1EA5>t không d<U+1ED3>ng ý    11    2.46 2.46%   
##  9 PSB2  Không d<U+1ED3>ng ý        18    4.02 4.02%   
## 10 PSB2  Khá không d<U+1ED3>ng ý    18    4.02 4.02%   
## # ... with 284 more rows
library(extrafont)
theme_set(theme_minimal())
gg_viet <- df_odered %>% 
  ggplot(aes(x = BPE, y = percent, fill = Res)) + 
  geom_col(width = 0.8) + 
  coord_flip() + 
  scale_fill_manual(values = my_colors[7:1], name = "") + 
  theme(legend.position = "top") + 
  theme(text = element_text(family = my_font)) + 
  guides(fill = guide_legend(reverse = TRUE)) + 
  scale_y_continuous(labels = paste0(seq(0, 100, 25), "%"), expand = c(0, 0)) + 
  theme(plot.title = element_text(size = 18), plot.subtitle = element_text(size = 11, color = "grey20")) + 
  theme(axis.text = element_text(color = "grey20", size = 10.2)) + 
  theme(plot.margin = unit(rep(0.7, 4), "cm")) + 
  theme(panel.grid.major.y = element_blank(), panel.grid.minor.x = element_blank()) + 
  theme(legend.key.height = unit(0.15, "mm")) + 
  labs(x = NULL, y = NULL, 
       title = "C\u1EA3m nh\u1EADn c\u1EE7a h\u00E0nh kh\u00E1ch v\u1EC1 h\u1EC7 th\u1ED1ng xe bu\u00FDt \u0111\u00F4 th\u1ECB \u1EDF th\u00E0nh ph\u1ED1 H\u1ED3 Ch\u00ED Minh", 
       subtitle = "Thang \u0111o Likert l\u00E0 lo\u1EA1i thang \u0111o \u0111i\u1EC3m \u0111\u00E1nh gi\u00E1 \u0111\u01B0\u1EE3c s\u1EED d\u1EE5ng ph\u1ED5 bi\u1EBFn trong kh\u1EA3o s\u00E1t. Nghi\u00EAn c\u1EE9u s\u1EED d\u1EE5ng thang \u0111o 7 m\u1EE9c \u0111\u1ED9 t\u01B0\u01A1ng \u1EE9ng v\u1EDBi 1 - R\u1EA5t kh\u00F4ng \u0111\u1ED3ng \u00FD \u0111\u1EBFn 7 - R\u1EA5t \u0111\u1ED3ng \u00FD.")
gg_viet
## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

# For displaying percent of "Very Disagree": Điều chỉnh percent để thể hiện giá trị của %
df_odered %>% 
  filter(Res == "R\u1EA5t kh\u00F4ng \u0111\u1ED3ng \u00FD") %>% 
  filter(percent >= 0) -> df_for_text1
df_for_text1
## # A tibble: 42 x 5
##    BPE   Res                  n percent bar_text
##    <fct> <fct>            <int>   <dbl> <chr>   
##  1 PSB1  R<U+1EA5>t không d<U+1ED3>ng ý     5    1.12 1.12%   
##  2 PSB2  R<U+1EA5>t không d<U+1ED3>ng ý    11    2.46 2.46%   
##  3 PSB3  R<U+1EA5>t không d<U+1ED3>ng ý    11    2.46 2.46%   
##  4 PSB4  R<U+1EA5>t không d<U+1ED3>ng ý    13    2.9  2.9%    
##  5 PSQT1 R<U+1EA5>t không d<U+1ED3>ng ý     6    1.34 1.34%   
##  6 PSQT2 R<U+1EA5>t không d<U+1ED3>ng ý    23    5.13 5.13%   
##  7 PSQT3 R<U+1EA5>t không d<U+1ED3>ng ý    24    5.36 5.36%   
##  8 PSQT4 R<U+1EA5>t không d<U+1ED3>ng ý    25    5.58 5.58%   
##  9 PSQC1 R<U+1EA5>t không d<U+1ED3>ng ý    24    5.36 5.36%   
## 10 PSQC2 R<U+1EA5>t không d<U+1ED3>ng ý    23    5.13 5.13%   
## # ... with 32 more rows
# For displaying percent of "Disagree": 
df_odered %>% 
  filter(Res == "Kh\u00F4ng \u0111\u1ED3ng \u00FD") %>% 
  filter(percent >= 0) -> df_for_text2
df_for_text2
## # A tibble: 42 x 5
##    BPE   Res              n percent bar_text
##    <fct> <fct>        <int>   <dbl> <chr>   
##  1 PSB1  Không d<U+1ED3>ng ý    17    3.79 3.79%   
##  2 PSB2  Không d<U+1ED3>ng ý    18    4.02 4.02%   
##  3 PSB3  Không d<U+1ED3>ng ý    10    2.23 2.23%   
##  4 PSB4  Không d<U+1ED3>ng ý    14    3.12 3.12%   
##  5 PSQT1 Không d<U+1ED3>ng ý    20    4.46 4.46%   
##  6 PSQT2 Không d<U+1ED3>ng ý     8    1.79 1.79%   
##  7 PSQT3 Không d<U+1ED3>ng ý    13    2.9  2.9%    
##  8 PSQT4 Không d<U+1ED3>ng ý    14    3.12 3.12%   
##  9 PSQC1 Không d<U+1ED3>ng ý    14    3.12 3.12%   
## 10 PSQC2 Không d<U+1ED3>ng ý    12    2.68 2.68%   
## # ... with 32 more rows
# For displaying percent of "Quite Disagree": 
df_odered %>% 
  filter(Res == "Kh\u00E1 kh\u00F4ng \u0111\u1ED3ng \u00FD") %>% 
  filter(percent >= 0) -> df_for_text3
df_for_text3
## # A tibble: 42 x 5
##    BPE   Res                  n percent bar_text
##    <fct> <fct>            <int>   <dbl> <chr>   
##  1 PSB1  Khá không d<U+1ED3>ng ý    21    4.69 4.69%   
##  2 PSB2  Khá không d<U+1ED3>ng ý    18    4.02 4.02%   
##  3 PSB3  Khá không d<U+1ED3>ng ý    16    3.57 3.57%   
##  4 PSB4  Khá không d<U+1ED3>ng ý    18    4.02 4.02%   
##  5 PSQT1 Khá không d<U+1ED3>ng ý    15    3.35 3.35%   
##  6 PSQT2 Khá không d<U+1ED3>ng ý    10    2.23 2.23%   
##  7 PSQT3 Khá không d<U+1ED3>ng ý    12    2.68 2.68%   
##  8 PSQT4 Khá không d<U+1ED3>ng ý     8    1.79 1.79%   
##  9 PSQC1 Khá không d<U+1ED3>ng ý     7    1.56 1.56%   
## 10 PSQC2 Khá không d<U+1ED3>ng ý    20    4.46 4.46%   
## # ... with 32 more rows
# For displaying percent of "Normal": 
df_odered %>% 
  filter(Res == "B\u00ECnh th\u01B0\u1EDDng") %>% 
  filter(percent >= 0) -> df_for_text4
df_for_text4
## # A tibble: 42 x 5
##    BPE   Res             n percent bar_text
##    <fct> <fct>       <int>   <dbl> <chr>   
##  1 PSB1  Bình thu<U+1EDD>ng   100    22.3 22.32%  
##  2 PSB2  Bình thu<U+1EDD>ng   111    24.8 24.78%  
##  3 PSB3  Bình thu<U+1EDD>ng    89    19.9 19.87%  
##  4 PSB4  Bình thu<U+1EDD>ng    88    19.6 19.64%  
##  5 PSQT1 Bình thu<U+1EDD>ng    81    18.1 18.08%  
##  6 PSQT2 Bình thu<U+1EDD>ng    46    10.3 10.27%  
##  7 PSQT3 Bình thu<U+1EDD>ng    50    11.2 11.16%  
##  8 PSQT4 Bình thu<U+1EDD>ng    52    11.6 11.61%  
##  9 PSQC1 Bình thu<U+1EDD>ng    67    15.0 14.96%  
## 10 PSQC2 Bình thu<U+1EDD>ng    63    14.1 14.06%  
## # ... with 32 more rows
# For displaying percent of "Quite Agree": 
df_odered %>% 
  filter(Res == "Kh\u00E1 \u0111\u1ED3ng \u00FD") %>% 
  filter(percent >= 0) -> df_for_text5
df_for_text5
## # A tibble: 42 x 5
##    BPE   Res            n percent bar_text
##    <fct> <fct>      <int>   <dbl> <chr>   
##  1 PSB1  Khá d<U+1ED3>ng ý    93    20.8 20.76%  
##  2 PSB2  Khá d<U+1ED3>ng ý   100    22.3 22.32%  
##  3 PSB3  Khá d<U+1ED3>ng ý   100    22.3 22.32%  
##  4 PSB4  Khá d<U+1ED3>ng ý    97    21.6 21.65%  
##  5 PSQT1 Khá d<U+1ED3>ng ý   107    23.9 23.88%  
##  6 PSQT2 Khá d<U+1ED3>ng ý    50    11.2 11.16%  
##  7 PSQT3 Khá d<U+1ED3>ng ý    72    16.1 16.07%  
##  8 PSQT4 Khá d<U+1ED3>ng ý    82    18.3 18.3%   
##  9 PSQC1 Khá d<U+1ED3>ng ý    78    17.4 17.41%  
## 10 PSQC2 Khá d<U+1ED3>ng ý    76    17.0 16.96%  
## # ... with 32 more rows
# For displaying percent of "Agree": 
df_odered %>% 
  filter(Res == "\u0110\u1ED3ng \u00FD") %>% 
  filter(percent >= 0) -> df_for_text6
df_for_text6
## # A tibble: 42 x 5
##    BPE   Res        n percent bar_text
##    <fct> <fct>  <int>   <dbl> <chr>   
##  1 PSB1  Ð<U+1ED3>ng ý   180    40.2 40.18%  
##  2 PSB2  Ð<U+1ED3>ng ý   158    35.3 35.27%  
##  3 PSB3  Ð<U+1ED3>ng ý   187    41.7 41.74%  
##  4 PSB4  Ð<U+1ED3>ng ý   185    41.3 41.29%  
##  5 PSQT1 Ð<U+1ED3>ng ý   187    41.7 41.74%  
##  6 PSQT2 Ð<U+1ED3>ng ý   181    40.4 40.4%   
##  7 PSQT3 Ð<U+1ED3>ng ý   166    37.0 37.05%  
##  8 PSQT4 Ð<U+1ED3>ng ý   161    35.9 35.94%  
##  9 PSQC1 Ð<U+1ED3>ng ý   165    36.8 36.83%  
## 10 PSQC2 Ð<U+1ED3>ng ý   193    43.1 43.08%  
## # ... with 32 more rows
# For displaying percent of "Very Agree": 
df_odered %>% 
  filter(Res == "R\u1EA5t \u0111\u1ED3ng \u00FD") %>% 
  filter(percent >= 0) -> df_for_text7
df_for_text7
## # A tibble: 42 x 5
##    BPE   Res            n percent bar_text
##    <fct> <fct>      <int>   <dbl> <chr>   
##  1 PSB1  R<U+1EA5>t d<U+1ED3>ng ý    32    7.14 7.14%   
##  2 PSB2  R<U+1EA5>t d<U+1ED3>ng ý    32    7.14 7.14%   
##  3 PSB3  R<U+1EA5>t d<U+1ED3>ng ý    35    7.81 7.81%   
##  4 PSB4  R<U+1EA5>t d<U+1ED3>ng ý    33    7.37 7.37%   
##  5 PSQT1 R<U+1EA5>t d<U+1ED3>ng ý    32    7.14 7.14%   
##  6 PSQT2 R<U+1EA5>t d<U+1ED3>ng ý   130   29.0  29.02%  
##  7 PSQT3 R<U+1EA5>t d<U+1ED3>ng ý   111   24.8  24.78%  
##  8 PSQT4 R<U+1EA5>t d<U+1ED3>ng ý   106   23.7  23.66%  
##  9 PSQC1 R<U+1EA5>t d<U+1ED3>ng ý    93   20.8  20.76%  
## 10 PSQC2 R<U+1EA5>t d<U+1ED3>ng ý    61   13.6  13.62%  
## # ... with 32 more rows
# For displaying percent of "Very Agree": 
df_odered %>% 
  filter(Res == "R\u1EA5t \u0111\u1ED3ng \u00FD") -> df_for_text
df_for_text
## # A tibble: 42 x 5
##    BPE   Res            n percent bar_text
##    <fct> <fct>      <int>   <dbl> <chr>   
##  1 PSB1  R<U+1EA5>t d<U+1ED3>ng ý    32    7.14 7.14%   
##  2 PSB2  R<U+1EA5>t d<U+1ED3>ng ý    32    7.14 7.14%   
##  3 PSB3  R<U+1EA5>t d<U+1ED3>ng ý    35    7.81 7.81%   
##  4 PSB4  R<U+1EA5>t d<U+1ED3>ng ý    33    7.37 7.37%   
##  5 PSQT1 R<U+1EA5>t d<U+1ED3>ng ý    32    7.14 7.14%   
##  6 PSQT2 R<U+1EA5>t d<U+1ED3>ng ý   130   29.0  29.02%  
##  7 PSQT3 R<U+1EA5>t d<U+1ED3>ng ý   111   24.8  24.78%  
##  8 PSQT4 R<U+1EA5>t d<U+1ED3>ng ý   106   23.7  23.66%  
##  9 PSQC1 R<U+1EA5>t d<U+1ED3>ng ý    93   20.8  20.76%  
## 10 PSQC2 R<U+1EA5>t d<U+1ED3>ng ý    61   13.6  13.62%  
## # ... with 32 more rows
# Ad text layers-thay đổi giá trị y để thể hiện vị trí ghi text phù hợp
gg_viet + 
  geom_text(data = df_for_text1, aes(x = BPE, y = 4, label = bar_text), size = 4, color = "white", family = my_font) + 
  geom_text(data = df_for_text6, aes(x = BPE, y = 100-30, label = bar_text), size = 4, color = "white", family = my_font) +
  geom_text(data = df_for_text7, aes(x = BPE, y = 100-2, label = bar_text), size = 4, color = "white", family = my_font)
## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database
## Warning in grid.Call.graphics(C_text, as.graphicsAnnot(x$label), x$x, x$y, :
## font family not found in Windows font database
## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

3.8. Vẽ biểu đồ likert cho dữ liệu của 2 thành phố theo từng constructs 3.8.1. Construct PSB - Nhãn tiếng anh

# Plot Likert graph for people in both cities for construct PSQ
library(tidyverse)
library(compareGroups)
head(DN_HCM_SEM5_PSB)
##   Res  BPE
## 1   6 PSB1
## 2   3 PSB1
## 3   2 PSB1
## 4   5 PSB1
## 5   2 PSB1
## 6   2 PSB1
dim(DN_HCM_SEM5_PSB)
## [1] 3432    2
attach(DN_HCM_SEM5_PSB)
## The following objects are masked from HCM_SEM5:
## 
##     BPE, Res
## The following objects are masked from DN_SEM5:
## 
##     BPE, Res
## The following objects are masked from DN_HCM_SEM5:
## 
##     BPE, Res
DN_HCM_SEM5_PSB = within(DN_HCM_SEM5_PSB, {
  Res = factor(Res, labels = c("Very Disagree", "Disagree", "Quite Disagree", "Normal", "Quite Agree", "Agree", "Very Agree"))
  BPE = factor(BPE, labels = c("PSB1", "PSB2", "PSB3", "PSB4"))
  })
str(DN_HCM_SEM5_PSB)
## 'data.frame':    3432 obs. of  2 variables:
##  $ Res: Factor w/ 7 levels "Very Disagree",..: 6 3 2 5 2 2 1 6 2 4 ...
##  $ BPE: Factor w/ 4 levels "PSB1","PSB2",..: 1 1 1 1 1 1 1 1 1 1 ...
summary(DN_HCM_SEM5_PSB)
##              Res         BPE     
##  Very Disagree : 139   PSB1:858  
##  Disagree      : 295   PSB2:858  
##  Quite Disagree: 190   PSB3:858  
##  Normal        : 376   PSB4:858  
##  Quite Agree   : 562             
##  Agree         :1514             
##  Very Agree    : 356
    ## t <- compareGroups(Res ~ BPE, data = DN_SEM1)
    ## createTable(t)
DN_HCM_SEM5_PSB %>% 
  group_by(BPE, Res) %>% 
  count() %>% 
  ungroup() %>% 
  group_by(BPE) %>% 
  mutate(percent = 100*n / sum(n)) %>% 
  mutate(percent = round(percent, 2)) %>% 
  mutate(bar_text = paste0(percent, "%")) %>% 
  ungroup() -> df_for_ploting
df_for_ploting %>% 
  filter(Res == Res[7]) %>% 
  arrange(percent) %>% # sắp xếp theo %
  pull(BPE) -> order_x
order_x
## [1] PSB4 PSB1 PSB2 PSB3
## Levels: PSB1 PSB2 PSB3 PSB4
# Make a draft plot: 
my_colors <- c("#3e6487", "#829cb2", "pink", "pink3", "palevioletred", "rosybrown2", "rosybrown3")
my_font <- "Roboto Condensed"

df_for_ploting %>% 
  mutate(BPE = factor(BPE, levels = order_x), Res = factor(Res, levels = Res[7:1])) -> df_odered
df_odered
## # A tibble: 28 x 5
##    BPE   Res                n percent bar_text
##    <fct> <fct>          <int>   <dbl> <chr>   
##  1 PSB1  Very Disagree     57    6.64 6.64%   
##  2 PSB1  Disagree         130   15.2  15.15%  
##  3 PSB1  Quite Disagree    53    6.18 6.18%   
##  4 PSB1  Normal            80    9.32 9.32%   
##  5 PSB1  Quite Agree      127   14.8  14.8%   
##  6 PSB1  Agree            329   38.3  38.34%  
##  7 PSB1  Very Agree        82    9.56 9.56%   
##  8 PSB2  Very Disagree     35    4.08 4.08%   
##  9 PSB2  Disagree          65    7.58 7.58%   
## 10 PSB2  Quite Disagree    51    5.94 5.94%   
## # ... with 18 more rows
library(extrafont)
theme_set(theme_minimal())
gg <- df_odered %>% 
  ggplot(aes(x = BPE, y = percent, fill = Res)) + 
  geom_col(width = 0.8) + 
  coord_flip() + 
  scale_fill_manual(values = my_colors[7:1], name = "") + 
  theme(legend.position = "top") + 
  theme(text = element_text(family = my_font)) + 
  guides(fill = guide_legend(reverse = TRUE)) + 
  scale_y_continuous(labels = paste0(seq(0, 100, 25), "%"), expand = c(0, 0)) + 
  theme(plot.title = element_text(size = 18), plot.subtitle = element_text(size = 11, color = "grey20")) + 
  theme(axis.text = element_text(color = "grey20", size = 10.2)) + 
  theme(plot.margin = unit(rep(0.7, 4), "cm")) + 
  theme(panel.grid.major.y = element_blank(), panel.grid.minor.x = element_blank()) + 
  theme(legend.key.height = unit(0.15, "mm")) + 
  labs(x = NULL, y = NULL, 
       title = "Perceived Safety on Bus (PSQT) on bus of passengers in urban areas of Viet Nam", 
       subtitle = "Likert scale is a type of rating scale commonly used in surveys. When responding to a Likert type question,\nrespondents simply state their level of agreement or disagreement on a symmetric agree-disagree scale.")
gg
## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

# For displaying percent of "Very Disagree": Điều chỉnh percent để thể hiện giá trị của %
df_odered %>% 
  filter(Res == "Very Disagree") %>% 
  filter(percent >= 0) -> df_for_text1
df_for_text1
## # A tibble: 4 x 5
##   BPE   Res               n percent bar_text
##   <fct> <fct>         <int>   <dbl> <chr>   
## 1 PSB1  Very Disagree    57    6.64 6.64%   
## 2 PSB2  Very Disagree    35    4.08 4.08%   
## 3 PSB3  Very Disagree    15    1.75 1.75%   
## 4 PSB4  Very Disagree    32    3.73 3.73%
# For displaying percent of "Disagree": 
df_odered %>% 
  filter(Res == "Disagree") %>% 
  filter(percent >= 3) -> df_for_text2
df_for_text2
## # A tibble: 3 x 5
##   BPE   Res          n percent bar_text
##   <fct> <fct>    <int>   <dbl> <chr>   
## 1 PSB1  Disagree   130   15.2  15.15%  
## 2 PSB2  Disagree    65    7.58 7.58%   
## 3 PSB4  Disagree    78    9.09 9.09%
# For displaying percent of "Quite Disagree": 
df_odered %>% 
  filter(Res == "Quite Disagree") %>% 
  filter(percent >= 0) -> df_for_text3
df_for_text3
## # A tibble: 4 x 5
##   BPE   Res                n percent bar_text
##   <fct> <fct>          <int>   <dbl> <chr>   
## 1 PSB1  Quite Disagree    53    6.18 6.18%   
## 2 PSB2  Quite Disagree    51    5.94 5.94%   
## 3 PSB3  Quite Disagree    30    3.5  3.5%    
## 4 PSB4  Quite Disagree    56    6.53 6.53%
# For displaying percent of "Normal": 
df_odered %>% 
  filter(Res == "Normal") %>% 
  filter(percent >= 0) -> df_for_text4
df_for_text4
## # A tibble: 4 x 5
##   BPE   Res        n percent bar_text
##   <fct> <fct>  <int>   <dbl> <chr>   
## 1 PSB1  Normal    80    9.32 9.32%   
## 2 PSB2  Normal    85    9.91 9.91%   
## 3 PSB3  Normal    66    7.69 7.69%   
## 4 PSB4  Normal   145   16.9  16.9%
# For displaying percent of "Quite Agree": 
df_odered %>% 
  filter(Res == "Quite Agree") %>% 
  filter(percent >= 0) -> df_for_text5
df_for_text5
## # A tibble: 4 x 5
##   BPE   Res             n percent bar_text
##   <fct> <fct>       <int>   <dbl> <chr>   
## 1 PSB1  Quite Agree   127    14.8 14.8%   
## 2 PSB2  Quite Agree   126    14.7 14.69%  
## 3 PSB3  Quite Agree   148    17.2 17.25%  
## 4 PSB4  Quite Agree   161    18.8 18.76%
# For displaying percent of "Agree": 
df_odered %>% 
  filter(Res == "Agree") %>% 
  filter(percent >= 0) -> df_for_text6
df_for_text6
## # A tibble: 4 x 5
##   BPE   Res       n percent bar_text
##   <fct> <fct> <int>   <dbl> <chr>   
## 1 PSB1  Agree   329    38.3 38.34%  
## 2 PSB2  Agree   402    46.8 46.85%  
## 3 PSB3  Agree   474    55.2 55.24%  
## 4 PSB4  Agree   309    36.0 36.01%
# For displaying percent of "Very Agree": 
df_odered %>% 
  filter(Res == "Very Agree") %>% 
  filter(percent >= 0) -> df_for_text7 # Chỉ thể hiện giá trị có % lựa chọn >0
df_for_text7
## # A tibble: 4 x 5
##   BPE   Res            n percent bar_text
##   <fct> <fct>      <int>   <dbl> <chr>   
## 1 PSB1  Very Agree    82    9.56 9.56%   
## 2 PSB2  Very Agree    94   11.0  10.96%  
## 3 PSB3  Very Agree   103   12    12%     
## 4 PSB4  Very Agree    77    8.97 8.97%
# For displaying percent of "Very Agree": 
df_odered %>% 
  filter(Res == "Very Agree") -> df_for_text
df_for_text
## # A tibble: 4 x 5
##   BPE   Res            n percent bar_text
##   <fct> <fct>      <int>   <dbl> <chr>   
## 1 PSB1  Very Agree    82    9.56 9.56%   
## 2 PSB2  Very Agree    94   11.0  10.96%  
## 3 PSB3  Very Agree   103   12    12%     
## 4 PSB4  Very Agree    77    8.97 8.97%
# Ad text layers-thay đổi giá trị y để thể hiện vị trí ghi text phù hợp
gg + 
  geom_text(data = df_for_text1, aes(x = BPE, y = 2, label = bar_text), size = 4, color = "white", family = my_font) + 
  geom_text(data = df_for_text6, aes(x = BPE, y = 100-30, label = bar_text), size = 4, color = "white", family = my_font) +
  geom_text(data = df_for_text7, aes(x = BPE, y = 100-2, label = bar_text), size = 4, color = "white", family = my_font)
## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database
## Warning in grid.Call.graphics(C_text, as.graphicsAnnot(x$label), x$x, x$y, :
## font family not found in Windows font database
## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

3.8.2. Construct PSB - Nhãn tiếng việt

DN_HCM_SEM5_PSB_v = within(DN_HCM_SEM5_PSB, {
  Res = factor(Res, labels = c("R\u1EA5t kh\u00F4ng \u0111\u1ED3ng \u00FD", "Kh\u00F4ng \u0111\u1ED3ng \u00FD", "Kh\u00E1 kh\u00F4ng \u0111\u1ED3ng \u00FD", "B\u00ECnh th\u01B0\u1EDDng", "Kh\u00E1 \u0111\u1ED3ng \u00FD", "\u0110\u1ED3ng \u00FD", "R\u1EA5t \u0111\u1ED3ng \u00FD"))
  BPE = factor(BPE, labels = c("PSB1", "PSB2", "PSB3", "PSB4"))
  })
str(DN_HCM_SEM5_PSB_v)
## 'data.frame':    3432 obs. of  2 variables:
##  $ Res: Factor w/ 7 levels "R<U+1EA5>t không d<U+1ED3>ng ý",..: 6 3 2 5 2 2 1 6 2 4 ...
##  $ BPE: Factor w/ 4 levels "PSB1","PSB2",..: 1 1 1 1 1 1 1 1 1 1 ...
summary(DN_HCM_SEM5_PSB_v)
##                              Res         BPE     
##  R<U+1EA5>t không d<U+1ED3>ng ý: 139   PSB1:858  
##  Không d<U+1ED3>ng ý           : 295   PSB2:858  
##  Khá không d<U+1ED3>ng ý       : 190   PSB3:858  
##  Bình thu<U+1EDD>ng            : 376   PSB4:858  
##  Khá d<U+1ED3>ng ý             : 562             
##  Ð<U+1ED3>ng ý                 :1514             
##  R<U+1EA5>t d<U+1ED3>ng ý      : 356
    ## t <- compareGroups(Res ~ BPE, data = DN_SEM1)
    ## createTable(t)
DN_HCM_SEM5_PSB_v %>% 
  group_by(BPE, Res) %>% 
  count() %>% 
  ungroup() %>% 
  group_by(BPE) %>% 
  mutate(percent = 100*n / sum(n)) %>% 
  mutate(percent = round(percent, 2)) %>% 
  mutate(bar_text = paste0(percent, "%")) %>% 
  ungroup() -> df_for_ploting
df_for_ploting %>% 
  filter(Res == Res[7]) %>% 
  arrange(percent) %>% # sắp xếp theo %
  pull(BPE) -> order_x
order_x
## [1] PSB4 PSB1 PSB2 PSB3
## Levels: PSB1 PSB2 PSB3 PSB4
# Make a draft plot: 
my_colors <- c("#3e6487", "#829cb2", "pink", "pink3", "palevioletred", "rosybrown2", "rosybrown3")
my_font <- "Roboto Condensed"

df_for_ploting %>% 
  mutate(BPE = factor(BPE, levels = order_x), Res = factor(Res, levels = Res[7:1])) -> df_odered
df_odered
## # A tibble: 28 x 5
##    BPE   Res                  n percent bar_text
##    <fct> <fct>            <int>   <dbl> <chr>   
##  1 PSB1  R<U+1EA5>t không d<U+1ED3>ng ý    57    6.64 6.64%   
##  2 PSB1  Không d<U+1ED3>ng ý       130   15.2  15.15%  
##  3 PSB1  Khá không d<U+1ED3>ng ý    53    6.18 6.18%   
##  4 PSB1  Bình thu<U+1EDD>ng         80    9.32 9.32%   
##  5 PSB1  Khá d<U+1ED3>ng ý         127   14.8  14.8%   
##  6 PSB1  Ð<U+1ED3>ng ý             329   38.3  38.34%  
##  7 PSB1  R<U+1EA5>t d<U+1ED3>ng ý          82    9.56 9.56%   
##  8 PSB2  R<U+1EA5>t không d<U+1ED3>ng ý    35    4.08 4.08%   
##  9 PSB2  Không d<U+1ED3>ng ý        65    7.58 7.58%   
## 10 PSB2  Khá không d<U+1ED3>ng ý    51    5.94 5.94%   
## # ... with 18 more rows
library(extrafont)
theme_set(theme_minimal())
gg_v <- df_odered %>% 
  ggplot(aes(x = BPE, y = percent, fill = Res)) + 
  geom_col(width = 0.8) + 
  coord_flip() + 
  scale_fill_manual(values = my_colors[7:1], name = "") + 
  theme(legend.position = "top") + 
  theme(text = element_text(family = my_font)) + 
  guides(fill = guide_legend(reverse = TRUE)) + 
  scale_y_continuous(labels = paste0(seq(0, 100, 25), "%"), expand = c(0, 0)) + 
  theme(plot.title = element_text(size = 18), plot.subtitle = element_text(size = 11, color = "grey20")) + 
  theme(axis.text = element_text(color = "grey20", size = 10.2)) + 
  theme(plot.margin = unit(rep(0.7, 4), "cm")) + 
  theme(panel.grid.major.y = element_blank(), panel.grid.minor.x = element_blank()) + 
  theme(legend.key.height = unit(0.15, "mm")) + 
  labs(x = NULL, y = NULL, 
       title = "C\u1EA3m nh\u1EADn c\u1EE7a h\u00E0nh kh\u00E1ch v\u1EC1 an to\u00E0n tr\u00EAn xe (PSB) \u0111\u1ED1i v\u1EDBi h\u1EC7 th\u1ED1ng xe bu\u00FDt \u0111\u00F4 th\u1ECB Vi\u1EC7t Nam", 
       subtitle = "Thang \u0111o Likert l\u00E0 lo\u1EA1i thang \u0111o \u0111i\u1EC3m \u0111\u00E1nh gi\u00E1 \u0111\u01B0\u1EE3c s\u1EED d\u1EE5ng ph\u1ED5 bi\u1EBFn trong kh\u1EA3o s\u00E1t. Nghi\u00EAn c\u1EE9u s\u1EED d\u1EE5ng thang \u0111o 7 m\u1EE9c \u0111\u1ED9 t\u01B0\u01A1ng \u1EE9ng v\u1EDBi 1 - R\u1EA5t kh\u00F4ng \u0111\u1ED3ng \u00FD \u0111\u1EBFn 7 - R\u1EA5t \u0111\u1ED3ng \u00FD.")
gg_v
## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

# For displaying percent of "Very Disagree": Điều chỉnh percent để thể hiện giá trị của %
df_odered %>% 
  filter(Res == "R\u1EA5t kh\u00F4ng \u0111\u1ED3ng \u00FD") %>% 
  filter(percent >= 0) -> df_for_text1
df_for_text1
## # A tibble: 4 x 5
##   BPE   Res                  n percent bar_text
##   <fct> <fct>            <int>   <dbl> <chr>   
## 1 PSB1  R<U+1EA5>t không d<U+1ED3>ng ý    57    6.64 6.64%   
## 2 PSB2  R<U+1EA5>t không d<U+1ED3>ng ý    35    4.08 4.08%   
## 3 PSB3  R<U+1EA5>t không d<U+1ED3>ng ý    15    1.75 1.75%   
## 4 PSB4  R<U+1EA5>t không d<U+1ED3>ng ý    32    3.73 3.73%
# For displaying percent of "Disagree": 
df_odered %>% 
  filter(Res == "Kh\u00F4ng \u0111\u1ED3ng \u00FD") %>% 
  filter(percent >= 0) -> df_for_text2
df_for_text2
## # A tibble: 4 x 5
##   BPE   Res              n percent bar_text
##   <fct> <fct>        <int>   <dbl> <chr>   
## 1 PSB1  Không d<U+1ED3>ng ý   130   15.2  15.15%  
## 2 PSB2  Không d<U+1ED3>ng ý    65    7.58 7.58%   
## 3 PSB3  Không d<U+1ED3>ng ý    22    2.56 2.56%   
## 4 PSB4  Không d<U+1ED3>ng ý    78    9.09 9.09%
# For displaying percent of "Quite Disagree": 
df_odered %>% 
  filter(Res == "Kh\u00E1 kh\u00F4ng \u0111\u1ED3ng \u00FD") %>% 
  filter(percent >= 0) -> df_for_text3
df_for_text3
## # A tibble: 4 x 5
##   BPE   Res                  n percent bar_text
##   <fct> <fct>            <int>   <dbl> <chr>   
## 1 PSB1  Khá không d<U+1ED3>ng ý    53    6.18 6.18%   
## 2 PSB2  Khá không d<U+1ED3>ng ý    51    5.94 5.94%   
## 3 PSB3  Khá không d<U+1ED3>ng ý    30    3.5  3.5%    
## 4 PSB4  Khá không d<U+1ED3>ng ý    56    6.53 6.53%
# For displaying percent of "Normal": 
df_odered %>% 
  filter(Res == "B\u00ECnh th\u01B0\u1EDDng") %>% 
  filter(percent >= 0) -> df_for_text4
df_for_text4
## # A tibble: 4 x 5
##   BPE   Res             n percent bar_text
##   <fct> <fct>       <int>   <dbl> <chr>   
## 1 PSB1  Bình thu<U+1EDD>ng    80    9.32 9.32%   
## 2 PSB2  Bình thu<U+1EDD>ng    85    9.91 9.91%   
## 3 PSB3  Bình thu<U+1EDD>ng    66    7.69 7.69%   
## 4 PSB4  Bình thu<U+1EDD>ng   145   16.9  16.9%
# For displaying percent of "Quite Agree": 
df_odered %>% 
  filter(Res == "Kh\u00E1 \u0111\u1ED3ng \u00FD") %>% 
  filter(percent >= 0) -> df_for_text5
df_for_text5
## # A tibble: 4 x 5
##   BPE   Res            n percent bar_text
##   <fct> <fct>      <int>   <dbl> <chr>   
## 1 PSB1  Khá d<U+1ED3>ng ý   127    14.8 14.8%   
## 2 PSB2  Khá d<U+1ED3>ng ý   126    14.7 14.69%  
## 3 PSB3  Khá d<U+1ED3>ng ý   148    17.2 17.25%  
## 4 PSB4  Khá d<U+1ED3>ng ý   161    18.8 18.76%
# For displaying percent of "Agree": 
df_odered %>% 
  filter(Res == "\u0110\u1ED3ng \u00FD") %>% 
  filter(percent >= 0) -> df_for_text6
df_for_text6
## # A tibble: 4 x 5
##   BPE   Res        n percent bar_text
##   <fct> <fct>  <int>   <dbl> <chr>   
## 1 PSB1  Ð<U+1ED3>ng ý   329    38.3 38.34%  
## 2 PSB2  Ð<U+1ED3>ng ý   402    46.8 46.85%  
## 3 PSB3  Ð<U+1ED3>ng ý   474    55.2 55.24%  
## 4 PSB4  Ð<U+1ED3>ng ý   309    36.0 36.01%
# For displaying percent of "Very Agree": 
df_odered %>% 
  filter(Res == "R\u1EA5t \u0111\u1ED3ng \u00FD") %>% 
  filter(percent >= 0) -> df_for_text7
df_for_text7
## # A tibble: 4 x 5
##   BPE   Res            n percent bar_text
##   <fct> <fct>      <int>   <dbl> <chr>   
## 1 PSB1  R<U+1EA5>t d<U+1ED3>ng ý    82    9.56 9.56%   
## 2 PSB2  R<U+1EA5>t d<U+1ED3>ng ý    94   11.0  10.96%  
## 3 PSB3  R<U+1EA5>t d<U+1ED3>ng ý   103   12    12%     
## 4 PSB4  R<U+1EA5>t d<U+1ED3>ng ý    77    8.97 8.97%
# For displaying percent of "Very Agree": 
df_odered %>% 
  filter(Res == "R\u1EA5t \u0111\u1ED3ng \u00FD") -> df_for_text
df_for_text
## # A tibble: 4 x 5
##   BPE   Res            n percent bar_text
##   <fct> <fct>      <int>   <dbl> <chr>   
## 1 PSB1  R<U+1EA5>t d<U+1ED3>ng ý    82    9.56 9.56%   
## 2 PSB2  R<U+1EA5>t d<U+1ED3>ng ý    94   11.0  10.96%  
## 3 PSB3  R<U+1EA5>t d<U+1ED3>ng ý   103   12    12%     
## 4 PSB4  R<U+1EA5>t d<U+1ED3>ng ý    77    8.97 8.97%
# Ad text layers-thay đổi giá trị y để thể hiện vị trí ghi text phù hợp
gg_v + 
  geom_text(data = df_for_text1, aes(x = BPE, y = 2, label = bar_text), size = 4, color = "white", family = my_font) + 
  geom_text(data = df_for_text6, aes(x = BPE, y = 100-30, label = bar_text), size = 4, color = "white", family = my_font) +
  geom_text(data = df_for_text7, aes(x = BPE, y = 100-2, label = bar_text), size = 4, color = "white", family = my_font)
## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database
## Warning in grid.Call.graphics(C_text, as.graphicsAnnot(x$label), x$x, x$y, :
## font family not found in Windows font database
## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

3.8.3. Construct PSQT - Nhãn tiếng anh

# Plot Likert graph for people in both cities for construct PSQ
library(tidyverse)
library(compareGroups)
head(DN_HCM_SEM5_PSQT)
##   Res   BPE
## 1   6 PSQT1
## 2   4 PSQT1
## 3   2 PSQT1
## 4   6 PSQT1
## 5   6 PSQT1
## 6   4 PSQT1
dim(DN_HCM_SEM5_PSQT)
## [1] 3432    2
attach(DN_HCM_SEM5_PSQT)
## The following objects are masked from DN_HCM_SEM5_PSB:
## 
##     BPE, Res
## The following objects are masked from HCM_SEM5:
## 
##     BPE, Res
## The following objects are masked from DN_SEM5:
## 
##     BPE, Res
## The following objects are masked from DN_HCM_SEM5:
## 
##     BPE, Res
DN_HCM_SEM5_PSQT = within(DN_HCM_SEM5_PSQT, {
  Res = factor(Res, labels = c("Very Disagree", "Disagree", "Quite Disagree", "Normal", "Quite Agree", "Agree", "Very Agree"))
  BPE = factor(BPE, labels = c("PSQT1", "PSQT2", "PSQT3", "PSQT4"))
  })
str(DN_HCM_SEM5_PSQT)
## 'data.frame':    3432 obs. of  2 variables:
##  $ Res: Factor w/ 7 levels "Very Disagree",..: 6 4 2 6 6 4 2 5 5 7 ...
##  $ BPE: Factor w/ 4 levels "PSQT1","PSQT2",..: 1 1 1 1 1 1 1 1 1 1 ...
summary(DN_HCM_SEM5_PSQT)
##              Res          BPE     
##  Very Disagree :  76   PSQT1:858  
##  Disagree      : 166   PSQT2:858  
##  Quite Disagree: 169   PSQT3:858  
##  Normal        : 341   PSQT4:858  
##  Quite Agree   : 740              
##  Agree         :1431              
##  Very Agree    : 509
    ## t <- compareGroups(Res ~ BPE, data = DN_SEM1)
    ## createTable(t)
DN_HCM_SEM5_PSQT %>% 
  group_by(BPE, Res) %>% 
  count() %>% 
  ungroup() %>% 
  group_by(BPE) %>% 
  mutate(percent = 100*n / sum(n)) %>% 
  mutate(percent = round(percent, 2)) %>% 
  mutate(bar_text = paste0(percent, "%")) %>% 
  ungroup() -> df_for_ploting
df_for_ploting %>% 
  filter(Res == Res[7]) %>% 
  arrange(percent) %>% # sắp xếp theo %
  pull(BPE) -> order_x
order_x
## [1] PSQT4 PSQT1 PSQT3 PSQT2
## Levels: PSQT1 PSQT2 PSQT3 PSQT4
# Make a draft plot: 
my_colors <- c("#3e6487", "#829cb2", "pink", "pink3", "palevioletred", "rosybrown2", "rosybrown3")
my_font <- "Roboto Condensed"

df_for_ploting %>% 
  mutate(BPE = factor(BPE, levels = order_x), Res = factor(Res, levels = Res[7:1])) -> df_odered
df_odered
## # A tibble: 28 x 5
##    BPE   Res                n percent bar_text
##    <fct> <fct>          <int>   <dbl> <chr>   
##  1 PSQT1 Very Disagree     12    1.4  1.4%    
##  2 PSQT1 Disagree          33    3.85 3.85%   
##  3 PSQT1 Quite Disagree    38    4.43 4.43%   
##  4 PSQT1 Normal            92   10.7  10.72%  
##  5 PSQT1 Quite Agree      194   22.6  22.61%  
##  6 PSQT1 Agree            362   42.2  42.19%  
##  7 PSQT1 Very Agree       127   14.8  14.8%   
##  8 PSQT2 Very Disagree     18    2.1  2.1%    
##  9 PSQT2 Disagree          45    5.24 5.24%   
## 10 PSQT2 Quite Disagree    32    3.73 3.73%   
## # ... with 18 more rows
library(extrafont)
theme_set(theme_minimal())
gg <- df_odered %>% 
  ggplot(aes(x = BPE, y = percent, fill = Res)) + 
  geom_col(width = 0.8) + 
  coord_flip() + 
  scale_fill_manual(values = my_colors[7:1], name = "") + 
  theme(legend.position = "top") + 
  theme(text = element_text(family = my_font)) + 
  guides(fill = guide_legend(reverse = TRUE)) + 
  scale_y_continuous(labels = paste0(seq(0, 100, 25), "%"), expand = c(0, 0)) + 
  theme(plot.title = element_text(size = 18), plot.subtitle = element_text(size = 11, color = "grey20")) + 
  theme(axis.text = element_text(color = "grey20", size = 10.2)) + 
  theme(plot.margin = unit(rep(0.7, 4), "cm")) + 
  theme(panel.grid.major.y = element_blank(), panel.grid.minor.x = element_blank()) + 
  theme(legend.key.height = unit(0.15, "mm")) + 
  labs(x = NULL, y = NULL, 
       title = "Perceived Service Quality of tangibility (PSQT) on bus of passengers in urban areas of Viet Nam", 
       subtitle = "Likert scale is a type of rating scale commonly used in surveys. When responding to a Likert type question,\nrespondents simply state their level of agreement or disagreement on a symmetric agree-disagree scale.")
gg
## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

# For displaying percent of "Very Disagree": Điều chỉnh percent để thể hiện giá trị của %
df_odered %>% 
  filter(Res == "Very Disagree") %>% 
  filter(percent >= 0) -> df_for_text1
df_for_text1
## # A tibble: 4 x 5
##   BPE   Res               n percent bar_text
##   <fct> <fct>         <int>   <dbl> <chr>   
## 1 PSQT1 Very Disagree    12    1.4  1.4%    
## 2 PSQT2 Very Disagree    18    2.1  2.1%    
## 3 PSQT3 Very Disagree    30    3.5  3.5%    
## 4 PSQT4 Very Disagree    16    1.86 1.86%
# For displaying percent of "Disagree": 
df_odered %>% 
  filter(Res == "Disagree") %>% 
  filter(percent >= 3) -> df_for_text2
df_for_text2
## # A tibble: 4 x 5
##   BPE   Res          n percent bar_text
##   <fct> <fct>    <int>   <dbl> <chr>   
## 1 PSQT1 Disagree    33    3.85 3.85%   
## 2 PSQT2 Disagree    45    5.24 5.24%   
## 3 PSQT3 Disagree    45    5.24 5.24%   
## 4 PSQT4 Disagree    43    5.01 5.01%
# For displaying percent of "Quite Disagree": 
df_odered %>% 
  filter(Res == "Quite Disagree") %>% 
  filter(percent >= 0) -> df_for_text3
df_for_text3
## # A tibble: 4 x 5
##   BPE   Res                n percent bar_text
##   <fct> <fct>          <int>   <dbl> <chr>   
## 1 PSQT1 Quite Disagree    38    4.43 4.43%   
## 2 PSQT2 Quite Disagree    32    3.73 3.73%   
## 3 PSQT3 Quite Disagree    50    5.83 5.83%   
## 4 PSQT4 Quite Disagree    49    5.71 5.71%
# For displaying percent of "Normal": 
df_odered %>% 
  filter(Res == "Normal") %>% 
  filter(percent >= 0) -> df_for_text4
df_for_text4
## # A tibble: 4 x 5
##   BPE   Res        n percent bar_text
##   <fct> <fct>  <int>   <dbl> <chr>   
## 1 PSQT1 Normal    92   10.7  10.72%  
## 2 PSQT2 Normal    85    9.91 9.91%   
## 3 PSQT3 Normal    76    8.86 8.86%   
## 4 PSQT4 Normal    88   10.3  10.26%
# For displaying percent of "Quite Agree": 
df_odered %>% 
  filter(Res == "Quite Agree") %>% 
  filter(percent >= 0) -> df_for_text5
df_for_text5
## # A tibble: 4 x 5
##   BPE   Res             n percent bar_text
##   <fct> <fct>       <int>   <dbl> <chr>   
## 1 PSQT1 Quite Agree   194    22.6 22.61%  
## 2 PSQT2 Quite Agree   143    16.7 16.67%  
## 3 PSQT3 Quite Agree   180    21.0 20.98%  
## 4 PSQT4 Quite Agree   223    26.0 25.99%
# For displaying percent of "Agree": 
df_odered %>% 
  filter(Res == "Agree") %>% 
  filter(percent >= 0) -> df_for_text6
df_for_text6
## # A tibble: 4 x 5
##   BPE   Res       n percent bar_text
##   <fct> <fct> <int>   <dbl> <chr>   
## 1 PSQT1 Agree   362    42.2 42.19%  
## 2 PSQT2 Agree   378    44.1 44.06%  
## 3 PSQT3 Agree   349    40.7 40.68%  
## 4 PSQT4 Agree   342    39.9 39.86%
# For displaying percent of "Very Agree": 
df_odered %>% 
  filter(Res == "Very Agree") %>% 
  filter(percent >= 0) -> df_for_text7 # Chỉ thể hiện giá trị có % lựa chọn >0
df_for_text7
## # A tibble: 4 x 5
##   BPE   Res            n percent bar_text
##   <fct> <fct>      <int>   <dbl> <chr>   
## 1 PSQT1 Very Agree   127    14.8 14.8%   
## 2 PSQT2 Very Agree   157    18.3 18.3%   
## 3 PSQT3 Very Agree   128    14.9 14.92%  
## 4 PSQT4 Very Agree    97    11.3 11.31%
# For displaying percent of "Very Agree": 
df_odered %>% 
  filter(Res == "Very Agree") -> df_for_text
df_for_text
## # A tibble: 4 x 5
##   BPE   Res            n percent bar_text
##   <fct> <fct>      <int>   <dbl> <chr>   
## 1 PSQT1 Very Agree   127    14.8 14.8%   
## 2 PSQT2 Very Agree   157    18.3 18.3%   
## 3 PSQT3 Very Agree   128    14.9 14.92%  
## 4 PSQT4 Very Agree    97    11.3 11.31%
# Ad text layers-thay đổi giá trị y để thể hiện vị trí ghi text phù hợp
gg + 
  geom_text(data = df_for_text1, aes(x = BPE, y = 2, label = bar_text), size = 4, color = "white", family = my_font) + 
  geom_text(data = df_for_text6, aes(x = BPE, y = 100-30, label = bar_text), size = 4, color = "white", family = my_font) +
  geom_text(data = df_for_text7, aes(x = BPE, y = 100-2, label = bar_text), size = 4, color = "white", family = my_font)
## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database
## Warning in grid.Call.graphics(C_text, as.graphicsAnnot(x$label), x$x, x$y, :
## font family not found in Windows font database
## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

3.8.4. Construct PSQT - Nhãn tiếng việt

DN_HCM_SEM5_PSQT_v = within(DN_HCM_SEM5_PSQT, {
  Res = factor(Res, labels = c("R\u1EA5t kh\u00F4ng \u0111\u1ED3ng \u00FD", "Kh\u00F4ng \u0111\u1ED3ng \u00FD", "Kh\u00E1 kh\u00F4ng \u0111\u1ED3ng \u00FD", "B\u00ECnh th\u01B0\u1EDDng", "Kh\u00E1 \u0111\u1ED3ng \u00FD", "\u0110\u1ED3ng \u00FD", "R\u1EA5t \u0111\u1ED3ng \u00FD"))
  BPE = factor(BPE, labels = c("PSQT1", "PSQT2", "PSQT3", "PSQT4"))
  })
str(DN_HCM_SEM5_PSQT_v)
## 'data.frame':    3432 obs. of  2 variables:
##  $ Res: Factor w/ 7 levels "R<U+1EA5>t không d<U+1ED3>ng ý",..: 6 4 2 6 6 4 2 5 5 7 ...
##  $ BPE: Factor w/ 4 levels "PSQT1","PSQT2",..: 1 1 1 1 1 1 1 1 1 1 ...
summary(DN_HCM_SEM5_PSQT_v)
##                              Res          BPE     
##  R<U+1EA5>t không d<U+1ED3>ng ý:  76   PSQT1:858  
##  Không d<U+1ED3>ng ý           : 166   PSQT2:858  
##  Khá không d<U+1ED3>ng ý       : 169   PSQT3:858  
##  Bình thu<U+1EDD>ng            : 341   PSQT4:858  
##  Khá d<U+1ED3>ng ý             : 740              
##  Ð<U+1ED3>ng ý                 :1431              
##  R<U+1EA5>t d<U+1ED3>ng ý      : 509
    ## t <- compareGroups(Res ~ BPE, data = DN_SEM1)
    ## createTable(t)
DN_HCM_SEM5_PSQT_v %>% 
  group_by(BPE, Res) %>% 
  count() %>% 
  ungroup() %>% 
  group_by(BPE) %>% 
  mutate(percent = 100*n / sum(n)) %>% 
  mutate(percent = round(percent, 2)) %>% 
  mutate(bar_text = paste0(percent, "%")) %>% 
  ungroup() -> df_for_ploting
df_for_ploting %>% 
  filter(Res == Res[7]) %>% 
  arrange(percent) %>% # sắp xếp theo %
  pull(BPE) -> order_x
order_x
## [1] PSQT4 PSQT1 PSQT3 PSQT2
## Levels: PSQT1 PSQT2 PSQT3 PSQT4
# Make a draft plot: 
my_colors <- c("#3e6487", "#829cb2", "pink", "pink3", "palevioletred", "rosybrown2", "rosybrown3")
my_font <- "Roboto Condensed"

df_for_ploting %>% 
  mutate(BPE = factor(BPE, levels = order_x), Res = factor(Res, levels = Res[7:1])) -> df_odered
df_odered
## # A tibble: 28 x 5
##    BPE   Res                  n percent bar_text
##    <fct> <fct>            <int>   <dbl> <chr>   
##  1 PSQT1 R<U+1EA5>t không d<U+1ED3>ng ý    12    1.4  1.4%    
##  2 PSQT1 Không d<U+1ED3>ng ý        33    3.85 3.85%   
##  3 PSQT1 Khá không d<U+1ED3>ng ý    38    4.43 4.43%   
##  4 PSQT1 Bình thu<U+1EDD>ng         92   10.7  10.72%  
##  5 PSQT1 Khá d<U+1ED3>ng ý         194   22.6  22.61%  
##  6 PSQT1 Ð<U+1ED3>ng ý             362   42.2  42.19%  
##  7 PSQT1 R<U+1EA5>t d<U+1ED3>ng ý         127   14.8  14.8%   
##  8 PSQT2 R<U+1EA5>t không d<U+1ED3>ng ý    18    2.1  2.1%    
##  9 PSQT2 Không d<U+1ED3>ng ý        45    5.24 5.24%   
## 10 PSQT2 Khá không d<U+1ED3>ng ý    32    3.73 3.73%   
## # ... with 18 more rows
library(extrafont)
theme_set(theme_minimal())
gg_v <- df_odered %>% 
  ggplot(aes(x = BPE, y = percent, fill = Res)) + 
  geom_col(width = 0.8) + 
  coord_flip() + 
  scale_fill_manual(values = my_colors[7:1], name = "") + 
  theme(legend.position = "top") + 
  theme(text = element_text(family = my_font)) + 
  guides(fill = guide_legend(reverse = TRUE)) + 
  scale_y_continuous(labels = paste0(seq(0, 100, 25), "%"), expand = c(0, 0)) + 
  theme(plot.title = element_text(size = 18), plot.subtitle = element_text(size = 11, color = "grey20")) + 
  theme(axis.text = element_text(color = "grey20", size = 10.2)) + 
  theme(plot.margin = unit(rep(0.7, 4), "cm")) + 
  theme(panel.grid.major.y = element_blank(), panel.grid.minor.x = element_blank()) + 
  theme(legend.key.height = unit(0.15, "mm")) + 
  labs(x = NULL, y = NULL, 
       title = "C\u1EA3m nh\u1EADn c\u1EE7a h\u00E0nh kh\u00E1ch v\u1EC1 ch\u1EA5t l\u01B0\u1EE3ng d\u1ECBch v\u1EE5 h\u1EEFu h\u00ECnh (PSQT) \u0111\u1ED1i v\u1EDBi h\u1EC7 th\u1ED1ng xe bu\u00FDt \u0111\u00F4 th\u1ECB Vi\u1EC7t Nam", 
       subtitle = "Thang \u0111o Likert l\u00E0 lo\u1EA1i thang \u0111o \u0111i\u1EC3m \u0111\u00E1nh gi\u00E1 \u0111\u01B0\u1EE3c s\u1EED d\u1EE5ng ph\u1ED5 bi\u1EBFn trong kh\u1EA3o s\u00E1t. Nghi\u00EAn c\u1EE9u s\u1EED d\u1EE5ng thang \u0111o 7 m\u1EE9c \u0111\u1ED9 t\u01B0\u01A1ng \u1EE9ng v\u1EDBi 1 - R\u1EA5t kh\u00F4ng \u0111\u1ED3ng \u00FD \u0111\u1EBFn 7 - R\u1EA5t \u0111\u1ED3ng \u00FD.")
gg_v
## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

# For displaying percent of "Very Disagree": Điều chỉnh percent để thể hiện giá trị của %
df_odered %>% 
  filter(Res == "R\u1EA5t kh\u00F4ng \u0111\u1ED3ng \u00FD") %>% 
  filter(percent >= 0) -> df_for_text1
df_for_text1
## # A tibble: 4 x 5
##   BPE   Res                  n percent bar_text
##   <fct> <fct>            <int>   <dbl> <chr>   
## 1 PSQT1 R<U+1EA5>t không d<U+1ED3>ng ý    12    1.4  1.4%    
## 2 PSQT2 R<U+1EA5>t không d<U+1ED3>ng ý    18    2.1  2.1%    
## 3 PSQT3 R<U+1EA5>t không d<U+1ED3>ng ý    30    3.5  3.5%    
## 4 PSQT4 R<U+1EA5>t không d<U+1ED3>ng ý    16    1.86 1.86%
# For displaying percent of "Disagree": 
df_odered %>% 
  filter(Res == "Kh\u00F4ng \u0111\u1ED3ng \u00FD") %>% 
  filter(percent >= 0) -> df_for_text2
df_for_text2
## # A tibble: 4 x 5
##   BPE   Res              n percent bar_text
##   <fct> <fct>        <int>   <dbl> <chr>   
## 1 PSQT1 Không d<U+1ED3>ng ý    33    3.85 3.85%   
## 2 PSQT2 Không d<U+1ED3>ng ý    45    5.24 5.24%   
## 3 PSQT3 Không d<U+1ED3>ng ý    45    5.24 5.24%   
## 4 PSQT4 Không d<U+1ED3>ng ý    43    5.01 5.01%
# For displaying percent of "Quite Disagree": 
df_odered %>% 
  filter(Res == "Kh\u00E1 kh\u00F4ng \u0111\u1ED3ng \u00FD") %>% 
  filter(percent >= 0) -> df_for_text3
df_for_text3
## # A tibble: 4 x 5
##   BPE   Res                  n percent bar_text
##   <fct> <fct>            <int>   <dbl> <chr>   
## 1 PSQT1 Khá không d<U+1ED3>ng ý    38    4.43 4.43%   
## 2 PSQT2 Khá không d<U+1ED3>ng ý    32    3.73 3.73%   
## 3 PSQT3 Khá không d<U+1ED3>ng ý    50    5.83 5.83%   
## 4 PSQT4 Khá không d<U+1ED3>ng ý    49    5.71 5.71%
# For displaying percent of "Normal": 
df_odered %>% 
  filter(Res == "B\u00ECnh th\u01B0\u1EDDng") %>% 
  filter(percent >= 0) -> df_for_text4
df_for_text4
## # A tibble: 4 x 5
##   BPE   Res             n percent bar_text
##   <fct> <fct>       <int>   <dbl> <chr>   
## 1 PSQT1 Bình thu<U+1EDD>ng    92   10.7  10.72%  
## 2 PSQT2 Bình thu<U+1EDD>ng    85    9.91 9.91%   
## 3 PSQT3 Bình thu<U+1EDD>ng    76    8.86 8.86%   
## 4 PSQT4 Bình thu<U+1EDD>ng    88   10.3  10.26%
# For displaying percent of "Quite Agree": 
df_odered %>% 
  filter(Res == "Kh\u00E1 \u0111\u1ED3ng \u00FD") %>% 
  filter(percent >= 0) -> df_for_text5
df_for_text5
## # A tibble: 4 x 5
##   BPE   Res            n percent bar_text
##   <fct> <fct>      <int>   <dbl> <chr>   
## 1 PSQT1 Khá d<U+1ED3>ng ý   194    22.6 22.61%  
## 2 PSQT2 Khá d<U+1ED3>ng ý   143    16.7 16.67%  
## 3 PSQT3 Khá d<U+1ED3>ng ý   180    21.0 20.98%  
## 4 PSQT4 Khá d<U+1ED3>ng ý   223    26.0 25.99%
# For displaying percent of "Agree": 
df_odered %>% 
  filter(Res == "\u0110\u1ED3ng \u00FD") %>% 
  filter(percent >= 0) -> df_for_text6
df_for_text6
## # A tibble: 4 x 5
##   BPE   Res        n percent bar_text
##   <fct> <fct>  <int>   <dbl> <chr>   
## 1 PSQT1 Ð<U+1ED3>ng ý   362    42.2 42.19%  
## 2 PSQT2 Ð<U+1ED3>ng ý   378    44.1 44.06%  
## 3 PSQT3 Ð<U+1ED3>ng ý   349    40.7 40.68%  
## 4 PSQT4 Ð<U+1ED3>ng ý   342    39.9 39.86%
# For displaying percent of "Very Agree": 
df_odered %>% 
  filter(Res == "R\u1EA5t \u0111\u1ED3ng \u00FD") %>% 
  filter(percent >= 0) -> df_for_text7
df_for_text7
## # A tibble: 4 x 5
##   BPE   Res            n percent bar_text
##   <fct> <fct>      <int>   <dbl> <chr>   
## 1 PSQT1 R<U+1EA5>t d<U+1ED3>ng ý   127    14.8 14.8%   
## 2 PSQT2 R<U+1EA5>t d<U+1ED3>ng ý   157    18.3 18.3%   
## 3 PSQT3 R<U+1EA5>t d<U+1ED3>ng ý   128    14.9 14.92%  
## 4 PSQT4 R<U+1EA5>t d<U+1ED3>ng ý    97    11.3 11.31%
# For displaying percent of "Very Agree": 
df_odered %>% 
  filter(Res == "R\u1EA5t \u0111\u1ED3ng \u00FD") -> df_for_text
df_for_text
## # A tibble: 4 x 5
##   BPE   Res            n percent bar_text
##   <fct> <fct>      <int>   <dbl> <chr>   
## 1 PSQT1 R<U+1EA5>t d<U+1ED3>ng ý   127    14.8 14.8%   
## 2 PSQT2 R<U+1EA5>t d<U+1ED3>ng ý   157    18.3 18.3%   
## 3 PSQT3 R<U+1EA5>t d<U+1ED3>ng ý   128    14.9 14.92%  
## 4 PSQT4 R<U+1EA5>t d<U+1ED3>ng ý    97    11.3 11.31%
# Ad text layers-thay đổi giá trị y để thể hiện vị trí ghi text phù hợp
gg_v + 
  geom_text(data = df_for_text1, aes(x = BPE, y = 2, label = bar_text), size = 4, color = "white", family = my_font) + 
  geom_text(data = df_for_text6, aes(x = BPE, y = 100-30, label = bar_text), size = 4, color = "white", family = my_font) +
  geom_text(data = df_for_text7, aes(x = BPE, y = 100-2, label = bar_text), size = 4, color = "white", family = my_font)
## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database
## Warning in grid.Call.graphics(C_text, as.graphicsAnnot(x$label), x$x, x$y, :
## font family not found in Windows font database
## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

3.8.5. Construct PSQC-Nhãn tiếng anh

# Plot Likert graph for people in both cities for construct LIN
library(tidyverse)
library(compareGroups)
head(DN_HCM_SEM5_PSQC)
##   Res   BPE
## 1   6 PSQC1
## 2   4 PSQC1
## 3   2 PSQC1
## 4   5 PSQC1
## 5   6 PSQC1
## 6   5 PSQC1
dim(DN_HCM_SEM5_PSQC)
## [1] 5148    2
attach(DN_HCM_SEM5_PSQC)
## The following objects are masked from DN_HCM_SEM5_PSQT:
## 
##     BPE, Res
## The following objects are masked from DN_HCM_SEM5_PSB:
## 
##     BPE, Res
## The following objects are masked from HCM_SEM5:
## 
##     BPE, Res
## The following objects are masked from DN_SEM5:
## 
##     BPE, Res
## The following objects are masked from DN_HCM_SEM5:
## 
##     BPE, Res
DN_HCM_SEM5_PSQC = within(DN_HCM_SEM5_PSQC, {
  Res = factor(Res, labels = c("Very Disagree", "Disagree", "Quite Disagree", "Normal", "Quite Agree", "Agree", "Very Agree"))
  BPE = factor(BPE, labels = c("PSQC1", "PSQC2", "PSQC3", "PSQC4", "PSQC5", "PSQC6"))
  })
str(DN_HCM_SEM5_PSQC)
## 'data.frame':    5148 obs. of  2 variables:
##  $ Res: Factor w/ 7 levels "Very Disagree",..: 6 4 2 5 6 5 2 6 3 7 ...
##  $ BPE: Factor w/ 6 levels "PSQC1","PSQC2",..: 1 1 1 1 1 1 1 1 1 1 ...
summary(DN_HCM_SEM5_PSQC)
##              Res          BPE     
##  Very Disagree :  84   PSQC1:858  
##  Disagree      : 233   PSQC2:858  
##  Quite Disagree: 268   PSQC3:858  
##  Normal        : 773   PSQC4:858  
##  Quite Agree   :1030   PSQC5:858  
##  Agree         :2169   PSQC6:858  
##  Very Agree    : 591
    ## t <- compareGroups(Res ~ BPE, data = DN_SEM1)
    ## createTable(t)
DN_HCM_SEM5_PSQC %>% 
  group_by(BPE, Res) %>% 
  count() %>% 
  ungroup() %>% 
  group_by(BPE) %>% 
  mutate(percent = 100*n / sum(n)) %>% 
  mutate(percent = round(percent, 2)) %>% 
  mutate(bar_text = paste0(percent, "%")) %>% 
  ungroup() -> df_for_ploting
df_for_ploting %>% 
  filter(Res == Res[7]) %>% 
  arrange(percent) %>% # sắp xếp theo %
  pull(BPE) -> order_x
order_x
## [1] PSQC4 PSQC5 PSQC3 PSQC1 PSQC2 PSQC6
## Levels: PSQC1 PSQC2 PSQC3 PSQC4 PSQC5 PSQC6
# Make a draft plot: 
my_colors <- c("#3e6487", "#829cb2", "pink", "pink3", "palevioletred", "rosybrown2", "rosybrown3")
my_font <- "Roboto Condensed"

df_for_ploting %>% 
  mutate(BPE = factor(BPE, levels = order_x), Res = factor(Res, levels = Res[7:1])) -> df_odered
df_odered
## # A tibble: 42 x 5
##    BPE   Res                n percent bar_text
##    <fct> <fct>          <int>   <dbl> <chr>   
##  1 PSQC1 Very Disagree     17    1.98 1.98%   
##  2 PSQC1 Disagree          38    4.43 4.43%   
##  3 PSQC1 Quite Disagree    62    7.23 7.23%   
##  4 PSQC1 Normal           100   11.7  11.66%  
##  5 PSQC1 Quite Agree      205   23.9  23.89%  
##  6 PSQC1 Agree            348   40.6  40.56%  
##  7 PSQC1 Very Agree        88   10.3  10.26%  
##  8 PSQC2 Very Disagree     10    1.17 1.17%   
##  9 PSQC2 Disagree          32    3.73 3.73%   
## 10 PSQC2 Quite Disagree    16    1.86 1.86%   
## # ... with 32 more rows
library(extrafont)
theme_set(theme_minimal())
gg <- df_odered %>% 
  ggplot(aes(x = BPE, y = percent, fill = Res)) + 
  geom_col(width = 0.8) + 
  coord_flip() + 
  scale_fill_manual(values = my_colors[7:1], name = "") + 
  theme(legend.position = "top") + 
  theme(text = element_text(family = my_font)) + 
  guides(fill = guide_legend(reverse = TRUE)) + 
  scale_y_continuous(labels = paste0(seq(0, 100, 25), "%"), expand = c(0, 0)) + 
  theme(plot.title = element_text(size = 18), plot.subtitle = element_text(size = 11, color = "grey20")) + 
  theme(axis.text = element_text(color = "grey20", size = 10.2)) + 
  theme(plot.margin = unit(rep(0.7, 4), "cm")) + 
  theme(panel.grid.major.y = element_blank(), panel.grid.minor.x = element_blank()) + 
  theme(legend.key.height = unit(0.15, "mm")) + 
  labs(x = NULL, y = NULL, 
       title = "Perceived service quality of convenience (PSQC) of passengers in urban areas of Viet Nam", 
       subtitle = "Likert scale is a type of rating scale commonly used in surveys. When responding to a Likert type question,\nrespondents simply state their level of agreement or disagreement on a symmetric agree-disagree scale.")
gg
## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

# For displaying percent of "Very Disagree": Điều chỉnh percent để thể hiện giá trị của %
df_odered %>% 
  filter(Res == "Very Disagree") %>% 
  filter(percent >= 0) -> df_for_text1
df_for_text1
## # A tibble: 6 x 5
##   BPE   Res               n percent bar_text
##   <fct> <fct>         <int>   <dbl> <chr>   
## 1 PSQC1 Very Disagree    17    1.98 1.98%   
## 2 PSQC2 Very Disagree    10    1.17 1.17%   
## 3 PSQC3 Very Disagree    16    1.86 1.86%   
## 4 PSQC4 Very Disagree    16    1.86 1.86%   
## 5 PSQC5 Very Disagree    15    1.75 1.75%   
## 6 PSQC6 Very Disagree    10    1.17 1.17%
# For displaying percent of "Disagree": 
df_odered %>% 
  filter(Res == "Disagree") %>% 
  filter(percent >= 3) -> df_for_text2
df_for_text2
## # A tibble: 5 x 5
##   BPE   Res          n percent bar_text
##   <fct> <fct>    <int>   <dbl> <chr>   
## 1 PSQC1 Disagree    38    4.43 4.43%   
## 2 PSQC2 Disagree    32    3.73 3.73%   
## 3 PSQC3 Disagree    43    5.01 5.01%   
## 4 PSQC4 Disagree    49    5.71 5.71%   
## 5 PSQC5 Disagree    47    5.48 5.48%
# For displaying percent of "Quite Disagree": 
df_odered %>% 
  filter(Res == "Quite Disagree") %>% 
  filter(percent >= 0) -> df_for_text3
df_for_text3
## # A tibble: 6 x 5
##   BPE   Res                n percent bar_text
##   <fct> <fct>          <int>   <dbl> <chr>   
## 1 PSQC1 Quite Disagree    62    7.23 7.23%   
## 2 PSQC2 Quite Disagree    16    1.86 1.86%   
## 3 PSQC3 Quite Disagree    62    7.23 7.23%   
## 4 PSQC4 Quite Disagree    54    6.29 6.29%   
## 5 PSQC5 Quite Disagree    42    4.9  4.9%    
## 6 PSQC6 Quite Disagree    32    3.73 3.73%
# For displaying percent of "Normal": 
df_odered %>% 
  filter(Res == "Normal") %>% 
  filter(percent >= 0) -> df_for_text4
df_for_text4
## # A tibble: 6 x 5
##   BPE   Res        n percent bar_text
##   <fct> <fct>  <int>   <dbl> <chr>   
## 1 PSQC1 Normal   100   11.7  11.66%  
## 2 PSQC2 Normal    69    8.04 8.04%   
## 3 PSQC3 Normal   101   11.8  11.77%  
## 4 PSQC4 Normal   255   29.7  29.72%  
## 5 PSQC5 Normal   182   21.2  21.21%  
## 6 PSQC6 Normal    66    7.69 7.69%
# For displaying percent of "Quite Agree": 
df_odered %>% 
  filter(Res == "Quite Agree") %>% 
  filter(percent >= 0) -> df_for_text5
df_for_text5
## # A tibble: 6 x 5
##   BPE   Res             n percent bar_text
##   <fct> <fct>       <int>   <dbl> <chr>   
## 1 PSQC1 Quite Agree   205    23.9 23.89%  
## 2 PSQC2 Quite Agree   139    16.2 16.2%   
## 3 PSQC3 Quite Agree   202    23.5 23.54%  
## 4 PSQC4 Quite Agree   162    18.9 18.88%  
## 5 PSQC5 Quite Agree   150    17.5 17.48%  
## 6 PSQC6 Quite Agree   172    20.0 20.05%
# For displaying percent of "Agree": 
df_odered %>% 
  filter(Res == "Agree") %>% 
  filter(percent >= 0) -> df_for_text6
df_for_text6
## # A tibble: 6 x 5
##   BPE   Res       n percent bar_text
##   <fct> <fct> <int>   <dbl> <chr>   
## 1 PSQC1 Agree   348    40.6 40.56%  
## 2 PSQC2 Agree   449    52.3 52.33%  
## 3 PSQC3 Agree   348    40.6 40.56%  
## 4 PSQC4 Agree   265    30.9 30.89%  
## 5 PSQC5 Agree   349    40.7 40.68%  
## 6 PSQC6 Agree   410    47.8 47.79%
# For displaying percent of "Very Agree": 
df_odered %>% 
  filter(Res == "Very Agree") %>% 
  filter(percent >= 0) -> df_for_text7 # Chỉ thể hiện giá trị có % lựa chọn >0
df_for_text7
## # A tibble: 6 x 5
##   BPE   Res            n percent bar_text
##   <fct> <fct>      <int>   <dbl> <chr>   
## 1 PSQC1 Very Agree    88   10.3  10.26%  
## 2 PSQC2 Very Agree   143   16.7  16.67%  
## 3 PSQC3 Very Agree    86   10.0  10.02%  
## 4 PSQC4 Very Agree    57    6.64 6.64%   
## 5 PSQC5 Very Agree    73    8.51 8.51%   
## 6 PSQC6 Very Agree   144   16.8  16.78%
# For displaying percent of "Very Agree": 
df_odered %>% 
  filter(Res == "Very Agree") -> df_for_text
df_for_text
## # A tibble: 6 x 5
##   BPE   Res            n percent bar_text
##   <fct> <fct>      <int>   <dbl> <chr>   
## 1 PSQC1 Very Agree    88   10.3  10.26%  
## 2 PSQC2 Very Agree   143   16.7  16.67%  
## 3 PSQC3 Very Agree    86   10.0  10.02%  
## 4 PSQC4 Very Agree    57    6.64 6.64%   
## 5 PSQC5 Very Agree    73    8.51 8.51%   
## 6 PSQC6 Very Agree   144   16.8  16.78%
# Ad text layers-thay đổi giá trị y để thể hiện vị trí ghi text phù hợp
gg + 
  geom_text(data = df_for_text1, aes(x = BPE, y = 3, label = bar_text), size = 4, color = "white", family = my_font) + 
  geom_text(data = df_for_text2, aes(x = BPE, y = 9, label = bar_text), size = 4, color = "white", family = my_font) +
  geom_text(data = df_for_text5, aes(x = BPE, y = 32, label = bar_text), size = 4, color = "white", family = my_font) +
  geom_text(data = df_for_text6, aes(x = BPE, y = 100-30, label = bar_text), size = 4, color = "white", family = my_font) +
  geom_text(data = df_for_text7, aes(x = BPE, y = 100-4, label = bar_text), size = 4, color = "white", family = my_font)
## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database
## Warning in grid.Call.graphics(C_text, as.graphicsAnnot(x$label), x$x, x$y, :
## font family not found in Windows font database
## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

3.8.6. Construct PSQC-Nhãn tiếng việt

DN_HCM_SEM5_PSQC_v = within(DN_HCM_SEM5_PSQC, {
  Res = factor(Res, labels = c("R\u1EA5t kh\u00F4ng \u0111\u1ED3ng \u00FD", "Kh\u00F4ng \u0111\u1ED3ng \u00FD", "Kh\u00E1 kh\u00F4ng \u0111\u1ED3ng \u00FD", "B\u00ECnh th\u01B0\u1EDDng", "Kh\u00E1 \u0111\u1ED3ng \u00FD", "\u0110\u1ED3ng \u00FD", "R\u1EA5t \u0111\u1ED3ng \u00FD"))
  BPE = factor(BPE, labels = c("PSQC1", "PSQC2", "PSQC3", "PSQC4", "PSQC5", "PSQC6"))
  })
str(DN_HCM_SEM5_PSQC_v)
## 'data.frame':    5148 obs. of  2 variables:
##  $ Res: Factor w/ 7 levels "R<U+1EA5>t không d<U+1ED3>ng ý",..: 6 4 2 5 6 5 2 6 3 7 ...
##  $ BPE: Factor w/ 6 levels "PSQC1","PSQC2",..: 1 1 1 1 1 1 1 1 1 1 ...
summary(DN_HCM_SEM5_PSQC_v)
##                              Res          BPE     
##  R<U+1EA5>t không d<U+1ED3>ng ý:  84   PSQC1:858  
##  Không d<U+1ED3>ng ý           : 233   PSQC2:858  
##  Khá không d<U+1ED3>ng ý       : 268   PSQC3:858  
##  Bình thu<U+1EDD>ng            : 773   PSQC4:858  
##  Khá d<U+1ED3>ng ý             :1030   PSQC5:858  
##  Ð<U+1ED3>ng ý                 :2169   PSQC6:858  
##  R<U+1EA5>t d<U+1ED3>ng ý      : 591
    ## t <- compareGroups(Res ~ BPE, data = DN_SEM1)
    ## createTable(t)
DN_HCM_SEM5_PSQC_v %>% 
  group_by(BPE, Res) %>% 
  count() %>% 
  ungroup() %>% 
  group_by(BPE) %>% 
  mutate(percent = 100*n / sum(n)) %>% 
  mutate(percent = round(percent, 2)) %>% 
  mutate(bar_text = paste0(percent, "%")) %>% 
  ungroup() -> df_for_ploting
df_for_ploting %>% 
  filter(Res == Res[7]) %>% 
  arrange(percent) %>% # sắp xếp theo %
  pull(BPE) -> order_x
order_x
## [1] PSQC4 PSQC5 PSQC3 PSQC1 PSQC2 PSQC6
## Levels: PSQC1 PSQC2 PSQC3 PSQC4 PSQC5 PSQC6
# Make a draft plot: 
my_colors <- c("#3e6487", "#829cb2", "pink", "pink3", "palevioletred", "rosybrown2", "rosybrown3")
my_font <- "Roboto Condensed"

df_for_ploting %>% 
  mutate(BPE = factor(BPE, levels = order_x), Res = factor(Res, levels = Res[7:1])) -> df_odered
df_odered
## # A tibble: 42 x 5
##    BPE   Res                  n percent bar_text
##    <fct> <fct>            <int>   <dbl> <chr>   
##  1 PSQC1 R<U+1EA5>t không d<U+1ED3>ng ý    17    1.98 1.98%   
##  2 PSQC1 Không d<U+1ED3>ng ý        38    4.43 4.43%   
##  3 PSQC1 Khá không d<U+1ED3>ng ý    62    7.23 7.23%   
##  4 PSQC1 Bình thu<U+1EDD>ng        100   11.7  11.66%  
##  5 PSQC1 Khá d<U+1ED3>ng ý         205   23.9  23.89%  
##  6 PSQC1 Ð<U+1ED3>ng ý             348   40.6  40.56%  
##  7 PSQC1 R<U+1EA5>t d<U+1ED3>ng ý          88   10.3  10.26%  
##  8 PSQC2 R<U+1EA5>t không d<U+1ED3>ng ý    10    1.17 1.17%   
##  9 PSQC2 Không d<U+1ED3>ng ý        32    3.73 3.73%   
## 10 PSQC2 Khá không d<U+1ED3>ng ý    16    1.86 1.86%   
## # ... with 32 more rows
library(extrafont)
theme_set(theme_minimal())
gg_v <- df_odered %>% 
  ggplot(aes(x = BPE, y = percent, fill = Res)) + 
  geom_col(width = 0.8) + 
  coord_flip() + 
  scale_fill_manual(values = my_colors[7:1], name = "") + 
  theme(legend.position = "top") + 
  theme(text = element_text(family = my_font)) + 
  guides(fill = guide_legend(reverse = TRUE)) + 
  scale_y_continuous(labels = paste0(seq(0, 100, 25), "%"), expand = c(0, 0)) + 
  theme(plot.title = element_text(size = 18), plot.subtitle = element_text(size = 11, color = "grey20")) + 
  theme(axis.text = element_text(color = "grey20", size = 10.2)) + 
  theme(plot.margin = unit(rep(0.7, 4), "cm")) + 
  theme(panel.grid.major.y = element_blank(), panel.grid.minor.x = element_blank()) + 
  theme(legend.key.height = unit(0.15, "mm")) + 
  labs(x = NULL, y = NULL, 
       title = "C\u1EA3m nh\u1EADn c\u1EE7a h\u00E0nh kh\u00E1ch v\u1EC1 ch\u1EA5t l\u01B0\u1EE3ng d\u1ECBch v\u1EE5 ti\u1EC7n nghi (PSQC) \u0111\u1ED1i v\u1EDBi h\u1EC7 th\u1ED1ng xe bu\u00FDt \u0111\u00F4 th\u1ECB Vi\u1EC7t Nam", 
       subtitle = "Thang \u0111o Likert l\u00E0 lo\u1EA1i thang \u0111o \u0111i\u1EC3m \u0111\u00E1nh gi\u00E1 \u0111\u01B0\u1EE3c s\u1EED d\u1EE5ng ph\u1ED5 bi\u1EBFn trong kh\u1EA3o s\u00E1t. Nghi\u00EAn c\u1EE9u s\u1EED d\u1EE5ng thang \u0111o 7 m\u1EE9c \u0111\u1ED9 t\u01B0\u01A1ng \u1EE9ng v\u1EDBi 1 - R\u1EA5t kh\u00F4ng \u0111\u1ED3ng \u00FD \u0111\u1EBFn 7 - R\u1EA5t \u0111\u1ED3ng \u00FD.")
gg_v
## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

# For displaying percent of "Very Disagree": Điều chỉnh percent để thể hiện giá trị của %
df_odered %>% 
  filter(Res == "R\u1EA5t kh\u00F4ng \u0111\u1ED3ng \u00FD") %>% 
  filter(percent >= 0) -> df_for_text1
df_for_text1
## # A tibble: 6 x 5
##   BPE   Res                  n percent bar_text
##   <fct> <fct>            <int>   <dbl> <chr>   
## 1 PSQC1 R<U+1EA5>t không d<U+1ED3>ng ý    17    1.98 1.98%   
## 2 PSQC2 R<U+1EA5>t không d<U+1ED3>ng ý    10    1.17 1.17%   
## 3 PSQC3 R<U+1EA5>t không d<U+1ED3>ng ý    16    1.86 1.86%   
## 4 PSQC4 R<U+1EA5>t không d<U+1ED3>ng ý    16    1.86 1.86%   
## 5 PSQC5 R<U+1EA5>t không d<U+1ED3>ng ý    15    1.75 1.75%   
## 6 PSQC6 R<U+1EA5>t không d<U+1ED3>ng ý    10    1.17 1.17%
# For displaying percent of "Disagree": 
df_odered %>% 
  filter(Res == "Kh\u00F4ng \u0111\u1ED3ng \u00FD") %>% 
  filter(percent >= 0) -> df_for_text2
df_for_text2
## # A tibble: 6 x 5
##   BPE   Res              n percent bar_text
##   <fct> <fct>        <int>   <dbl> <chr>   
## 1 PSQC1 Không d<U+1ED3>ng ý    38    4.43 4.43%   
## 2 PSQC2 Không d<U+1ED3>ng ý    32    3.73 3.73%   
## 3 PSQC3 Không d<U+1ED3>ng ý    43    5.01 5.01%   
## 4 PSQC4 Không d<U+1ED3>ng ý    49    5.71 5.71%   
## 5 PSQC5 Không d<U+1ED3>ng ý    47    5.48 5.48%   
## 6 PSQC6 Không d<U+1ED3>ng ý    24    2.8  2.8%
# For displaying percent of "Quite Disagree": 
df_odered %>% 
  filter(Res == "Kh\u00E1 kh\u00F4ng \u0111\u1ED3ng \u00FD") %>% 
  filter(percent >= 0) -> df_for_text3
df_for_text3
## # A tibble: 6 x 5
##   BPE   Res                  n percent bar_text
##   <fct> <fct>            <int>   <dbl> <chr>   
## 1 PSQC1 Khá không d<U+1ED3>ng ý    62    7.23 7.23%   
## 2 PSQC2 Khá không d<U+1ED3>ng ý    16    1.86 1.86%   
## 3 PSQC3 Khá không d<U+1ED3>ng ý    62    7.23 7.23%   
## 4 PSQC4 Khá không d<U+1ED3>ng ý    54    6.29 6.29%   
## 5 PSQC5 Khá không d<U+1ED3>ng ý    42    4.9  4.9%    
## 6 PSQC6 Khá không d<U+1ED3>ng ý    32    3.73 3.73%
# For displaying percent of "Normal": 
df_odered %>% 
  filter(Res == "B\u00ECnh th\u01B0\u1EDDng") %>% 
  filter(percent >= 0) -> df_for_text4
df_for_text4
## # A tibble: 6 x 5
##   BPE   Res             n percent bar_text
##   <fct> <fct>       <int>   <dbl> <chr>   
## 1 PSQC1 Bình thu<U+1EDD>ng   100   11.7  11.66%  
## 2 PSQC2 Bình thu<U+1EDD>ng    69    8.04 8.04%   
## 3 PSQC3 Bình thu<U+1EDD>ng   101   11.8  11.77%  
## 4 PSQC4 Bình thu<U+1EDD>ng   255   29.7  29.72%  
## 5 PSQC5 Bình thu<U+1EDD>ng   182   21.2  21.21%  
## 6 PSQC6 Bình thu<U+1EDD>ng    66    7.69 7.69%
# For displaying percent of "Quite Agree": 
df_odered %>% 
  filter(Res == "Kh\u00E1 \u0111\u1ED3ng \u00FD") %>% 
  filter(percent >= 0) -> df_for_text5
df_for_text5
## # A tibble: 6 x 5
##   BPE   Res            n percent bar_text
##   <fct> <fct>      <int>   <dbl> <chr>   
## 1 PSQC1 Khá d<U+1ED3>ng ý   205    23.9 23.89%  
## 2 PSQC2 Khá d<U+1ED3>ng ý   139    16.2 16.2%   
## 3 PSQC3 Khá d<U+1ED3>ng ý   202    23.5 23.54%  
## 4 PSQC4 Khá d<U+1ED3>ng ý   162    18.9 18.88%  
## 5 PSQC5 Khá d<U+1ED3>ng ý   150    17.5 17.48%  
## 6 PSQC6 Khá d<U+1ED3>ng ý   172    20.0 20.05%
# For displaying percent of "Agree": 
df_odered %>% 
  filter(Res == "\u0110\u1ED3ng \u00FD") %>% 
  filter(percent >= 0) -> df_for_text6
df_for_text6
## # A tibble: 6 x 5
##   BPE   Res        n percent bar_text
##   <fct> <fct>  <int>   <dbl> <chr>   
## 1 PSQC1 Ð<U+1ED3>ng ý   348    40.6 40.56%  
## 2 PSQC2 Ð<U+1ED3>ng ý   449    52.3 52.33%  
## 3 PSQC3 Ð<U+1ED3>ng ý   348    40.6 40.56%  
## 4 PSQC4 Ð<U+1ED3>ng ý   265    30.9 30.89%  
## 5 PSQC5 Ð<U+1ED3>ng ý   349    40.7 40.68%  
## 6 PSQC6 Ð<U+1ED3>ng ý   410    47.8 47.79%
# For displaying percent of "Very Agree": 
df_odered %>% 
  filter(Res == "R\u1EA5t \u0111\u1ED3ng \u00FD") %>% 
  filter(percent >= 0) -> df_for_text7
df_for_text7
## # A tibble: 6 x 5
##   BPE   Res            n percent bar_text
##   <fct> <fct>      <int>   <dbl> <chr>   
## 1 PSQC1 R<U+1EA5>t d<U+1ED3>ng ý    88   10.3  10.26%  
## 2 PSQC2 R<U+1EA5>t d<U+1ED3>ng ý   143   16.7  16.67%  
## 3 PSQC3 R<U+1EA5>t d<U+1ED3>ng ý    86   10.0  10.02%  
## 4 PSQC4 R<U+1EA5>t d<U+1ED3>ng ý    57    6.64 6.64%   
## 5 PSQC5 R<U+1EA5>t d<U+1ED3>ng ý    73    8.51 8.51%   
## 6 PSQC6 R<U+1EA5>t d<U+1ED3>ng ý   144   16.8  16.78%
# For displaying percent of "Very Agree": 
df_odered %>% 
  filter(Res == "R\u1EA5t \u0111\u1ED3ng \u00FD") -> df_for_text
df_for_text
## # A tibble: 6 x 5
##   BPE   Res            n percent bar_text
##   <fct> <fct>      <int>   <dbl> <chr>   
## 1 PSQC1 R<U+1EA5>t d<U+1ED3>ng ý    88   10.3  10.26%  
## 2 PSQC2 R<U+1EA5>t d<U+1ED3>ng ý   143   16.7  16.67%  
## 3 PSQC3 R<U+1EA5>t d<U+1ED3>ng ý    86   10.0  10.02%  
## 4 PSQC4 R<U+1EA5>t d<U+1ED3>ng ý    57    6.64 6.64%   
## 5 PSQC5 R<U+1EA5>t d<U+1ED3>ng ý    73    8.51 8.51%   
## 6 PSQC6 R<U+1EA5>t d<U+1ED3>ng ý   144   16.8  16.78%
# Ad text layers-thay đổi giá trị y để thể hiện vị trí ghi text phù hợp
gg_v + 
  geom_text(data = df_for_text1, aes(x = BPE, y = 3, label = bar_text), size = 4, color = "white", family = my_font) + 
  geom_text(data = df_for_text2, aes(x = BPE, y = 9, label = bar_text), size = 4, color = "white", family = my_font) +
  geom_text(data = df_for_text5, aes(x = BPE, y = 32, label = bar_text), size = 4, color = "white", family = my_font) +
  geom_text(data = df_for_text6, aes(x = BPE, y = 100-30, label = bar_text), size = 4, color = "white", family = my_font) +
  geom_text(data = df_for_text7, aes(x = BPE, y = 100-4, label = bar_text), size = 4, color = "white", family = my_font)
## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database
## Warning in grid.Call.graphics(C_text, as.graphicsAnnot(x$label), x$x, x$y, :
## font family not found in Windows font database
## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

3.8.7. Construct PSQP- Nhãn tiếng anh

# Plot Likert graph for people in both cities for construct IMA
library(tidyverse)
library(compareGroups)
head(DN_HCM_SEM5_PSQP)
##   Res   BPE
## 1   6 PSQP1
## 2   6 PSQP1
## 3   1 PSQP1
## 4   5 PSQP1
## 5   4 PSQP1
## 6   4 PSQP1
dim(DN_HCM_SEM5_PSQP)
## [1] 3432    2
attach(DN_HCM_SEM5_PSQP)
## The following objects are masked from DN_HCM_SEM5_PSQC:
## 
##     BPE, Res
## The following objects are masked from DN_HCM_SEM5_PSQT:
## 
##     BPE, Res
## The following objects are masked from DN_HCM_SEM5_PSB:
## 
##     BPE, Res
## The following objects are masked from HCM_SEM5:
## 
##     BPE, Res
## The following objects are masked from DN_SEM5:
## 
##     BPE, Res
## The following objects are masked from DN_HCM_SEM5:
## 
##     BPE, Res
DN_HCM_SEM5_PSQP = within(DN_HCM_SEM5_PSQP, {
  Res = factor(Res, labels = c("Very Disagree", "Disagree", "Quite Disagree", "Normal", "Quite Agree", "Agree", "Very Agree"))
  BPE = factor(BPE, labels = c("PSQP1", "PSQP2", "PSQP3", "PSQP4"))
  })
str(DN_HCM_SEM5_PSQP)
## 'data.frame':    3432 obs. of  2 variables:
##  $ Res: Factor w/ 7 levels "Very Disagree",..: 6 6 1 5 4 4 4 4 3 4 ...
##  $ BPE: Factor w/ 4 levels "PSQP1","PSQP2",..: 1 1 1 1 1 1 1 1 1 1 ...
summary(DN_HCM_SEM5_PSQP)
##              Res          BPE     
##  Very Disagree :  47   PSQP1:858  
##  Disagree      : 105   PSQP2:858  
##  Quite Disagree: 120   PSQP3:858  
##  Normal        : 393   PSQP4:858  
##  Quite Agree   : 700              
##  Agree         :1652              
##  Very Agree    : 415
    ## t <- compareGroups(Res ~ BPE, data = DN_SEM1)
    ## createTable(t)
DN_HCM_SEM5_PSQP %>% 
  group_by(BPE, Res) %>% 
  count() %>% 
  ungroup() %>% 
  group_by(BPE) %>% 
  mutate(percent = 100*n / sum(n)) %>% 
  mutate(percent = round(percent, 2)) %>% 
  mutate(bar_text = paste0(percent, "%")) %>% 
  ungroup() -> df_for_ploting
df_for_ploting %>% 
  filter(Res == Res[7]) %>% 
  arrange(percent) %>% # sắp xếp theo %
  pull(BPE) -> order_x
order_x
## [1] PSQP3 PSQP1 PSQP2 PSQP4
## Levels: PSQP1 PSQP2 PSQP3 PSQP4
# Make a draft plot: 
my_colors <- c("#3e6487", "#829cb2", "pink", "pink3", "palevioletred", "rosybrown2", "rosybrown3")
my_font <- "Roboto Condensed"

df_for_ploting %>% 
  mutate(BPE = factor(BPE, levels = order_x), Res = factor(Res, levels = Res[7:1])) -> df_odered
df_odered
## # A tibble: 28 x 5
##    BPE   Res                n percent bar_text
##    <fct> <fct>          <int>   <dbl> <chr>   
##  1 PSQP1 Very Disagree     14    1.63 1.63%   
##  2 PSQP1 Disagree          27    3.15 3.15%   
##  3 PSQP1 Quite Disagree    40    4.66 4.66%   
##  4 PSQP1 Normal           110   12.8  12.82%  
##  5 PSQP1 Quite Agree      167   19.5  19.46%  
##  6 PSQP1 Agree            398   46.4  46.39%  
##  7 PSQP1 Very Agree       102   11.9  11.89%  
##  8 PSQP2 Very Disagree     13    1.52 1.52%   
##  9 PSQP2 Disagree          31    3.61 3.61%   
## 10 PSQP2 Quite Disagree    42    4.9  4.9%    
## # ... with 18 more rows
library(extrafont)
theme_set(theme_minimal())
gg <- df_odered %>% 
  ggplot(aes(x = BPE, y = percent, fill = Res)) + 
  geom_col(width = 0.8) + 
  coord_flip() + 
  scale_fill_manual(values = my_colors[7:1], name = "") + 
  theme(legend.position = "top") + 
  theme(text = element_text(family = my_font)) + 
  guides(fill = guide_legend(reverse = TRUE)) + 
  scale_y_continuous(labels = paste0(seq(0, 100, 25), "%"), expand = c(0, 0)) + 
  theme(plot.title = element_text(size = 18), plot.subtitle = element_text(size = 11, color = "grey20")) + 
  theme(axis.text = element_text(color = "grey20", size = 10.2)) + 
  theme(plot.margin = unit(rep(0.7, 4), "cm")) + 
  theme(panel.grid.major.y = element_blank(), panel.grid.minor.x = element_blank()) + 
  theme(legend.key.height = unit(0.15, "mm")) + 
  labs(x = NULL, y = NULL, 
       title = "Perceived service quality of personel (PSQP) of passengers in urban areas of Viet Nam", 
       subtitle = "Likert scale is a type of rating scale commonly used in surveys. When responding to a Likert type question,\nrespondents simply state their level of agreement or disagreement on a symmetric agree-disagree scale.")
gg
## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

# For displaying percent of "Very Disagree": Điều chỉnh percent để thể hiện giá trị của %
df_odered %>% 
  filter(Res == "Very Disagree") %>% 
  filter(percent >= 0) -> df_for_text1
df_for_text1
## # A tibble: 4 x 5
##   BPE   Res               n percent bar_text
##   <fct> <fct>         <int>   <dbl> <chr>   
## 1 PSQP1 Very Disagree    14    1.63 1.63%   
## 2 PSQP2 Very Disagree    13    1.52 1.52%   
## 3 PSQP3 Very Disagree    11    1.28 1.28%   
## 4 PSQP4 Very Disagree     9    1.05 1.05%
# For displaying percent of "Disagree": 
df_odered %>% 
  filter(Res == "Disagree") %>% 
  filter(percent >= 3) -> df_for_text2
df_for_text2
## # A tibble: 3 x 5
##   BPE   Res          n percent bar_text
##   <fct> <fct>    <int>   <dbl> <chr>   
## 1 PSQP1 Disagree    27    3.15 3.15%   
## 2 PSQP2 Disagree    31    3.61 3.61%   
## 3 PSQP3 Disagree    26    3.03 3.03%
# For displaying percent of "Quite Disagree": 
df_odered %>% 
  filter(Res == "Quite Disagree") %>% 
  filter(percent >= 0) -> df_for_text3
df_for_text3
## # A tibble: 4 x 5
##   BPE   Res                n percent bar_text
##   <fct> <fct>          <int>   <dbl> <chr>   
## 1 PSQP1 Quite Disagree    40    4.66 4.66%   
## 2 PSQP2 Quite Disagree    42    4.9  4.9%    
## 3 PSQP3 Quite Disagree    25    2.91 2.91%   
## 4 PSQP4 Quite Disagree    13    1.52 1.52%
# For displaying percent of "Normal": 
df_odered %>% 
  filter(Res == "Normal") %>% 
  filter(percent >= 0) -> df_for_text4
df_for_text4
## # A tibble: 4 x 5
##   BPE   Res        n percent bar_text
##   <fct> <fct>  <int>   <dbl> <chr>   
## 1 PSQP1 Normal   110   12.8  12.82%  
## 2 PSQP2 Normal    99   11.5  11.54%  
## 3 PSQP3 Normal   100   11.7  11.66%  
## 4 PSQP4 Normal    84    9.79 9.79%
# For displaying percent of "Quite Agree": 
df_odered %>% 
  filter(Res == "Quite Agree") %>% 
  filter(percent >= 0) -> df_for_text5
df_for_text5
## # A tibble: 4 x 5
##   BPE   Res             n percent bar_text
##   <fct> <fct>       <int>   <dbl> <chr>   
## 1 PSQP1 Quite Agree   167    19.5 19.46%  
## 2 PSQP2 Quite Agree   188    21.9 21.91%  
## 3 PSQP3 Quite Agree   187    21.8 21.79%  
## 4 PSQP4 Quite Agree   158    18.4 18.41%
# For displaying percent of "Agree": 
df_odered %>% 
  filter(Res == "Agree") %>% 
  filter(percent >= 0) -> df_for_text6
df_for_text6
## # A tibble: 4 x 5
##   BPE   Res       n percent bar_text
##   <fct> <fct> <int>   <dbl> <chr>   
## 1 PSQP1 Agree   398    46.4 46.39%  
## 2 PSQP2 Agree   378    44.1 44.06%  
## 3 PSQP3 Agree   418    48.7 48.72%  
## 4 PSQP4 Agree   458    53.4 53.38%
# For displaying percent of "Very Agree": 
df_odered %>% 
  filter(Res == "Very Agree") %>% 
  filter(percent >= 0) -> df_for_text7 # Chỉ thể hiện giá trị có % lựa chọn >0
df_for_text7
## # A tibble: 4 x 5
##   BPE   Res            n percent bar_text
##   <fct> <fct>      <int>   <dbl> <chr>   
## 1 PSQP1 Very Agree   102    11.9 11.89%  
## 2 PSQP2 Very Agree   107    12.5 12.47%  
## 3 PSQP3 Very Agree    91    10.6 10.61%  
## 4 PSQP4 Very Agree   115    13.4 13.4%
# For displaying percent of "Very Agree": 
df_odered %>% 
  filter(Res == "Very Agree") -> df_for_text
df_for_text
## # A tibble: 4 x 5
##   BPE   Res            n percent bar_text
##   <fct> <fct>      <int>   <dbl> <chr>   
## 1 PSQP1 Very Agree   102    11.9 11.89%  
## 2 PSQP2 Very Agree   107    12.5 12.47%  
## 3 PSQP3 Very Agree    91    10.6 10.61%  
## 4 PSQP4 Very Agree   115    13.4 13.4%
# Ad text layers-thay đổi giá trị y để thể hiện vị trí ghi text phù hợp
gg + 
  geom_text(data = df_for_text1, aes(x = BPE, y = 3, label = bar_text), size = 4, color = "white", family = my_font) + 
  geom_text(data = df_for_text4, aes(x = BPE, y = 13, label = bar_text), size = 4, color = "white", family = my_font) +
  geom_text(data = df_for_text5, aes(x = BPE, y = 32, label = bar_text), size = 4, color = "white", family = my_font) +
  geom_text(data = df_for_text6, aes(x = BPE, y = 100-30, label = bar_text), size = 4, color = "white", family = my_font) +
  geom_text(data = df_for_text7, aes(x = BPE, y = 100-4, label = bar_text), size = 4, color = "white", family = my_font)
## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database
## Warning in grid.Call.graphics(C_text, as.graphicsAnnot(x$label), x$x, x$y, :
## font family not found in Windows font database
## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

3.8.8. Construct PSQP - Nhãn tiếng việt

DN_HCM_SEM5_PSQP_v = within(DN_HCM_SEM5_PSQP, {
  Res = factor(Res, labels = c("R\u1EA5t kh\u00F4ng \u0111\u1ED3ng \u00FD", "Kh\u00F4ng \u0111\u1ED3ng \u00FD", "Kh\u00E1 kh\u00F4ng \u0111\u1ED3ng \u00FD", "B\u00ECnh th\u01B0\u1EDDng", "Kh\u00E1 \u0111\u1ED3ng \u00FD", "\u0110\u1ED3ng \u00FD", "R\u1EA5t \u0111\u1ED3ng \u00FD"))
  BPE = factor(BPE, labels = c("PSQP1", "PSQP2", "PSQP3", "PSQP4"))
  })
str(DN_HCM_SEM5_PSQP_v)
## 'data.frame':    3432 obs. of  2 variables:
##  $ Res: Factor w/ 7 levels "R<U+1EA5>t không d<U+1ED3>ng ý",..: 6 6 1 5 4 4 4 4 3 4 ...
##  $ BPE: Factor w/ 4 levels "PSQP1","PSQP2",..: 1 1 1 1 1 1 1 1 1 1 ...
summary(DN_HCM_SEM5_PSQP_v)
##                              Res          BPE     
##  R<U+1EA5>t không d<U+1ED3>ng ý:  47   PSQP1:858  
##  Không d<U+1ED3>ng ý           : 105   PSQP2:858  
##  Khá không d<U+1ED3>ng ý       : 120   PSQP3:858  
##  Bình thu<U+1EDD>ng            : 393   PSQP4:858  
##  Khá d<U+1ED3>ng ý             : 700              
##  Ð<U+1ED3>ng ý                 :1652              
##  R<U+1EA5>t d<U+1ED3>ng ý      : 415
    ## t <- compareGroups(Res ~ BPE, data = DN_SEM1)
    ## createTable(t)
DN_HCM_SEM5_PSQP_v %>% 
  group_by(BPE, Res) %>% 
  count() %>% 
  ungroup() %>% 
  group_by(BPE) %>% 
  mutate(percent = 100*n / sum(n)) %>% 
  mutate(percent = round(percent, 2)) %>% 
  mutate(bar_text = paste0(percent, "%")) %>% 
  ungroup() -> df_for_ploting
df_for_ploting %>% 
  filter(Res == Res[7]) %>% 
  arrange(percent) %>% # sắp xếp theo %
  pull(BPE) -> order_x
order_x
## [1] PSQP3 PSQP1 PSQP2 PSQP4
## Levels: PSQP1 PSQP2 PSQP3 PSQP4
# Make a draft plot: 
my_colors <- c("#3e6487", "#829cb2", "pink", "pink3", "palevioletred", "rosybrown2", "rosybrown3")
my_font <- "Roboto Condensed"

df_for_ploting %>% 
  mutate(BPE = factor(BPE, levels = order_x), Res = factor(Res, levels = Res[7:1])) -> df_odered
df_odered
## # A tibble: 28 x 5
##    BPE   Res                  n percent bar_text
##    <fct> <fct>            <int>   <dbl> <chr>   
##  1 PSQP1 R<U+1EA5>t không d<U+1ED3>ng ý    14    1.63 1.63%   
##  2 PSQP1 Không d<U+1ED3>ng ý        27    3.15 3.15%   
##  3 PSQP1 Khá không d<U+1ED3>ng ý    40    4.66 4.66%   
##  4 PSQP1 Bình thu<U+1EDD>ng        110   12.8  12.82%  
##  5 PSQP1 Khá d<U+1ED3>ng ý         167   19.5  19.46%  
##  6 PSQP1 Ð<U+1ED3>ng ý             398   46.4  46.39%  
##  7 PSQP1 R<U+1EA5>t d<U+1ED3>ng ý         102   11.9  11.89%  
##  8 PSQP2 R<U+1EA5>t không d<U+1ED3>ng ý    13    1.52 1.52%   
##  9 PSQP2 Không d<U+1ED3>ng ý        31    3.61 3.61%   
## 10 PSQP2 Khá không d<U+1ED3>ng ý    42    4.9  4.9%    
## # ... with 18 more rows
library(extrafont)
theme_set(theme_minimal())
gg_v <- df_odered %>% 
  ggplot(aes(x = BPE, y = percent, fill = Res)) + 
  geom_col(width = 0.8) + 
  coord_flip() + 
  scale_fill_manual(values = my_colors[7:1], name = "") + 
  theme(legend.position = "top") + 
  theme(text = element_text(family = my_font)) + 
  guides(fill = guide_legend(reverse = TRUE)) + 
  scale_y_continuous(labels = paste0(seq(0, 100, 25), "%"), expand = c(0, 0)) + 
  theme(plot.title = element_text(size = 18), plot.subtitle = element_text(size = 11, color = "grey20")) + 
  theme(axis.text = element_text(color = "grey20", size = 10.2)) + 
  theme(plot.margin = unit(rep(0.7, 4), "cm")) + 
  theme(panel.grid.major.y = element_blank(), panel.grid.minor.x = element_blank()) + 
  theme(legend.key.height = unit(0.15, "mm")) + 
  labs(x = NULL, y = NULL, 
       title = "C\u1EA3m nh\u1EADn c\u1EE7a h\u00E0nh kh\u00E1ch v\u1EC1 ch\u1EA5t l\u01B0\u1EE3ng d\u1ECBch v\u1EE5 c\u00E1 nh\u00E2n (PSQC) \u0111\u1ED1i v\u1EDBi h\u1EC7 th\u1ED1ng xe bu\u00FDt \u0111\u00F4 th\u1ECB Vi\u1EC7t Nam", 
       subtitle = "Thang \u0111o Likert l\u00E0 lo\u1EA1i thang \u0111o \u0111i\u1EC3m \u0111\u00E1nh gi\u00E1 \u0111\u01B0\u1EE3c s\u1EED d\u1EE5ng ph\u1ED5 bi\u1EBFn trong kh\u1EA3o s\u00E1t. Nghi\u00EAn c\u1EE9u s\u1EED d\u1EE5ng thang \u0111o 7 m\u1EE9c \u0111\u1ED9 t\u01B0\u01A1ng \u1EE9ng v\u1EDBi 1 - R\u1EA5t kh\u00F4ng \u0111\u1ED3ng \u00FD \u0111\u1EBFn 7 - R\u1EA5t \u0111\u1ED3ng \u00FD.")
gg_v
## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

# For displaying percent of "Very Disagree": Điều chỉnh percent để thể hiện giá trị của %
df_odered %>% 
  filter(Res == "R\u1EA5t kh\u00F4ng \u0111\u1ED3ng \u00FD") %>% 
  filter(percent >= 0) -> df_for_text1
df_for_text1
## # A tibble: 4 x 5
##   BPE   Res                  n percent bar_text
##   <fct> <fct>            <int>   <dbl> <chr>   
## 1 PSQP1 R<U+1EA5>t không d<U+1ED3>ng ý    14    1.63 1.63%   
## 2 PSQP2 R<U+1EA5>t không d<U+1ED3>ng ý    13    1.52 1.52%   
## 3 PSQP3 R<U+1EA5>t không d<U+1ED3>ng ý    11    1.28 1.28%   
## 4 PSQP4 R<U+1EA5>t không d<U+1ED3>ng ý     9    1.05 1.05%
# For displaying percent of "Disagree": 
df_odered %>% 
  filter(Res == "Kh\u00F4ng \u0111\u1ED3ng \u00FD") %>% 
  filter(percent >= 0) -> df_for_text2
df_for_text2
## # A tibble: 4 x 5
##   BPE   Res              n percent bar_text
##   <fct> <fct>        <int>   <dbl> <chr>   
## 1 PSQP1 Không d<U+1ED3>ng ý    27    3.15 3.15%   
## 2 PSQP2 Không d<U+1ED3>ng ý    31    3.61 3.61%   
## 3 PSQP3 Không d<U+1ED3>ng ý    26    3.03 3.03%   
## 4 PSQP4 Không d<U+1ED3>ng ý    21    2.45 2.45%
# For displaying percent of "Quite Disagree": 
df_odered %>% 
  filter(Res == "Kh\u00E1 kh\u00F4ng \u0111\u1ED3ng \u00FD") %>% 
  filter(percent >= 0) -> df_for_text3
df_for_text3
## # A tibble: 4 x 5
##   BPE   Res                  n percent bar_text
##   <fct> <fct>            <int>   <dbl> <chr>   
## 1 PSQP1 Khá không d<U+1ED3>ng ý    40    4.66 4.66%   
## 2 PSQP2 Khá không d<U+1ED3>ng ý    42    4.9  4.9%    
## 3 PSQP3 Khá không d<U+1ED3>ng ý    25    2.91 2.91%   
## 4 PSQP4 Khá không d<U+1ED3>ng ý    13    1.52 1.52%
# For displaying percent of "Normal": 
df_odered %>% 
  filter(Res == "B\u00ECnh th\u01B0\u1EDDng") %>% 
  filter(percent >= 0) -> df_for_text4
df_for_text4
## # A tibble: 4 x 5
##   BPE   Res             n percent bar_text
##   <fct> <fct>       <int>   <dbl> <chr>   
## 1 PSQP1 Bình thu<U+1EDD>ng   110   12.8  12.82%  
## 2 PSQP2 Bình thu<U+1EDD>ng    99   11.5  11.54%  
## 3 PSQP3 Bình thu<U+1EDD>ng   100   11.7  11.66%  
## 4 PSQP4 Bình thu<U+1EDD>ng    84    9.79 9.79%
# For displaying percent of "Quite Agree": 
df_odered %>% 
  filter(Res == "Kh\u00E1 \u0111\u1ED3ng \u00FD") %>% 
  filter(percent >= 0) -> df_for_text5
df_for_text5
## # A tibble: 4 x 5
##   BPE   Res            n percent bar_text
##   <fct> <fct>      <int>   <dbl> <chr>   
## 1 PSQP1 Khá d<U+1ED3>ng ý   167    19.5 19.46%  
## 2 PSQP2 Khá d<U+1ED3>ng ý   188    21.9 21.91%  
## 3 PSQP3 Khá d<U+1ED3>ng ý   187    21.8 21.79%  
## 4 PSQP4 Khá d<U+1ED3>ng ý   158    18.4 18.41%
# For displaying percent of "Agree": 
df_odered %>% 
  filter(Res == "\u0110\u1ED3ng \u00FD") %>% 
  filter(percent >= 0) -> df_for_text6
df_for_text6
## # A tibble: 4 x 5
##   BPE   Res        n percent bar_text
##   <fct> <fct>  <int>   <dbl> <chr>   
## 1 PSQP1 Ð<U+1ED3>ng ý   398    46.4 46.39%  
## 2 PSQP2 Ð<U+1ED3>ng ý   378    44.1 44.06%  
## 3 PSQP3 Ð<U+1ED3>ng ý   418    48.7 48.72%  
## 4 PSQP4 Ð<U+1ED3>ng ý   458    53.4 53.38%
# For displaying percent of "Very Agree": 
df_odered %>% 
  filter(Res == "R\u1EA5t \u0111\u1ED3ng \u00FD") %>% 
  filter(percent >= 0) -> df_for_text7
df_for_text7
## # A tibble: 4 x 5
##   BPE   Res            n percent bar_text
##   <fct> <fct>      <int>   <dbl> <chr>   
## 1 PSQP1 R<U+1EA5>t d<U+1ED3>ng ý   102    11.9 11.89%  
## 2 PSQP2 R<U+1EA5>t d<U+1ED3>ng ý   107    12.5 12.47%  
## 3 PSQP3 R<U+1EA5>t d<U+1ED3>ng ý    91    10.6 10.61%  
## 4 PSQP4 R<U+1EA5>t d<U+1ED3>ng ý   115    13.4 13.4%
# For displaying percent of "Very Agree": 
df_odered %>% 
  filter(Res == "R\u1EA5t \u0111\u1ED3ng \u00FD") -> df_for_text
df_for_text
## # A tibble: 4 x 5
##   BPE   Res            n percent bar_text
##   <fct> <fct>      <int>   <dbl> <chr>   
## 1 PSQP1 R<U+1EA5>t d<U+1ED3>ng ý   102    11.9 11.89%  
## 2 PSQP2 R<U+1EA5>t d<U+1ED3>ng ý   107    12.5 12.47%  
## 3 PSQP3 R<U+1EA5>t d<U+1ED3>ng ý    91    10.6 10.61%  
## 4 PSQP4 R<U+1EA5>t d<U+1ED3>ng ý   115    13.4 13.4%
# Ad text layers-thay đổi giá trị y để thể hiện vị trí ghi text phù hợp
gg_v + 
  geom_text(data = df_for_text1, aes(x = BPE, y = 2, label = bar_text), size = 4, color = "white", family = my_font) + 
  geom_text(data = df_for_text6, aes(x = BPE, y = 100-30, label = bar_text), size = 4, color = "white", family = my_font) +
  geom_text(data = df_for_text7, aes(x = BPE, y = 100-2, label = bar_text), size = 4, color = "white", family = my_font)
## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database
## Warning in grid.Call.graphics(C_text, as.graphicsAnnot(x$label), x$x, x$y, :
## font family not found in Windows font database
## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

3.8.9. Construct PSQR- Nhãn tiếng anh

# Plot Likert graph for people in both cities for construct IMA
library(tidyverse)
library(compareGroups)
head(DN_HCM_SEM5_PSQR)
##   Res   BPE
## 1   4 PSQR1
## 2   4 PSQR1
## 3   2 PSQR1
## 4   4 PSQR1
## 5   5 PSQR1
## 6   3 PSQR1
dim(DN_HCM_SEM5_PSQR)
## [1] 3432    2
attach(DN_HCM_SEM5_PSQR)
## The following objects are masked from DN_HCM_SEM5_PSQP:
## 
##     BPE, Res
## The following objects are masked from DN_HCM_SEM5_PSQC:
## 
##     BPE, Res
## The following objects are masked from DN_HCM_SEM5_PSQT:
## 
##     BPE, Res
## The following objects are masked from DN_HCM_SEM5_PSB:
## 
##     BPE, Res
## The following objects are masked from HCM_SEM5:
## 
##     BPE, Res
## The following objects are masked from DN_SEM5:
## 
##     BPE, Res
## The following objects are masked from DN_HCM_SEM5:
## 
##     BPE, Res
DN_HCM_SEM5_PSQR = within(DN_HCM_SEM5_PSQR, {
  Res = factor(Res, labels = c("Very Disagree", "Disagree", "Quite Disagree", "Normal", "Quite Agree", "Agree", "Very Agree"))
  BPE = factor(BPE, labels = c("PSQR1", "PSQR2", "PSQR3", "PSQR4"))
  })
str(DN_HCM_SEM5_PSQR)
## 'data.frame':    3432 obs. of  2 variables:
##  $ Res: Factor w/ 7 levels "Very Disagree",..: 4 4 2 4 5 3 2 5 3 4 ...
##  $ BPE: Factor w/ 4 levels "PSQR1","PSQR2",..: 1 1 1 1 1 1 1 1 1 1 ...
summary(DN_HCM_SEM5_PSQR)
##              Res          BPE     
##  Very Disagree :  84   PSQR1:858  
##  Disagree      : 196   PSQR2:858  
##  Quite Disagree: 266   PSQR3:858  
##  Normal        : 429   PSQR4:858  
##  Quite Agree   : 847              
##  Agree         :1288              
##  Very Agree    : 322
    ## t <- compareGroups(Res ~ BPE, data = DN_SEM1)
    ## createTable(t)
DN_HCM_SEM5_PSQR %>% 
  group_by(BPE, Res) %>% 
  count() %>% 
  ungroup() %>% 
  group_by(BPE) %>% 
  mutate(percent = 100*n / sum(n)) %>% 
  mutate(percent = round(percent, 2)) %>% 
  mutate(bar_text = paste0(percent, "%")) %>% 
  ungroup() -> df_for_ploting
df_for_ploting %>% 
  filter(Res == Res[7]) %>% 
  arrange(percent) %>% # sắp xếp theo %
  pull(BPE) -> order_x
order_x
## [1] PSQR1 PSQR3 PSQR4 PSQR2
## Levels: PSQR1 PSQR2 PSQR3 PSQR4
# Make a draft plot: 
my_colors <- c("#3e6487", "#829cb2", "pink", "pink3", "palevioletred", "rosybrown2", "rosybrown3")
my_font <- "Roboto Condensed"

df_for_ploting %>% 
  mutate(BPE = factor(BPE, levels = order_x), Res = factor(Res, levels = Res[7:1])) -> df_odered
df_odered
## # A tibble: 28 x 5
##    BPE   Res                n percent bar_text
##    <fct> <fct>          <int>   <dbl> <chr>   
##  1 PSQR1 Very Disagree     24    2.8  2.8%    
##  2 PSQR1 Disagree          48    5.59 5.59%   
##  3 PSQR1 Quite Disagree    73    8.51 8.51%   
##  4 PSQR1 Normal            97   11.3  11.31%  
##  5 PSQR1 Quite Agree      244   28.4  28.44%  
##  6 PSQR1 Agree            303   35.3  35.31%  
##  7 PSQR1 Very Agree        69    8.04 8.04%   
##  8 PSQR2 Very Disagree     12    1.4  1.4%    
##  9 PSQR2 Disagree          31    3.61 3.61%   
## 10 PSQR2 Quite Disagree    56    6.53 6.53%   
## # ... with 18 more rows
library(extrafont)
theme_set(theme_minimal())
gg <- df_odered %>% 
  ggplot(aes(x = BPE, y = percent, fill = Res)) + 
  geom_col(width = 0.8) + 
  coord_flip() + 
  scale_fill_manual(values = my_colors[7:1], name = "") + 
  theme(legend.position = "top") + 
  theme(text = element_text(family = my_font)) + 
  guides(fill = guide_legend(reverse = TRUE)) + 
  scale_y_continuous(labels = paste0(seq(0, 100, 25), "%"), expand = c(0, 0)) + 
  theme(plot.title = element_text(size = 18), plot.subtitle = element_text(size = 11, color = "grey20")) + 
  theme(axis.text = element_text(color = "grey20", size = 10.2)) + 
  theme(plot.margin = unit(rep(0.7, 4), "cm")) + 
  theme(panel.grid.major.y = element_blank(), panel.grid.minor.x = element_blank()) + 
  theme(legend.key.height = unit(0.15, "mm")) + 
  labs(x = NULL, y = NULL, 
       title = "Perceived service quality of reliability (PSQR) of passengers in urban areas of Viet Nam", 
       subtitle = "Likert scale is a type of rating scale commonly used in surveys. When responding to a Likert type question,\nrespondents simply state their level of agreement or disagreement on a symmetric agree-disagree scale.")
gg
## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

# For displaying percent of "Very Disagree": Điều chỉnh percent để thể hiện giá trị của %
df_odered %>% 
  filter(Res == "Very Disagree") %>% 
  filter(percent >= 0) -> df_for_text1
df_for_text1
## # A tibble: 4 x 5
##   BPE   Res               n percent bar_text
##   <fct> <fct>         <int>   <dbl> <chr>   
## 1 PSQR1 Very Disagree    24    2.8  2.8%    
## 2 PSQR2 Very Disagree    12    1.4  1.4%    
## 3 PSQR3 Very Disagree    19    2.21 2.21%   
## 4 PSQR4 Very Disagree    29    3.38 3.38%
# For displaying percent of "Disagree": 
df_odered %>% 
  filter(Res == "Disagree") %>% 
  filter(percent >= 3) -> df_for_text2
df_for_text2
## # A tibble: 4 x 5
##   BPE   Res          n percent bar_text
##   <fct> <fct>    <int>   <dbl> <chr>   
## 1 PSQR1 Disagree    48    5.59 5.59%   
## 2 PSQR2 Disagree    31    3.61 3.61%   
## 3 PSQR3 Disagree    42    4.9  4.9%    
## 4 PSQR4 Disagree    75    8.74 8.74%
# For displaying percent of "Quite Disagree": 
df_odered %>% 
  filter(Res == "Quite Disagree") %>% 
  filter(percent >= 0) -> df_for_text3
df_for_text3
## # A tibble: 4 x 5
##   BPE   Res                n percent bar_text
##   <fct> <fct>          <int>   <dbl> <chr>   
## 1 PSQR1 Quite Disagree    73    8.51 8.51%   
## 2 PSQR2 Quite Disagree    56    6.53 6.53%   
## 3 PSQR3 Quite Disagree    61    7.11 7.11%   
## 4 PSQR4 Quite Disagree    76    8.86 8.86%
# For displaying percent of "Normal": 
df_odered %>% 
  filter(Res == "Normal") %>% 
  filter(percent >= 0) -> df_for_text4
df_for_text4
## # A tibble: 4 x 5
##   BPE   Res        n percent bar_text
##   <fct> <fct>  <int>   <dbl> <chr>   
## 1 PSQR1 Normal    97    11.3 11.31%  
## 2 PSQR2 Normal   107    12.5 12.47%  
## 3 PSQR3 Normal   126    14.7 14.69%  
## 4 PSQR4 Normal    99    11.5 11.54%
# For displaying percent of "Quite Agree": 
df_odered %>% 
  filter(Res == "Quite Agree") %>% 
  filter(percent >= 0) -> df_for_text5
df_for_text5
## # A tibble: 4 x 5
##   BPE   Res             n percent bar_text
##   <fct> <fct>       <int>   <dbl> <chr>   
## 1 PSQR1 Quite Agree   244    28.4 28.44%  
## 2 PSQR2 Quite Agree   190    22.1 22.14%  
## 3 PSQR3 Quite Agree   217    25.3 25.29%  
## 4 PSQR4 Quite Agree   196    22.8 22.84%
# For displaying percent of "Agree": 
df_odered %>% 
  filter(Res == "Agree") %>% 
  filter(percent >= 0) -> df_for_text6
df_for_text6
## # A tibble: 4 x 5
##   BPE   Res       n percent bar_text
##   <fct> <fct> <int>   <dbl> <chr>   
## 1 PSQR1 Agree   303    35.3 35.31%  
## 2 PSQR2 Agree   363    42.3 42.31%  
## 3 PSQR3 Agree   319    37.2 37.18%  
## 4 PSQR4 Agree   303    35.3 35.31%
# For displaying percent of "Very Agree": 
df_odered %>% 
  filter(Res == "Very Agree") %>% 
  filter(percent >= 0) -> df_for_text7 # Chỉ thể hiện giá trị có % lựa chọn >0
df_for_text7
## # A tibble: 4 x 5
##   BPE   Res            n percent bar_text
##   <fct> <fct>      <int>   <dbl> <chr>   
## 1 PSQR1 Very Agree    69    8.04 8.04%   
## 2 PSQR2 Very Agree    99   11.5  11.54%  
## 3 PSQR3 Very Agree    74    8.62 8.62%   
## 4 PSQR4 Very Agree    80    9.32 9.32%
# For displaying percent of "Very Agree": 
df_odered %>% 
  filter(Res == "Very Agree") -> df_for_text
df_for_text
## # A tibble: 4 x 5
##   BPE   Res            n percent bar_text
##   <fct> <fct>      <int>   <dbl> <chr>   
## 1 PSQR1 Very Agree    69    8.04 8.04%   
## 2 PSQR2 Very Agree    99   11.5  11.54%  
## 3 PSQR3 Very Agree    74    8.62 8.62%   
## 4 PSQR4 Very Agree    80    9.32 9.32%
# Ad text layers-thay đổi giá trị y để thể hiện vị trí ghi text phù hợp
gg + 
  geom_text(data = df_for_text1, aes(x = BPE, y = 3, label = bar_text), size = 4, color = "white", family = my_font) + 
  geom_text(data = df_for_text4, aes(x = BPE, y = 13, label = bar_text), size = 4, color = "white", family = my_font) +
  geom_text(data = df_for_text5, aes(x = BPE, y = 32, label = bar_text), size = 4, color = "white", family = my_font) +
  geom_text(data = df_for_text6, aes(x = BPE, y = 100-30, label = bar_text), size = 4, color = "white", family = my_font) +
  geom_text(data = df_for_text7, aes(x = BPE, y = 100-4, label = bar_text), size = 4, color = "white", family = my_font)
## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database
## Warning in grid.Call.graphics(C_text, as.graphicsAnnot(x$label), x$x, x$y, :
## font family not found in Windows font database
## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

3.8.10. Construct PSQP - Nhãn tiếng việt

DN_HCM_SEM5_PSQR_v = within(DN_HCM_SEM5_PSQR, {
  Res = factor(Res, labels = c("R\u1EA5t kh\u00F4ng \u0111\u1ED3ng \u00FD", "Kh\u00F4ng \u0111\u1ED3ng \u00FD", "Kh\u00E1 kh\u00F4ng \u0111\u1ED3ng \u00FD", "B\u00ECnh th\u01B0\u1EDDng", "Kh\u00E1 \u0111\u1ED3ng \u00FD", "\u0110\u1ED3ng \u00FD", "R\u1EA5t \u0111\u1ED3ng \u00FD"))
  BPE = factor(BPE, labels = c("PSQR1", "PSQR2", "PSQR3", "PSQR4"))
  })
str(DN_HCM_SEM5_PSQR_v)
## 'data.frame':    3432 obs. of  2 variables:
##  $ Res: Factor w/ 7 levels "R<U+1EA5>t không d<U+1ED3>ng ý",..: 4 4 2 4 5 3 2 5 3 4 ...
##  $ BPE: Factor w/ 4 levels "PSQR1","PSQR2",..: 1 1 1 1 1 1 1 1 1 1 ...
summary(DN_HCM_SEM5_PSQR_v)
##                              Res          BPE     
##  R<U+1EA5>t không d<U+1ED3>ng ý:  84   PSQR1:858  
##  Không d<U+1ED3>ng ý           : 196   PSQR2:858  
##  Khá không d<U+1ED3>ng ý       : 266   PSQR3:858  
##  Bình thu<U+1EDD>ng            : 429   PSQR4:858  
##  Khá d<U+1ED3>ng ý             : 847              
##  Ð<U+1ED3>ng ý                 :1288              
##  R<U+1EA5>t d<U+1ED3>ng ý      : 322
    ## t <- compareGroups(Res ~ BPE, data = DN_SEM1)
    ## createTable(t)
DN_HCM_SEM5_PSQR_v %>% 
  group_by(BPE, Res) %>% 
  count() %>% 
  ungroup() %>% 
  group_by(BPE) %>% 
  mutate(percent = 100*n / sum(n)) %>% 
  mutate(percent = round(percent, 2)) %>% 
  mutate(bar_text = paste0(percent, "%")) %>% 
  ungroup() -> df_for_ploting
df_for_ploting %>% 
  filter(Res == Res[7]) %>% 
  arrange(percent) %>% # sắp xếp theo %
  pull(BPE) -> order_x
order_x
## [1] PSQR1 PSQR3 PSQR4 PSQR2
## Levels: PSQR1 PSQR2 PSQR3 PSQR4
# Make a draft plot: 
my_colors <- c("#3e6487", "#829cb2", "pink", "pink3", "palevioletred", "rosybrown2", "rosybrown3")
my_font <- "Roboto Condensed"

df_for_ploting %>% 
  mutate(BPE = factor(BPE, levels = order_x), Res = factor(Res, levels = Res[7:1])) -> df_odered
df_odered
## # A tibble: 28 x 5
##    BPE   Res                  n percent bar_text
##    <fct> <fct>            <int>   <dbl> <chr>   
##  1 PSQR1 R<U+1EA5>t không d<U+1ED3>ng ý    24    2.8  2.8%    
##  2 PSQR1 Không d<U+1ED3>ng ý        48    5.59 5.59%   
##  3 PSQR1 Khá không d<U+1ED3>ng ý    73    8.51 8.51%   
##  4 PSQR1 Bình thu<U+1EDD>ng         97   11.3  11.31%  
##  5 PSQR1 Khá d<U+1ED3>ng ý         244   28.4  28.44%  
##  6 PSQR1 Ð<U+1ED3>ng ý             303   35.3  35.31%  
##  7 PSQR1 R<U+1EA5>t d<U+1ED3>ng ý          69    8.04 8.04%   
##  8 PSQR2 R<U+1EA5>t không d<U+1ED3>ng ý    12    1.4  1.4%    
##  9 PSQR2 Không d<U+1ED3>ng ý        31    3.61 3.61%   
## 10 PSQR2 Khá không d<U+1ED3>ng ý    56    6.53 6.53%   
## # ... with 18 more rows
library(extrafont)
theme_set(theme_minimal())
gg_v <- df_odered %>% 
  ggplot(aes(x = BPE, y = percent, fill = Res)) + 
  geom_col(width = 0.8) + 
  coord_flip() + 
  scale_fill_manual(values = my_colors[7:1], name = "") + 
  theme(legend.position = "top") + 
  theme(text = element_text(family = my_font)) + 
  guides(fill = guide_legend(reverse = TRUE)) + 
  scale_y_continuous(labels = paste0(seq(0, 100, 25), "%"), expand = c(0, 0)) + 
  theme(plot.title = element_text(size = 18), plot.subtitle = element_text(size = 11, color = "grey20")) + 
  theme(axis.text = element_text(color = "grey20", size = 10.2)) + 
  theme(plot.margin = unit(rep(0.7, 4), "cm")) + 
  theme(panel.grid.major.y = element_blank(), panel.grid.minor.x = element_blank()) + 
  theme(legend.key.height = unit(0.15, "mm")) + 
  labs(x = NULL, y = NULL, 
       title = "C\u1EA3m nh\u1EADn c\u1EE7a h\u00E0nh kh\u00E1ch v\u1EC1 ch\u1EA5t l\u01B0\u1EE3ng d\u1ECBch v\u1EE5 li\u00EAn quan \u0111\u1EBFn \u0111\u1ED9 tin c\u1EADy (PSQR) \u0111\u1ED1i v\u1EDBi h\u1EC7 th\u1ED1ng xe bu\u00FDt \u0111\u00F4 th\u1ECB Vi\u1EC7t Nam", 
       subtitle = "Thang \u0111o Likert l\u00E0 lo\u1EA1i thang \u0111o \u0111i\u1EC3m \u0111\u00E1nh gi\u00E1 \u0111\u01B0\u1EE3c s\u1EED d\u1EE5ng ph\u1ED5 bi\u1EBFn trong kh\u1EA3o s\u00E1t. Nghi\u00EAn c\u1EE9u s\u1EED d\u1EE5ng thang \u0111o 7 m\u1EE9c \u0111\u1ED9 t\u01B0\u01A1ng \u1EE9ng v\u1EDBi 1 - R\u1EA5t kh\u00F4ng \u0111\u1ED3ng \u00FD \u0111\u1EBFn 7 - R\u1EA5t \u0111\u1ED3ng \u00FD.")
gg_v
## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

# For displaying percent of "Very Disagree": Điều chỉnh percent để thể hiện giá trị của %
df_odered %>% 
  filter(Res == "R\u1EA5t kh\u00F4ng \u0111\u1ED3ng \u00FD") %>% 
  filter(percent >= 0) -> df_for_text1
df_for_text1
## # A tibble: 4 x 5
##   BPE   Res                  n percent bar_text
##   <fct> <fct>            <int>   <dbl> <chr>   
## 1 PSQR1 R<U+1EA5>t không d<U+1ED3>ng ý    24    2.8  2.8%    
## 2 PSQR2 R<U+1EA5>t không d<U+1ED3>ng ý    12    1.4  1.4%    
## 3 PSQR3 R<U+1EA5>t không d<U+1ED3>ng ý    19    2.21 2.21%   
## 4 PSQR4 R<U+1EA5>t không d<U+1ED3>ng ý    29    3.38 3.38%
# For displaying percent of "Disagree": 
df_odered %>% 
  filter(Res == "Kh\u00F4ng \u0111\u1ED3ng \u00FD") %>% 
  filter(percent >= 0) -> df_for_text2
df_for_text2
## # A tibble: 4 x 5
##   BPE   Res              n percent bar_text
##   <fct> <fct>        <int>   <dbl> <chr>   
## 1 PSQR1 Không d<U+1ED3>ng ý    48    5.59 5.59%   
## 2 PSQR2 Không d<U+1ED3>ng ý    31    3.61 3.61%   
## 3 PSQR3 Không d<U+1ED3>ng ý    42    4.9  4.9%    
## 4 PSQR4 Không d<U+1ED3>ng ý    75    8.74 8.74%
# For displaying percent of "Quite Disagree": 
df_odered %>% 
  filter(Res == "Kh\u00E1 kh\u00F4ng \u0111\u1ED3ng \u00FD") %>% 
  filter(percent >= 0) -> df_for_text3
df_for_text3
## # A tibble: 4 x 5
##   BPE   Res                  n percent bar_text
##   <fct> <fct>            <int>   <dbl> <chr>   
## 1 PSQR1 Khá không d<U+1ED3>ng ý    73    8.51 8.51%   
## 2 PSQR2 Khá không d<U+1ED3>ng ý    56    6.53 6.53%   
## 3 PSQR3 Khá không d<U+1ED3>ng ý    61    7.11 7.11%   
## 4 PSQR4 Khá không d<U+1ED3>ng ý    76    8.86 8.86%
# For displaying percent of "Normal": 
df_odered %>% 
  filter(Res == "B\u00ECnh th\u01B0\u1EDDng") %>% 
  filter(percent >= 0) -> df_for_text4
df_for_text4
## # A tibble: 4 x 5
##   BPE   Res             n percent bar_text
##   <fct> <fct>       <int>   <dbl> <chr>   
## 1 PSQR1 Bình thu<U+1EDD>ng    97    11.3 11.31%  
## 2 PSQR2 Bình thu<U+1EDD>ng   107    12.5 12.47%  
## 3 PSQR3 Bình thu<U+1EDD>ng   126    14.7 14.69%  
## 4 PSQR4 Bình thu<U+1EDD>ng    99    11.5 11.54%
# For displaying percent of "Quite Agree": 
df_odered %>% 
  filter(Res == "Kh\u00E1 \u0111\u1ED3ng \u00FD") %>% 
  filter(percent >= 0) -> df_for_text5
df_for_text5
## # A tibble: 4 x 5
##   BPE   Res            n percent bar_text
##   <fct> <fct>      <int>   <dbl> <chr>   
## 1 PSQR1 Khá d<U+1ED3>ng ý   244    28.4 28.44%  
## 2 PSQR2 Khá d<U+1ED3>ng ý   190    22.1 22.14%  
## 3 PSQR3 Khá d<U+1ED3>ng ý   217    25.3 25.29%  
## 4 PSQR4 Khá d<U+1ED3>ng ý   196    22.8 22.84%
# For displaying percent of "Agree": 
df_odered %>% 
  filter(Res == "\u0110\u1ED3ng \u00FD") %>% 
  filter(percent >= 0) -> df_for_text6
df_for_text6
## # A tibble: 4 x 5
##   BPE   Res        n percent bar_text
##   <fct> <fct>  <int>   <dbl> <chr>   
## 1 PSQR1 Ð<U+1ED3>ng ý   303    35.3 35.31%  
## 2 PSQR2 Ð<U+1ED3>ng ý   363    42.3 42.31%  
## 3 PSQR3 Ð<U+1ED3>ng ý   319    37.2 37.18%  
## 4 PSQR4 Ð<U+1ED3>ng ý   303    35.3 35.31%
# For displaying percent of "Very Agree": 
df_odered %>% 
  filter(Res == "R\u1EA5t \u0111\u1ED3ng \u00FD") %>% 
  filter(percent >= 0) -> df_for_text7
df_for_text7
## # A tibble: 4 x 5
##   BPE   Res            n percent bar_text
##   <fct> <fct>      <int>   <dbl> <chr>   
## 1 PSQR1 R<U+1EA5>t d<U+1ED3>ng ý    69    8.04 8.04%   
## 2 PSQR2 R<U+1EA5>t d<U+1ED3>ng ý    99   11.5  11.54%  
## 3 PSQR3 R<U+1EA5>t d<U+1ED3>ng ý    74    8.62 8.62%   
## 4 PSQR4 R<U+1EA5>t d<U+1ED3>ng ý    80    9.32 9.32%
# For displaying percent of "Very Agree": 
df_odered %>% 
  filter(Res == "R\u1EA5t \u0111\u1ED3ng \u00FD") -> df_for_text
df_for_text
## # A tibble: 4 x 5
##   BPE   Res            n percent bar_text
##   <fct> <fct>      <int>   <dbl> <chr>   
## 1 PSQR1 R<U+1EA5>t d<U+1ED3>ng ý    69    8.04 8.04%   
## 2 PSQR2 R<U+1EA5>t d<U+1ED3>ng ý    99   11.5  11.54%  
## 3 PSQR3 R<U+1EA5>t d<U+1ED3>ng ý    74    8.62 8.62%   
## 4 PSQR4 R<U+1EA5>t d<U+1ED3>ng ý    80    9.32 9.32%
# Ad text layers-thay đổi giá trị y để thể hiện vị trí ghi text phù hợp
gg_v + 
  geom_text(data = df_for_text1, aes(x = BPE, y = 2, label = bar_text), size = 4, color = "white", family = my_font) + 
  geom_text(data = df_for_text6, aes(x = BPE, y = 100-30, label = bar_text), size = 4, color = "white", family = my_font) +
  geom_text(data = df_for_text7, aes(x = BPE, y = 100-2, label = bar_text), size = 4, color = "white", family = my_font)
## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database
## Warning in grid.Call.graphics(C_text, as.graphicsAnnot(x$label), x$x, x$y, :
## font family not found in Windows font database
## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

3.8.11. Construct SAT- Nhãn tiếng anh

# Plot Likert graph for people in both cities for construct IMA
library(tidyverse)
library(compareGroups)
head(DN_HCM_SEM5_SAT)
##   Res  BPE
## 1   6 SAT1
## 2   5 SAT1
## 3   2 SAT1
## 4   5 SAT1
## 5   4 SAT1
## 6   4 SAT1
dim(DN_HCM_SEM5_SAT)
## [1] 2574    2
attach(DN_HCM_SEM5_SAT)
## The following objects are masked from DN_HCM_SEM5_PSQR:
## 
##     BPE, Res
## The following objects are masked from DN_HCM_SEM5_PSQP:
## 
##     BPE, Res
## The following objects are masked from DN_HCM_SEM5_PSQC:
## 
##     BPE, Res
## The following objects are masked from DN_HCM_SEM5_PSQT:
## 
##     BPE, Res
## The following objects are masked from DN_HCM_SEM5_PSB:
## 
##     BPE, Res
## The following objects are masked from HCM_SEM5:
## 
##     BPE, Res
## The following objects are masked from DN_SEM5:
## 
##     BPE, Res
## The following objects are masked from DN_HCM_SEM5:
## 
##     BPE, Res
DN_HCM_SEM5_SAT = within(DN_HCM_SEM5_SAT, {
  Res = factor(Res, labels = c("Very Disagree", "Disagree", "Quite Disagree", "Normal", "Quite Agree", "Agree", "Very Agree"))
  BPE = factor(BPE, labels = c("SAT1", "SAT2", "SAT3"))
  })
str(DN_HCM_SEM5_SAT)
## 'data.frame':    2574 obs. of  2 variables:
##  $ Res: Factor w/ 7 levels "Very Disagree",..: 6 5 2 5 4 4 2 7 5 7 ...
##  $ BPE: Factor w/ 3 levels "SAT1","SAT2",..: 1 1 1 1 1 1 1 1 1 1 ...
summary(DN_HCM_SEM5_SAT)
##              Res         BPE     
##  Very Disagree :  23   SAT1:858  
##  Disagree      :  54   SAT2:858  
##  Quite Disagree:  90   SAT3:858  
##  Normal        : 289             
##  Quite Agree   : 625             
##  Agree         :1132             
##  Very Agree    : 361
    ## t <- compareGroups(Res ~ BPE, data = DN_SEM1)
    ## createTable(t)
DN_HCM_SEM5_SAT %>% 
  group_by(BPE, Res) %>% 
  count() %>% 
  ungroup() %>% 
  group_by(BPE) %>% 
  mutate(percent = 100*n / sum(n)) %>% 
  mutate(percent = round(percent, 2)) %>% 
  mutate(bar_text = paste0(percent, "%")) %>% 
  ungroup() -> df_for_ploting
df_for_ploting %>% 
  filter(Res == Res[7]) %>% 
  arrange(percent) %>% # sắp xếp theo %
  pull(BPE) -> order_x
order_x
## [1] SAT1 SAT3 SAT2
## Levels: SAT1 SAT2 SAT3
# Make a draft plot: 
my_colors <- c("#3e6487", "#829cb2", "pink", "pink3", "palevioletred", "rosybrown2", "rosybrown3")
my_font <- "Roboto Condensed"

df_for_ploting %>% 
  mutate(BPE = factor(BPE, levels = order_x), Res = factor(Res, levels = Res[7:1])) -> df_odered
df_odered
## # A tibble: 21 x 5
##    BPE   Res                n percent bar_text
##    <fct> <fct>          <int>   <dbl> <chr>   
##  1 SAT1  Very Disagree      9    1.05 1.05%   
##  2 SAT1  Disagree          23    2.68 2.68%   
##  3 SAT1  Quite Disagree    37    4.31 4.31%   
##  4 SAT1  Normal           110   12.8  12.82%  
##  5 SAT1  Quite Agree      215   25.1  25.06%  
##  6 SAT1  Agree            359   41.8  41.84%  
##  7 SAT1  Very Agree       105   12.2  12.24%  
##  8 SAT2  Very Disagree      6    0.7  0.7%    
##  9 SAT2  Disagree          14    1.63 1.63%   
## 10 SAT2  Quite Disagree    27    3.15 3.15%   
## # ... with 11 more rows
library(extrafont)
theme_set(theme_minimal())
gg <- df_odered %>% 
  ggplot(aes(x = BPE, y = percent, fill = Res)) + 
  geom_col(width = 0.8) + 
  coord_flip() + 
  scale_fill_manual(values = my_colors[7:1], name = "") + 
  theme(legend.position = "top") + 
  theme(text = element_text(family = my_font)) + 
  guides(fill = guide_legend(reverse = TRUE)) + 
  scale_y_continuous(labels = paste0(seq(0, 100, 25), "%"), expand = c(0, 0)) + 
  theme(plot.title = element_text(size = 18), plot.subtitle = element_text(size = 11, color = "grey20")) + 
  theme(axis.text = element_text(color = "grey20", size = 10.2)) + 
  theme(plot.margin = unit(rep(0.7, 4), "cm")) + 
  theme(panel.grid.major.y = element_blank(), panel.grid.minor.x = element_blank()) + 
  theme(legend.key.height = unit(0.15, "mm")) + 
  labs(x = NULL, y = NULL, 
       title = "Perceived satisfaction (SAT) of passengers in urban areas of Viet Nam", 
       subtitle = "Likert scale is a type of rating scale commonly used in surveys. When responding to a Likert type question,\nrespondents simply state their level of agreement or disagreement on a symmetric agree-disagree scale.")
gg
## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

# For displaying percent of "Very Disagree": Điều chỉnh percent để thể hiện giá trị của %
df_odered %>% 
  filter(Res == "Very Disagree") %>% 
  filter(percent >= 0) -> df_for_text1
df_for_text1
## # A tibble: 3 x 5
##   BPE   Res               n percent bar_text
##   <fct> <fct>         <int>   <dbl> <chr>   
## 1 SAT1  Very Disagree     9    1.05 1.05%   
## 2 SAT2  Very Disagree     6    0.7  0.7%    
## 3 SAT3  Very Disagree     8    0.93 0.93%
# For displaying percent of "Disagree": 
df_odered %>% 
  filter(Res == "Disagree") %>% 
  filter(percent >= 3) -> df_for_text2
df_for_text2
## # A tibble: 0 x 5
## # ... with 5 variables: BPE <fct>, Res <fct>, n <int>, percent <dbl>,
## #   bar_text <chr>
# For displaying percent of "Quite Disagree": 
df_odered %>% 
  filter(Res == "Quite Disagree") %>% 
  filter(percent >= 0) -> df_for_text3
df_for_text3
## # A tibble: 3 x 5
##   BPE   Res                n percent bar_text
##   <fct> <fct>          <int>   <dbl> <chr>   
## 1 SAT1  Quite Disagree    37    4.31 4.31%   
## 2 SAT2  Quite Disagree    27    3.15 3.15%   
## 3 SAT3  Quite Disagree    26    3.03 3.03%
# For displaying percent of "Normal": 
df_odered %>% 
  filter(Res == "Normal") %>% 
  filter(percent >= 0) -> df_for_text4
df_for_text4
## # A tibble: 3 x 5
##   BPE   Res        n percent bar_text
##   <fct> <fct>  <int>   <dbl> <chr>   
## 1 SAT1  Normal   110   12.8  12.82%  
## 2 SAT2  Normal   100   11.7  11.66%  
## 3 SAT3  Normal    79    9.21 9.21%
# For displaying percent of "Quite Agree": 
df_odered %>% 
  filter(Res == "Quite Agree") %>% 
  filter(percent >= 0) -> df_for_text5
df_for_text5
## # A tibble: 3 x 5
##   BPE   Res             n percent bar_text
##   <fct> <fct>       <int>   <dbl> <chr>   
## 1 SAT1  Quite Agree   215    25.1 25.06%  
## 2 SAT2  Quite Agree   197    23.0 22.96%  
## 3 SAT3  Quite Agree   213    24.8 24.83%
# For displaying percent of "Agree": 
df_odered %>% 
  filter(Res == "Agree") %>% 
  filter(percent >= 0) -> df_for_text6
df_for_text6
## # A tibble: 3 x 5
##   BPE   Res       n percent bar_text
##   <fct> <fct> <int>   <dbl> <chr>   
## 1 SAT1  Agree   359    41.8 41.84%  
## 2 SAT2  Agree   382    44.5 44.52%  
## 3 SAT3  Agree   391    45.6 45.57%
# For displaying percent of "Very Agree": 
df_odered %>% 
  filter(Res == "Very Agree") %>% 
  filter(percent >= 0) -> df_for_text7 # Chỉ thể hiện giá trị có % lựa chọn >0
df_for_text7
## # A tibble: 3 x 5
##   BPE   Res            n percent bar_text
##   <fct> <fct>      <int>   <dbl> <chr>   
## 1 SAT1  Very Agree   105    12.2 12.24%  
## 2 SAT2  Very Agree   132    15.4 15.38%  
## 3 SAT3  Very Agree   124    14.4 14.45%
# For displaying percent of "Very Agree": 
df_odered %>% 
  filter(Res == "Very Agree") -> df_for_text
df_for_text
## # A tibble: 3 x 5
##   BPE   Res            n percent bar_text
##   <fct> <fct>      <int>   <dbl> <chr>   
## 1 SAT1  Very Agree   105    12.2 12.24%  
## 2 SAT2  Very Agree   132    15.4 15.38%  
## 3 SAT3  Very Agree   124    14.4 14.45%
# Ad text layers-thay đổi giá trị y để thể hiện vị trí ghi text phù hợp
gg + 
  geom_text(data = df_for_text1, aes(x = BPE, y = 3, label = bar_text), size = 4, color = "white", family = my_font) + 
  geom_text(data = df_for_text4, aes(x = BPE, y = 13, label = bar_text), size = 4, color = "white", family = my_font) +
  geom_text(data = df_for_text5, aes(x = BPE, y = 32, label = bar_text), size = 4, color = "white", family = my_font) +
  geom_text(data = df_for_text6, aes(x = BPE, y = 100-30, label = bar_text), size = 4, color = "white", family = my_font) +
  geom_text(data = df_for_text7, aes(x = BPE, y = 100-4, label = bar_text), size = 4, color = "white", family = my_font)
## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database
## Warning in grid.Call.graphics(C_text, as.graphicsAnnot(x$label), x$x, x$y, :
## font family not found in Windows font database
## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

3.8.12. Construct SAT- Nhãn tiếng việt

DN_HCM_SEM5_SAT_v = within(DN_HCM_SEM5_SAT, {
  Res = factor(Res, labels = c("R\u1EA5t kh\u00F4ng \u0111\u1ED3ng \u00FD", "Kh\u00F4ng \u0111\u1ED3ng \u00FD", "Kh\u00E1 kh\u00F4ng \u0111\u1ED3ng \u00FD", "B\u00ECnh th\u01B0\u1EDDng", "Kh\u00E1 \u0111\u1ED3ng \u00FD", "\u0110\u1ED3ng \u00FD", "R\u1EA5t \u0111\u1ED3ng \u00FD"))
  BPE = factor(BPE, labels = c("SAT1", "SAT2", "SAT3"))
  })
str(DN_HCM_SEM5_SAT_v)
## 'data.frame':    2574 obs. of  2 variables:
##  $ Res: Factor w/ 7 levels "R<U+1EA5>t không d<U+1ED3>ng ý",..: 6 5 2 5 4 4 2 7 5 7 ...
##  $ BPE: Factor w/ 3 levels "SAT1","SAT2",..: 1 1 1 1 1 1 1 1 1 1 ...
summary(DN_HCM_SEM5_SAT_v)
##                              Res         BPE     
##  R<U+1EA5>t không d<U+1ED3>ng ý:  23   SAT1:858  
##  Không d<U+1ED3>ng ý           :  54   SAT2:858  
##  Khá không d<U+1ED3>ng ý       :  90   SAT3:858  
##  Bình thu<U+1EDD>ng            : 289             
##  Khá d<U+1ED3>ng ý             : 625             
##  Ð<U+1ED3>ng ý                 :1132             
##  R<U+1EA5>t d<U+1ED3>ng ý      : 361
    ## t <- compareGroups(Res ~ BPE, data = DN_SEM1)
    ## createTable(t)
DN_HCM_SEM5_SAT_v %>% 
  group_by(BPE, Res) %>% 
  count() %>% 
  ungroup() %>% 
  group_by(BPE) %>% 
  mutate(percent = 100*n / sum(n)) %>% 
  mutate(percent = round(percent, 2)) %>% 
  mutate(bar_text = paste0(percent, "%")) %>% 
  ungroup() -> df_for_ploting
df_for_ploting %>% 
  filter(Res == Res[7]) %>% 
  arrange(percent) %>% # sắp xếp theo %
  pull(BPE) -> order_x
order_x
## [1] SAT1 SAT3 SAT2
## Levels: SAT1 SAT2 SAT3
# Make a draft plot: 
my_colors <- c("#3e6487", "#829cb2", "pink", "pink3", "palevioletred", "rosybrown2", "rosybrown3")
my_font <- "Roboto Condensed"

df_for_ploting %>% 
  mutate(BPE = factor(BPE, levels = order_x), Res = factor(Res, levels = Res[7:1])) -> df_odered
df_odered
## # A tibble: 21 x 5
##    BPE   Res                  n percent bar_text
##    <fct> <fct>            <int>   <dbl> <chr>   
##  1 SAT1  R<U+1EA5>t không d<U+1ED3>ng ý     9    1.05 1.05%   
##  2 SAT1  Không d<U+1ED3>ng ý        23    2.68 2.68%   
##  3 SAT1  Khá không d<U+1ED3>ng ý    37    4.31 4.31%   
##  4 SAT1  Bình thu<U+1EDD>ng        110   12.8  12.82%  
##  5 SAT1  Khá d<U+1ED3>ng ý         215   25.1  25.06%  
##  6 SAT1  Ð<U+1ED3>ng ý             359   41.8  41.84%  
##  7 SAT1  R<U+1EA5>t d<U+1ED3>ng ý         105   12.2  12.24%  
##  8 SAT2  R<U+1EA5>t không d<U+1ED3>ng ý     6    0.7  0.7%    
##  9 SAT2  Không d<U+1ED3>ng ý        14    1.63 1.63%   
## 10 SAT2  Khá không d<U+1ED3>ng ý    27    3.15 3.15%   
## # ... with 11 more rows
library(extrafont)
theme_set(theme_minimal())
gg_v <- df_odered %>% 
  ggplot(aes(x = BPE, y = percent, fill = Res)) + 
  geom_col(width = 0.8) + 
  coord_flip() + 
  scale_fill_manual(values = my_colors[7:1], name = "") + 
  theme(legend.position = "top") + 
  theme(text = element_text(family = my_font)) + 
  guides(fill = guide_legend(reverse = TRUE)) + 
  scale_y_continuous(labels = paste0(seq(0, 100, 25), "%"), expand = c(0, 0)) + 
  theme(plot.title = element_text(size = 18), plot.subtitle = element_text(size = 11, color = "grey20")) + 
  theme(axis.text = element_text(color = "grey20", size = 10.2)) + 
  theme(plot.margin = unit(rep(0.7, 4), "cm")) + 
  theme(panel.grid.major.y = element_blank(), panel.grid.minor.x = element_blank()) + 
  theme(legend.key.height = unit(0.15, "mm")) + 
  labs(x = NULL, y = NULL, 
       title = "C\u1EA3m nh\u1EADn h\u00E0i l\u00F2ng c\u1EE7a h\u00E0nh kh\u00E1ch (SAT) \u0111\u1ED1i v\u1EDBi h\u1EC7 th\u1ED1ng xe bu\u00FDt \u0111\u00F4 th\u1ECB Vi\u1EC7t Nam", 
       subtitle = "Thang \u0111o Likert l\u00E0 lo\u1EA1i thang \u0111o \u0111i\u1EC3m \u0111\u00E1nh gi\u00E1 \u0111\u01B0\u1EE3c s\u1EED d\u1EE5ng ph\u1ED5 bi\u1EBFn trong kh\u1EA3o s\u00E1t. Nghi\u00EAn c\u1EE9u s\u1EED d\u1EE5ng thang \u0111o 7 m\u1EE9c \u0111\u1ED9 t\u01B0\u01A1ng \u1EE9ng v\u1EDBi 1 - R\u1EA5t kh\u00F4ng \u0111\u1ED3ng \u00FD \u0111\u1EBFn 7 - R\u1EA5t \u0111\u1ED3ng \u00FD.")
gg_v
## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

# For displaying percent of "Very Disagree": Điều chỉnh percent để thể hiện giá trị của %
df_odered %>% 
  filter(Res == "R\u1EA5t kh\u00F4ng \u0111\u1ED3ng \u00FD") %>% 
  filter(percent >= 0) -> df_for_text1
df_for_text1
## # A tibble: 3 x 5
##   BPE   Res                  n percent bar_text
##   <fct> <fct>            <int>   <dbl> <chr>   
## 1 SAT1  R<U+1EA5>t không d<U+1ED3>ng ý     9    1.05 1.05%   
## 2 SAT2  R<U+1EA5>t không d<U+1ED3>ng ý     6    0.7  0.7%    
## 3 SAT3  R<U+1EA5>t không d<U+1ED3>ng ý     8    0.93 0.93%
# For displaying percent of "Disagree": 
df_odered %>% 
  filter(Res == "Kh\u00F4ng \u0111\u1ED3ng \u00FD") %>% 
  filter(percent >= 0) -> df_for_text2
df_for_text2
## # A tibble: 3 x 5
##   BPE   Res              n percent bar_text
##   <fct> <fct>        <int>   <dbl> <chr>   
## 1 SAT1  Không d<U+1ED3>ng ý    23    2.68 2.68%   
## 2 SAT2  Không d<U+1ED3>ng ý    14    1.63 1.63%   
## 3 SAT3  Không d<U+1ED3>ng ý    17    1.98 1.98%
# For displaying percent of "Quite Disagree": 
df_odered %>% 
  filter(Res == "Kh\u00E1 kh\u00F4ng \u0111\u1ED3ng \u00FD") %>% 
  filter(percent >= 0) -> df_for_text3
df_for_text3
## # A tibble: 3 x 5
##   BPE   Res                  n percent bar_text
##   <fct> <fct>            <int>   <dbl> <chr>   
## 1 SAT1  Khá không d<U+1ED3>ng ý    37    4.31 4.31%   
## 2 SAT2  Khá không d<U+1ED3>ng ý    27    3.15 3.15%   
## 3 SAT3  Khá không d<U+1ED3>ng ý    26    3.03 3.03%
# For displaying percent of "Normal": 
df_odered %>% 
  filter(Res == "B\u00ECnh th\u01B0\u1EDDng") %>% 
  filter(percent >= 0) -> df_for_text4
df_for_text4
## # A tibble: 3 x 5
##   BPE   Res             n percent bar_text
##   <fct> <fct>       <int>   <dbl> <chr>   
## 1 SAT1  Bình thu<U+1EDD>ng   110   12.8  12.82%  
## 2 SAT2  Bình thu<U+1EDD>ng   100   11.7  11.66%  
## 3 SAT3  Bình thu<U+1EDD>ng    79    9.21 9.21%
# For displaying percent of "Quite Agree": 
df_odered %>% 
  filter(Res == "Kh\u00E1 \u0111\u1ED3ng \u00FD") %>% 
  filter(percent >= 0) -> df_for_text5
df_for_text5
## # A tibble: 3 x 5
##   BPE   Res            n percent bar_text
##   <fct> <fct>      <int>   <dbl> <chr>   
## 1 SAT1  Khá d<U+1ED3>ng ý   215    25.1 25.06%  
## 2 SAT2  Khá d<U+1ED3>ng ý   197    23.0 22.96%  
## 3 SAT3  Khá d<U+1ED3>ng ý   213    24.8 24.83%
# For displaying percent of "Agree": 
df_odered %>% 
  filter(Res == "\u0110\u1ED3ng \u00FD") %>% 
  filter(percent >= 0) -> df_for_text6
df_for_text6
## # A tibble: 3 x 5
##   BPE   Res        n percent bar_text
##   <fct> <fct>  <int>   <dbl> <chr>   
## 1 SAT1  Ð<U+1ED3>ng ý   359    41.8 41.84%  
## 2 SAT2  Ð<U+1ED3>ng ý   382    44.5 44.52%  
## 3 SAT3  Ð<U+1ED3>ng ý   391    45.6 45.57%
# For displaying percent of "Very Agree": 
df_odered %>% 
  filter(Res == "R\u1EA5t \u0111\u1ED3ng \u00FD") %>% 
  filter(percent >= 0) -> df_for_text7
df_for_text7
## # A tibble: 3 x 5
##   BPE   Res            n percent bar_text
##   <fct> <fct>      <int>   <dbl> <chr>   
## 1 SAT1  R<U+1EA5>t d<U+1ED3>ng ý   105    12.2 12.24%  
## 2 SAT2  R<U+1EA5>t d<U+1ED3>ng ý   132    15.4 15.38%  
## 3 SAT3  R<U+1EA5>t d<U+1ED3>ng ý   124    14.4 14.45%
# For displaying percent of "Very Agree": 
df_odered %>% 
  filter(Res == "R\u1EA5t \u0111\u1ED3ng \u00FD") -> df_for_text
df_for_text
## # A tibble: 3 x 5
##   BPE   Res            n percent bar_text
##   <fct> <fct>      <int>   <dbl> <chr>   
## 1 SAT1  R<U+1EA5>t d<U+1ED3>ng ý   105    12.2 12.24%  
## 2 SAT2  R<U+1EA5>t d<U+1ED3>ng ý   132    15.4 15.38%  
## 3 SAT3  R<U+1EA5>t d<U+1ED3>ng ý   124    14.4 14.45%
# Ad text layers-thay đổi giá trị y để thể hiện vị trí ghi text phù hợp
gg_v + 
  geom_text(data = df_for_text1, aes(x = BPE, y = 3, label = bar_text), size = 4, color = "white", family = my_font) + 
  geom_text(data = df_for_text4, aes(x = BPE, y = 13, label = bar_text), size = 4, color = "white", family = my_font) +
  geom_text(data = df_for_text5, aes(x = BPE, y = 32, label = bar_text), size = 4, color = "white", family = my_font) +
  geom_text(data = df_for_text6, aes(x = BPE, y = 100-30, label = bar_text), size = 4, color = "white", family = my_font) +
  geom_text(data = df_for_text7, aes(x = BPE, y = 100-4, label = bar_text), size = 4, color = "white", family = my_font)
## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database
## Warning in grid.Call.graphics(C_text, as.graphicsAnnot(x$label), x$x, x$y, :
## font family not found in Windows font database
## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

3.8.13. Construct IMA- Nhãn tiếng anh

# Plot Likert graph for people in both cities for construct IMA
library(tidyverse)
library(compareGroups)
head(DN_HCM_SEM5_IMA)
##   Res  BPE
## 1   6 IMA1
## 2   4 IMA1
## 3   4 IMA1
## 4   5 IMA1
## 5   5 IMA1
## 6   4 IMA1
dim(DN_HCM_SEM5_IMA)
## [1] 4290    2
attach(DN_HCM_SEM5_IMA)
## The following objects are masked from DN_HCM_SEM5_SAT:
## 
##     BPE, Res
## The following objects are masked from DN_HCM_SEM5_PSQR:
## 
##     BPE, Res
## The following objects are masked from DN_HCM_SEM5_PSQP:
## 
##     BPE, Res
## The following objects are masked from DN_HCM_SEM5_PSQC:
## 
##     BPE, Res
## The following objects are masked from DN_HCM_SEM5_PSQT:
## 
##     BPE, Res
## The following objects are masked from DN_HCM_SEM5_PSB:
## 
##     BPE, Res
## The following objects are masked from HCM_SEM5:
## 
##     BPE, Res
## The following objects are masked from DN_SEM5:
## 
##     BPE, Res
## The following objects are masked from DN_HCM_SEM5:
## 
##     BPE, Res
DN_HCM_SEM5_IMA = within(DN_HCM_SEM5_IMA, {
  Res = factor(Res, labels = c("Very Disagree", "Disagree", "Quite Disagree", "Normal", "Quite Agree", "Agree", "Very Agree"))
  BPE = factor(BPE, labels = c("IMA1", "IMA2", "IMA3", "IMA4", "IMA5"))
  })
str(DN_HCM_SEM5_IMA)
## 'data.frame':    4290 obs. of  2 variables:
##  $ Res: Factor w/ 7 levels "Very Disagree",..: 6 4 4 5 5 4 2 6 5 6 ...
##  $ BPE: Factor w/ 5 levels "IMA1","IMA2",..: 1 1 1 1 1 1 1 1 1 1 ...
summary(DN_HCM_SEM5_IMA)
##              Res         BPE     
##  Very Disagree :  47   IMA1:858  
##  Disagree      :  82   IMA2:858  
##  Quite Disagree: 126   IMA3:858  
##  Normal        : 657   IMA4:858  
##  Quite Agree   :1056   IMA5:858  
##  Agree         :1945             
##  Very Agree    : 377
    ## t <- compareGroups(Res ~ BPE, data = DN_SEM1)
    ## createTable(t)
DN_HCM_SEM5_IMA %>% 
  group_by(BPE, Res) %>% 
  count() %>% 
  ungroup() %>% 
  group_by(BPE) %>% 
  mutate(percent = 100*n / sum(n)) %>% 
  mutate(percent = round(percent, 2)) %>% 
  mutate(bar_text = paste0(percent, "%")) %>% 
  ungroup() -> df_for_ploting
df_for_ploting %>% 
  filter(Res == Res[7]) %>% 
  arrange(percent) %>% # sắp xếp theo %
  pull(BPE) -> order_x
order_x
## [1] IMA1 IMA2 IMA3 IMA4 IMA5
## Levels: IMA1 IMA2 IMA3 IMA4 IMA5
# Make a draft plot: 
my_colors <- c("#3e6487", "#829cb2", "pink", "pink3", "palevioletred", "rosybrown2", "rosybrown3")
my_font <- "Roboto Condensed"

df_for_ploting %>% 
  mutate(BPE = factor(BPE, levels = order_x), Res = factor(Res, levels = Res[7:1])) -> df_odered
df_odered
## # A tibble: 35 x 5
##    BPE   Res                n percent bar_text
##    <fct> <fct>          <int>   <dbl> <chr>   
##  1 IMA1  Very Disagree      6    0.7  0.7%    
##  2 IMA1  Disagree          19    2.21 2.21%   
##  3 IMA1  Quite Disagree    33    3.85 3.85%   
##  4 IMA1  Normal           154   18.0  17.95%  
##  5 IMA1  Quite Agree      230   26.8  26.81%  
##  6 IMA1  Agree            351   40.9  40.91%  
##  7 IMA1  Very Agree        65    7.58 7.58%   
##  8 IMA2  Very Disagree     11    1.28 1.28%   
##  9 IMA2  Disagree          18    2.1  2.1%    
## 10 IMA2  Quite Disagree    26    3.03 3.03%   
## # ... with 25 more rows
library(extrafont)
theme_set(theme_minimal())
gg <- df_odered %>% 
  ggplot(aes(x = BPE, y = percent, fill = Res)) + 
  geom_col(width = 0.8) + 
  coord_flip() + 
  scale_fill_manual(values = my_colors[7:1], name = "") + 
  theme(legend.position = "top") + 
  theme(text = element_text(family = my_font)) + 
  guides(fill = guide_legend(reverse = TRUE)) + 
  scale_y_continuous(labels = paste0(seq(0, 100, 25), "%"), expand = c(0, 0)) + 
  theme(plot.title = element_text(size = 18), plot.subtitle = element_text(size = 11, color = "grey20")) + 
  theme(axis.text = element_text(color = "grey20", size = 10.2)) + 
  theme(plot.margin = unit(rep(0.7, 4), "cm")) + 
  theme(panel.grid.major.y = element_blank(), panel.grid.minor.x = element_blank()) + 
  theme(legend.key.height = unit(0.15, "mm")) + 
  labs(x = NULL, y = NULL, 
       title = "Perceived image (IMA) of passengers in urban areas of Viet Nam", 
       subtitle = "Likert scale is a type of rating scale commonly used in surveys. When responding to a Likert type question,\nrespondents simply state their level of agreement or disagreement on a symmetric agree-disagree scale.")
gg
## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

# For displaying percent of "Very Disagree": Điều chỉnh percent để thể hiện giá trị của %
df_odered %>% 
  filter(Res == "Very Disagree") %>% 
  filter(percent >= 0) -> df_for_text1
df_for_text1
## # A tibble: 5 x 5
##   BPE   Res               n percent bar_text
##   <fct> <fct>         <int>   <dbl> <chr>   
## 1 IMA1  Very Disagree     6    0.7  0.7%    
## 2 IMA2  Very Disagree    11    1.28 1.28%   
## 3 IMA3  Very Disagree    11    1.28 1.28%   
## 4 IMA4  Very Disagree    13    1.52 1.52%   
## 5 IMA5  Very Disagree     6    0.7  0.7%
# For displaying percent of "Disagree": 
df_odered %>% 
  filter(Res == "Disagree") %>% 
  filter(percent >= 3) -> df_for_text2
df_for_text2
## # A tibble: 0 x 5
## # ... with 5 variables: BPE <fct>, Res <fct>, n <int>, percent <dbl>,
## #   bar_text <chr>
# For displaying percent of "Quite Disagree": 
df_odered %>% 
  filter(Res == "Quite Disagree") %>% 
  filter(percent >= 0) -> df_for_text3
df_for_text3
## # A tibble: 5 x 5
##   BPE   Res                n percent bar_text
##   <fct> <fct>          <int>   <dbl> <chr>   
## 1 IMA1  Quite Disagree    33    3.85 3.85%   
## 2 IMA2  Quite Disagree    26    3.03 3.03%   
## 3 IMA3  Quite Disagree    21    2.45 2.45%   
## 4 IMA4  Quite Disagree    26    3.03 3.03%   
## 5 IMA5  Quite Disagree    20    2.33 2.33%
# For displaying percent of "Normal": 
df_odered %>% 
  filter(Res == "Normal") %>% 
  filter(percent >= 0) -> df_for_text4
df_for_text4
## # A tibble: 5 x 5
##   BPE   Res        n percent bar_text
##   <fct> <fct>  <int>   <dbl> <chr>   
## 1 IMA1  Normal   154    18.0 17.95%  
## 2 IMA2  Normal   158    18.4 18.41%  
## 3 IMA3  Normal   128    14.9 14.92%  
## 4 IMA4  Normal   113    13.2 13.17%  
## 5 IMA5  Normal   104    12.1 12.12%
# For displaying percent of "Quite Agree": 
df_odered %>% 
  filter(Res == "Quite Agree") %>% 
  filter(percent >= 0) -> df_for_text5
df_for_text5
## # A tibble: 5 x 5
##   BPE   Res             n percent bar_text
##   <fct> <fct>       <int>   <dbl> <chr>   
## 1 IMA1  Quite Agree   230    26.8 26.81%  
## 2 IMA2  Quite Agree   214    24.9 24.94%  
## 3 IMA3  Quite Agree   207    24.1 24.13%  
## 4 IMA4  Quite Agree   201    23.4 23.43%  
## 5 IMA5  Quite Agree   204    23.8 23.78%
# For displaying percent of "Agree": 
df_odered %>% 
  filter(Res == "Agree") %>% 
  filter(percent >= 0) -> df_for_text6
df_for_text6
## # A tibble: 5 x 5
##   BPE   Res       n percent bar_text
##   <fct> <fct> <int>   <dbl> <chr>   
## 1 IMA1  Agree   351    40.9 40.91%  
## 2 IMA2  Agree   365    42.5 42.54%  
## 3 IMA3  Agree   403    47.0 46.97%  
## 4 IMA4  Agree   406    47.3 47.32%  
## 5 IMA5  Agree   420    49.0 48.95%
# For displaying percent of "Very Agree": 
df_odered %>% 
  filter(Res == "Very Agree") %>% 
  filter(percent >= 0) -> df_for_text7 # Chỉ thể hiện giá trị có % lựa chọn >0
df_for_text7
## # A tibble: 5 x 5
##   BPE   Res            n percent bar_text
##   <fct> <fct>      <int>   <dbl> <chr>   
## 1 IMA1  Very Agree    65    7.58 7.58%   
## 2 IMA2  Very Agree    66    7.69 7.69%   
## 3 IMA3  Very Agree    78    9.09 9.09%   
## 4 IMA4  Very Agree    84    9.79 9.79%   
## 5 IMA5  Very Agree    84    9.79 9.79%
# For displaying percent of "Very Agree": 
df_odered %>% 
  filter(Res == "Very Agree") -> df_for_text
df_for_text
## # A tibble: 5 x 5
##   BPE   Res            n percent bar_text
##   <fct> <fct>      <int>   <dbl> <chr>   
## 1 IMA1  Very Agree    65    7.58 7.58%   
## 2 IMA2  Very Agree    66    7.69 7.69%   
## 3 IMA3  Very Agree    78    9.09 9.09%   
## 4 IMA4  Very Agree    84    9.79 9.79%   
## 5 IMA5  Very Agree    84    9.79 9.79%
# Ad text layers-thay đổi giá trị y để thể hiện vị trí ghi text phù hợp
gg + 
  geom_text(data = df_for_text1, aes(x = BPE, y = 3, label = bar_text), size = 4, color = "white", family = my_font) + 
  geom_text(data = df_for_text4, aes(x = BPE, y = 13, label = bar_text), size = 4, color = "white", family = my_font) +
  geom_text(data = df_for_text5, aes(x = BPE, y = 32, label = bar_text), size = 4, color = "white", family = my_font) +
  geom_text(data = df_for_text6, aes(x = BPE, y = 100-30, label = bar_text), size = 4, color = "white", family = my_font) +
  geom_text(data = df_for_text7, aes(x = BPE, y = 100-4, label = bar_text), size = 4, color = "white", family = my_font)
## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database
## Warning in grid.Call.graphics(C_text, as.graphicsAnnot(x$label), x$x, x$y, :
## font family not found in Windows font database
## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

3.8.14. Construct IMA- Nhãn tiếng việt

DN_HCM_SEM5_IMA_v = within(DN_HCM_SEM5_IMA, {
  Res = factor(Res, labels = c("R\u1EA5t kh\u00F4ng \u0111\u1ED3ng \u00FD", "Kh\u00F4ng \u0111\u1ED3ng \u00FD", "Kh\u00E1 kh\u00F4ng \u0111\u1ED3ng \u00FD", "B\u00ECnh th\u01B0\u1EDDng", "Kh\u00E1 \u0111\u1ED3ng \u00FD", "\u0110\u1ED3ng \u00FD", "R\u1EA5t \u0111\u1ED3ng \u00FD"))
  BPE = factor(BPE, labels = c("IMA1", "IMA2", "IMA3", "IMA4", "IMA5"))
  })
str(DN_HCM_SEM5_IMA_v)
## 'data.frame':    4290 obs. of  2 variables:
##  $ Res: Factor w/ 7 levels "R<U+1EA5>t không d<U+1ED3>ng ý",..: 6 4 4 5 5 4 2 6 5 6 ...
##  $ BPE: Factor w/ 5 levels "IMA1","IMA2",..: 1 1 1 1 1 1 1 1 1 1 ...
summary(DN_HCM_SEM5_IMA_v)
##                              Res         BPE     
##  R<U+1EA5>t không d<U+1ED3>ng ý:  47   IMA1:858  
##  Không d<U+1ED3>ng ý           :  82   IMA2:858  
##  Khá không d<U+1ED3>ng ý       : 126   IMA3:858  
##  Bình thu<U+1EDD>ng            : 657   IMA4:858  
##  Khá d<U+1ED3>ng ý             :1056   IMA5:858  
##  Ð<U+1ED3>ng ý                 :1945             
##  R<U+1EA5>t d<U+1ED3>ng ý      : 377
    ## t <- compareGroups(Res ~ BPE, data = DN_SEM1)
    ## createTable(t)
DN_HCM_SEM5_IMA_v %>% 
  group_by(BPE, Res) %>% 
  count() %>% 
  ungroup() %>% 
  group_by(BPE) %>% 
  mutate(percent = 100*n / sum(n)) %>% 
  mutate(percent = round(percent, 2)) %>% 
  mutate(bar_text = paste0(percent, "%")) %>% 
  ungroup() -> df_for_ploting
df_for_ploting %>% 
  filter(Res == Res[7]) %>% 
  arrange(percent) %>% # sắp xếp theo %
  pull(BPE) -> order_x
order_x
## [1] IMA1 IMA2 IMA3 IMA4 IMA5
## Levels: IMA1 IMA2 IMA3 IMA4 IMA5
# Make a draft plot: 
my_colors <- c("#3e6487", "#829cb2", "pink", "pink3", "palevioletred", "rosybrown2", "rosybrown3")
my_font <- "Roboto Condensed"

df_for_ploting %>% 
  mutate(BPE = factor(BPE, levels = order_x), Res = factor(Res, levels = Res[7:1])) -> df_odered
df_odered
## # A tibble: 35 x 5
##    BPE   Res                  n percent bar_text
##    <fct> <fct>            <int>   <dbl> <chr>   
##  1 IMA1  R<U+1EA5>t không d<U+1ED3>ng ý     6    0.7  0.7%    
##  2 IMA1  Không d<U+1ED3>ng ý        19    2.21 2.21%   
##  3 IMA1  Khá không d<U+1ED3>ng ý    33    3.85 3.85%   
##  4 IMA1  Bình thu<U+1EDD>ng        154   18.0  17.95%  
##  5 IMA1  Khá d<U+1ED3>ng ý         230   26.8  26.81%  
##  6 IMA1  Ð<U+1ED3>ng ý             351   40.9  40.91%  
##  7 IMA1  R<U+1EA5>t d<U+1ED3>ng ý          65    7.58 7.58%   
##  8 IMA2  R<U+1EA5>t không d<U+1ED3>ng ý    11    1.28 1.28%   
##  9 IMA2  Không d<U+1ED3>ng ý        18    2.1  2.1%    
## 10 IMA2  Khá không d<U+1ED3>ng ý    26    3.03 3.03%   
## # ... with 25 more rows
library(extrafont)
theme_set(theme_minimal())
gg_v <- df_odered %>% 
  ggplot(aes(x = BPE, y = percent, fill = Res)) + 
  geom_col(width = 0.8) + 
  coord_flip() + 
  scale_fill_manual(values = my_colors[7:1], name = "") + 
  theme(legend.position = "top") + 
  theme(text = element_text(family = my_font)) + 
  guides(fill = guide_legend(reverse = TRUE)) + 
  scale_y_continuous(labels = paste0(seq(0, 100, 25), "%"), expand = c(0, 0)) + 
  theme(plot.title = element_text(size = 18), plot.subtitle = element_text(size = 11, color = "grey20")) + 
  theme(axis.text = element_text(color = "grey20", size = 10.2)) + 
  theme(plot.margin = unit(rep(0.7, 4), "cm")) + 
  theme(panel.grid.major.y = element_blank(), panel.grid.minor.x = element_blank()) + 
  theme(legend.key.height = unit(0.15, "mm")) + 
  labs(x = NULL, y = NULL, 
       title = "C\u1EA3m nh\u1EADn v\u1EC1 h\u00ECnh \u1EA3nh (IMA) c\u1EE7a h\u00E0nh kh\u00E1ch \u0111\u1ED1i v\u1EDBi h\u1EC7 th\u1ED1ng xe bu\u00FDt \u0111\u00F4 thi Vi\u1EC7t Nam ", 
       subtitle = "Thang \u0111o Likert l\u00E0 lo\u1EA1i thang \u0111o \u0111i\u1EC3m \u0111\u00E1nh gi\u00E1 \u0111\u01B0\u1EE3c s\u1EED d\u1EE5ng ph\u1ED5 bi\u1EBFn trong kh\u1EA3o s\u00E1t. Nghi\u00EAn c\u1EE9u s\u1EED d\u1EE5ng thang \u0111o 7 m\u1EE9c \u0111\u1ED9 t\u01B0\u01A1ng \u1EE9ng v\u1EDBi 1 - R\u1EA5t kh\u00F4ng \u0111\u1ED3ng \u00FD \u0111\u1EBFn 7 - R\u1EA5t \u0111\u1ED3ng \u00FD.")
gg_v
## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

# For displaying percent of "Very Disagree": Điều chỉnh percent để thể hiện giá trị của %
df_odered %>% 
  filter(Res == "R\u1EA5t kh\u00F4ng \u0111\u1ED3ng \u00FD") %>% 
  filter(percent >= 0) -> df_for_text1
df_for_text1
## # A tibble: 5 x 5
##   BPE   Res                  n percent bar_text
##   <fct> <fct>            <int>   <dbl> <chr>   
## 1 IMA1  R<U+1EA5>t không d<U+1ED3>ng ý     6    0.7  0.7%    
## 2 IMA2  R<U+1EA5>t không d<U+1ED3>ng ý    11    1.28 1.28%   
## 3 IMA3  R<U+1EA5>t không d<U+1ED3>ng ý    11    1.28 1.28%   
## 4 IMA4  R<U+1EA5>t không d<U+1ED3>ng ý    13    1.52 1.52%   
## 5 IMA5  R<U+1EA5>t không d<U+1ED3>ng ý     6    0.7  0.7%
# For displaying percent of "Disagree": 
df_odered %>% 
  filter(Res == "Kh\u00F4ng \u0111\u1ED3ng \u00FD") %>% 
  filter(percent >= 0) -> df_for_text2
df_for_text2
## # A tibble: 5 x 5
##   BPE   Res              n percent bar_text
##   <fct> <fct>        <int>   <dbl> <chr>   
## 1 IMA1  Không d<U+1ED3>ng ý    19    2.21 2.21%   
## 2 IMA2  Không d<U+1ED3>ng ý    18    2.1  2.1%    
## 3 IMA3  Không d<U+1ED3>ng ý    10    1.17 1.17%   
## 4 IMA4  Không d<U+1ED3>ng ý    15    1.75 1.75%   
## 5 IMA5  Không d<U+1ED3>ng ý    20    2.33 2.33%
# For displaying percent of "Quite Disagree": 
df_odered %>% 
  filter(Res == "Kh\u00E1 kh\u00F4ng \u0111\u1ED3ng \u00FD") %>% 
  filter(percent >= 0) -> df_for_text3
df_for_text3
## # A tibble: 5 x 5
##   BPE   Res                  n percent bar_text
##   <fct> <fct>            <int>   <dbl> <chr>   
## 1 IMA1  Khá không d<U+1ED3>ng ý    33    3.85 3.85%   
## 2 IMA2  Khá không d<U+1ED3>ng ý    26    3.03 3.03%   
## 3 IMA3  Khá không d<U+1ED3>ng ý    21    2.45 2.45%   
## 4 IMA4  Khá không d<U+1ED3>ng ý    26    3.03 3.03%   
## 5 IMA5  Khá không d<U+1ED3>ng ý    20    2.33 2.33%
# For displaying percent of "Normal": 
df_odered %>% 
  filter(Res == "B\u00ECnh th\u01B0\u1EDDng") %>% 
  filter(percent >= 0) -> df_for_text4
df_for_text4
## # A tibble: 5 x 5
##   BPE   Res             n percent bar_text
##   <fct> <fct>       <int>   <dbl> <chr>   
## 1 IMA1  Bình thu<U+1EDD>ng   154    18.0 17.95%  
## 2 IMA2  Bình thu<U+1EDD>ng   158    18.4 18.41%  
## 3 IMA3  Bình thu<U+1EDD>ng   128    14.9 14.92%  
## 4 IMA4  Bình thu<U+1EDD>ng   113    13.2 13.17%  
## 5 IMA5  Bình thu<U+1EDD>ng   104    12.1 12.12%
# For displaying percent of "Quite Agree": 
df_odered %>% 
  filter(Res == "Kh\u00E1 \u0111\u1ED3ng \u00FD") %>% 
  filter(percent >= 0) -> df_for_text5
df_for_text5
## # A tibble: 5 x 5
##   BPE   Res            n percent bar_text
##   <fct> <fct>      <int>   <dbl> <chr>   
## 1 IMA1  Khá d<U+1ED3>ng ý   230    26.8 26.81%  
## 2 IMA2  Khá d<U+1ED3>ng ý   214    24.9 24.94%  
## 3 IMA3  Khá d<U+1ED3>ng ý   207    24.1 24.13%  
## 4 IMA4  Khá d<U+1ED3>ng ý   201    23.4 23.43%  
## 5 IMA5  Khá d<U+1ED3>ng ý   204    23.8 23.78%
# For displaying percent of "Agree": 
df_odered %>% 
  filter(Res == "\u0110\u1ED3ng \u00FD") %>% 
  filter(percent >= 0) -> df_for_text6
df_for_text6
## # A tibble: 5 x 5
##   BPE   Res        n percent bar_text
##   <fct> <fct>  <int>   <dbl> <chr>   
## 1 IMA1  Ð<U+1ED3>ng ý   351    40.9 40.91%  
## 2 IMA2  Ð<U+1ED3>ng ý   365    42.5 42.54%  
## 3 IMA3  Ð<U+1ED3>ng ý   403    47.0 46.97%  
## 4 IMA4  Ð<U+1ED3>ng ý   406    47.3 47.32%  
## 5 IMA5  Ð<U+1ED3>ng ý   420    49.0 48.95%
# For displaying percent of "Very Agree": 
df_odered %>% 
  filter(Res == "R\u1EA5t \u0111\u1ED3ng \u00FD") %>% 
  filter(percent >= 0) -> df_for_text7
df_for_text7
## # A tibble: 5 x 5
##   BPE   Res            n percent bar_text
##   <fct> <fct>      <int>   <dbl> <chr>   
## 1 IMA1  R<U+1EA5>t d<U+1ED3>ng ý    65    7.58 7.58%   
## 2 IMA2  R<U+1EA5>t d<U+1ED3>ng ý    66    7.69 7.69%   
## 3 IMA3  R<U+1EA5>t d<U+1ED3>ng ý    78    9.09 9.09%   
## 4 IMA4  R<U+1EA5>t d<U+1ED3>ng ý    84    9.79 9.79%   
## 5 IMA5  R<U+1EA5>t d<U+1ED3>ng ý    84    9.79 9.79%
# For displaying percent of "Very Agree": 
df_odered %>% 
  filter(Res == "R\u1EA5t \u0111\u1ED3ng \u00FD") -> df_for_text
df_for_text
## # A tibble: 5 x 5
##   BPE   Res            n percent bar_text
##   <fct> <fct>      <int>   <dbl> <chr>   
## 1 IMA1  R<U+1EA5>t d<U+1ED3>ng ý    65    7.58 7.58%   
## 2 IMA2  R<U+1EA5>t d<U+1ED3>ng ý    66    7.69 7.69%   
## 3 IMA3  R<U+1EA5>t d<U+1ED3>ng ý    78    9.09 9.09%   
## 4 IMA4  R<U+1EA5>t d<U+1ED3>ng ý    84    9.79 9.79%   
## 5 IMA5  R<U+1EA5>t d<U+1ED3>ng ý    84    9.79 9.79%
# Ad text layers-thay đổi giá trị y để thể hiện vị trí ghi text phù hợp
gg_v + 
  geom_text(data = df_for_text1, aes(x = BPE, y = 3, label = bar_text), size = 4, color = "white", family = my_font) + 
  geom_text(data = df_for_text4, aes(x = BPE, y = 13, label = bar_text), size = 4, color = "white", family = my_font) +
  geom_text(data = df_for_text5, aes(x = BPE, y = 32, label = bar_text), size = 4, color = "white", family = my_font) +
  geom_text(data = df_for_text6, aes(x = BPE, y = 100-30, label = bar_text), size = 4, color = "white", family = my_font) +
  geom_text(data = df_for_text7, aes(x = BPE, y = 100-4, label = bar_text), size = 4, color = "white", family = my_font)
## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database
## Warning in grid.Call.graphics(C_text, as.graphicsAnnot(x$label), x$x, x$y, :
## font family not found in Windows font database
## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

3.8.15. Construct PHB - Nhãn tiếng anh

# Plot Likert graph for people in both cities for construct PHB
library(tidyverse)
library(compareGroups)
head(DN_HCM_SEM5_PHB)
##   Res  BPE
## 1   6 PHB1
## 2   3 PHB1
## 3   5 PHB1
## 4   5 PHB1
## 5   5 PHB1
## 6   4 PHB1
dim(DN_HCM_SEM5_PHB)
## [1] 4290    2
attach(DN_HCM_SEM5_PHB)
## The following objects are masked from DN_HCM_SEM5_IMA:
## 
##     BPE, Res
## The following objects are masked from DN_HCM_SEM5_SAT:
## 
##     BPE, Res
## The following objects are masked from DN_HCM_SEM5_PSQR:
## 
##     BPE, Res
## The following objects are masked from DN_HCM_SEM5_PSQP:
## 
##     BPE, Res
## The following objects are masked from DN_HCM_SEM5_PSQC:
## 
##     BPE, Res
## The following objects are masked from DN_HCM_SEM5_PSQT:
## 
##     BPE, Res
## The following objects are masked from DN_HCM_SEM5_PSB:
## 
##     BPE, Res
## The following objects are masked from HCM_SEM5:
## 
##     BPE, Res
## The following objects are masked from DN_SEM5:
## 
##     BPE, Res
## The following objects are masked from DN_HCM_SEM5:
## 
##     BPE, Res
DN_HCM_SEM5_PHB = within(DN_HCM_SEM5_PHB, {
  Res = factor(Res, labels = c("Very Disagree", "Disagree", "Quite Disagree", "Normal", "Quite Agree", "Agree", "Very Agree"))
  BPE = factor(BPE, labels = c("PHB1", "PHB2", "PHB3", "PHB4", "PHB5"))
  })
str(DN_HCM_SEM5_PHB)
## 'data.frame':    4290 obs. of  2 variables:
##  $ Res: Factor w/ 7 levels "Very Disagree",..: 6 3 5 5 5 4 3 6 6 7 ...
##  $ BPE: Factor w/ 5 levels "PHB1","PHB2",..: 1 1 1 1 1 1 1 1 1 1 ...
summary(DN_HCM_SEM5_PHB)
##              Res         BPE     
##  Very Disagree :  88   PHB1:858  
##  Disagree      :  73   PHB2:858  
##  Quite Disagree: 116   PHB3:858  
##  Normal        : 370   PHB4:858  
##  Quite Agree   : 801   PHB5:858  
##  Agree         :1919             
##  Very Agree    : 923
    ## t <- compareGroups(Res ~ BPE, data = DN_SEM1)
    ## createTable(t)
DN_HCM_SEM5_PHB %>% 
  group_by(BPE, Res) %>% 
  count() %>% 
  ungroup() %>% 
  group_by(BPE) %>% 
  mutate(percent = 100*n / sum(n)) %>% 
  mutate(percent = round(percent, 2)) %>% 
  mutate(bar_text = paste0(percent, "%")) %>% 
  ungroup() -> df_for_ploting
df_for_ploting %>% 
  filter(Res == Res[7]) %>% 
  arrange(percent) %>% # sắp xếp theo %
  pull(BPE) -> order_x
order_x
## [1] PHB1 PHB3 PHB2 PHB5 PHB4
## Levels: PHB1 PHB2 PHB3 PHB4 PHB5
# Make a draft plot: 
my_colors <- c("#3e6487", "#829cb2", "pink", "pink3", "palevioletred", "rosybrown2", "rosybrown3")
my_font <- "Roboto Condensed"

df_for_ploting %>% 
  mutate(BPE = factor(BPE, levels = order_x), Res = factor(Res, levels = Res[7:1])) -> df_odered
df_odered
## # A tibble: 35 x 5
##    BPE   Res                n percent bar_text
##    <fct> <fct>          <int>   <dbl> <chr>   
##  1 PHB1  Very Disagree     25    2.91 2.91%   
##  2 PHB1  Disagree          18    2.1  2.1%    
##  3 PHB1  Quite Disagree    37    4.31 4.31%   
##  4 PHB1  Normal            97   11.3  11.31%  
##  5 PHB1  Quite Agree      215   25.1  25.06%  
##  6 PHB1  Agree            352   41.0  41.03%  
##  7 PHB1  Very Agree       114   13.3  13.29%  
##  8 PHB2  Very Disagree     13    1.52 1.52%   
##  9 PHB2  Disagree          21    2.45 2.45%   
## 10 PHB2  Quite Disagree    26    3.03 3.03%   
## # ... with 25 more rows
library(extrafont)
theme_set(theme_minimal())
gg <- df_odered %>% 
  ggplot(aes(x = BPE, y = percent, fill = Res)) + 
  geom_col(width = 0.8) + 
  coord_flip() + 
  scale_fill_manual(values = my_colors[7:1], name = "") + 
  theme(legend.position = "top") + 
  theme(text = element_text(family = my_font)) + 
  guides(fill = guide_legend(reverse = TRUE)) + 
  scale_y_continuous(labels = paste0(seq(0, 100, 25), "%"), expand = c(0, 0)) + 
  theme(plot.title = element_text(size = 18), plot.subtitle = element_text(size = 11, color = "grey20")) + 
  theme(axis.text = element_text(color = "grey20", size = 10.2)) + 
  theme(plot.margin = unit(rep(0.7, 4), "cm")) + 
  theme(panel.grid.major.y = element_blank(), panel.grid.minor.x = element_blank()) + 
  theme(legend.key.height = unit(0.15, "mm")) + 
  labs(x = NULL, y = NULL, 
       title = "Perceived health benefits (PHB) of passengers towards urban bus systems of Viet Nam", 
       subtitle = "Likert scale is a type of rating scale commonly used in surveys. When responding to a Likert type question,\nrespondents simply state their level of agreement or disagreement on a symmetric agree-disagree scale.")
gg
## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

# For displaying percent of "Very Disagree": Điều chỉnh percent để thể hiện giá trị của %
df_odered %>% 
  filter(Res == "Very Disagree") %>% 
  filter(percent >= 0) -> df_for_text1
df_for_text1
## # A tibble: 5 x 5
##   BPE   Res               n percent bar_text
##   <fct> <fct>         <int>   <dbl> <chr>   
## 1 PHB1  Very Disagree    25    2.91 2.91%   
## 2 PHB2  Very Disagree    13    1.52 1.52%   
## 3 PHB3  Very Disagree    15    1.75 1.75%   
## 4 PHB4  Very Disagree    13    1.52 1.52%   
## 5 PHB5  Very Disagree    22    2.56 2.56%
# For displaying percent of "Disagree": 
df_odered %>% 
  filter(Res == "Disagree") %>% 
  filter(percent >= 3) -> df_for_text2
df_for_text2
## # A tibble: 0 x 5
## # ... with 5 variables: BPE <fct>, Res <fct>, n <int>, percent <dbl>,
## #   bar_text <chr>
# For displaying percent of "Quite Disagree": 
df_odered %>% 
  filter(Res == "Quite Disagree") %>% 
  filter(percent >= 0) -> df_for_text3
df_for_text3
## # A tibble: 5 x 5
##   BPE   Res                n percent bar_text
##   <fct> <fct>          <int>   <dbl> <chr>   
## 1 PHB1  Quite Disagree    37   4.31  4.31%   
## 2 PHB2  Quite Disagree    26   3.03  3.03%   
## 3 PHB3  Quite Disagree    38   4.43  4.43%   
## 4 PHB4  Quite Disagree    10   1.17  1.17%   
## 5 PHB5  Quite Disagree     5   0.580 0.58%
# For displaying percent of "Normal": 
df_odered %>% 
  filter(Res == "Normal") %>% 
  filter(percent >= 0) -> df_for_text4
df_for_text4
## # A tibble: 5 x 5
##   BPE   Res        n percent bar_text
##   <fct> <fct>  <int>   <dbl> <chr>   
## 1 PHB1  Normal    97   11.3  11.31%  
## 2 PHB2  Normal    69    8.04 8.04%   
## 3 PHB3  Normal    88   10.3  10.26%  
## 4 PHB4  Normal    53    6.18 6.18%   
## 5 PHB5  Normal    63    7.34 7.34%
# For displaying percent of "Quite Agree": 
df_odered %>% 
  filter(Res == "Quite Agree") %>% 
  filter(percent >= 0) -> df_for_text5
df_for_text5
## # A tibble: 5 x 5
##   BPE   Res             n percent bar_text
##   <fct> <fct>       <int>   <dbl> <chr>   
## 1 PHB1  Quite Agree   215    25.1 25.06%  
## 2 PHB2  Quite Agree   163    19   19%     
## 3 PHB3  Quite Agree   174    20.3 20.28%  
## 4 PHB4  Quite Agree   133    15.5 15.5%   
## 5 PHB5  Quite Agree   116    13.5 13.52%
# For displaying percent of "Agree": 
df_odered %>% 
  filter(Res == "Agree") %>% 
  filter(percent >= 0) -> df_for_text6
df_for_text6
## # A tibble: 5 x 5
##   BPE   Res       n percent bar_text
##   <fct> <fct> <int>   <dbl> <chr>   
## 1 PHB1  Agree   352    41.0 41.03%  
## 2 PHB2  Agree   378    44.1 44.06%  
## 3 PHB3  Agree   384    44.8 44.76%  
## 4 PHB4  Agree   390    45.4 45.45%  
## 5 PHB5  Agree   415    48.4 48.37%
# For displaying percent of "Very Agree": 
df_odered %>% 
  filter(Res == "Very Agree") %>% 
  filter(percent >= 0) -> df_for_text7 # Chỉ thể hiện giá trị có % lựa chọn >0
df_for_text7
## # A tibble: 5 x 5
##   BPE   Res            n percent bar_text
##   <fct> <fct>      <int>   <dbl> <chr>   
## 1 PHB1  Very Agree   114    13.3 13.29%  
## 2 PHB2  Very Agree   188    21.9 21.91%  
## 3 PHB3  Very Agree   140    16.3 16.32%  
## 4 PHB4  Very Agree   252    29.4 29.37%  
## 5 PHB5  Very Agree   229    26.7 26.69%
# For displaying percent of "Very Agree": 
df_odered %>% 
  filter(Res == "Very Agree") -> df_for_text
df_for_text
## # A tibble: 5 x 5
##   BPE   Res            n percent bar_text
##   <fct> <fct>      <int>   <dbl> <chr>   
## 1 PHB1  Very Agree   114    13.3 13.29%  
## 2 PHB2  Very Agree   188    21.9 21.91%  
## 3 PHB3  Very Agree   140    16.3 16.32%  
## 4 PHB4  Very Agree   252    29.4 29.37%  
## 5 PHB5  Very Agree   229    26.7 26.69%
# Ad text layers-thay đổi giá trị y để thể hiện vị trí ghi text phù hợp
gg + 
  geom_text(data = df_for_text1, aes(x = BPE, y = 3, label = bar_text), size = 4, color = "white", family = my_font) + 
  geom_text(data = df_for_text5, aes(x = BPE, y = 22, label = bar_text), size = 4, color = "white", family = my_font) +
  geom_text(data = df_for_text6, aes(x = BPE, y = 100-40, label = bar_text), size = 4, color = "white", family = my_font) +
  geom_text(data = df_for_text7, aes(x = BPE, y = 100-4, label = bar_text), size = 4, color = "white", family = my_font)
## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database
## Warning in grid.Call.graphics(C_text, as.graphicsAnnot(x$label), x$x, x$y, :
## font family not found in Windows font database
## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

3.8.16. Construct PHB - Nhãn tiếng việt

DN_HCM_SEM5_PHB_v = within(DN_HCM_SEM5_PHB, {
  Res = factor(Res, labels = c("R\u1EA5t kh\u00F4ng \u0111\u1ED3ng \u00FD", "Kh\u00F4ng \u0111\u1ED3ng \u00FD", "Kh\u00E1 kh\u00F4ng \u0111\u1ED3ng \u00FD", "B\u00ECnh th\u01B0\u1EDDng", "Kh\u00E1 \u0111\u1ED3ng \u00FD", "\u0110\u1ED3ng \u00FD", "R\u1EA5t \u0111\u1ED3ng \u00FD"))
  BPE = factor(BPE, labels = c("PHB1", "PHB2", "PHB3", "PHB4", "PHB5"))
  })
str(DN_HCM_SEM5_PHB_v)
## 'data.frame':    4290 obs. of  2 variables:
##  $ Res: Factor w/ 7 levels "R<U+1EA5>t không d<U+1ED3>ng ý",..: 6 3 5 5 5 4 3 6 6 7 ...
##  $ BPE: Factor w/ 5 levels "PHB1","PHB2",..: 1 1 1 1 1 1 1 1 1 1 ...
summary(DN_HCM_SEM5_PHB_v)
##                              Res         BPE     
##  R<U+1EA5>t không d<U+1ED3>ng ý:  88   PHB1:858  
##  Không d<U+1ED3>ng ý           :  73   PHB2:858  
##  Khá không d<U+1ED3>ng ý       : 116   PHB3:858  
##  Bình thu<U+1EDD>ng            : 370   PHB4:858  
##  Khá d<U+1ED3>ng ý             : 801   PHB5:858  
##  Ð<U+1ED3>ng ý                 :1919             
##  R<U+1EA5>t d<U+1ED3>ng ý      : 923
    ## t <- compareGroups(Res ~ BPE, data = DN_SEM1)
    ## createTable(t)
DN_HCM_SEM5_PHB_v %>% 
  group_by(BPE, Res) %>% 
  count() %>% 
  ungroup() %>% 
  group_by(BPE) %>% 
  mutate(percent = 100*n / sum(n)) %>% 
  mutate(percent = round(percent, 2)) %>% 
  mutate(bar_text = paste0(percent, "%")) %>% 
  ungroup() -> df_for_ploting
df_for_ploting %>% 
  filter(Res == Res[7]) %>% 
  arrange(percent) %>% # sắp xếp theo %
  pull(BPE) -> order_x
order_x
## [1] PHB1 PHB3 PHB2 PHB5 PHB4
## Levels: PHB1 PHB2 PHB3 PHB4 PHB5
# Make a draft plot: 
my_colors <- c("#3e6487", "#829cb2", "pink", "pink3", "palevioletred", "rosybrown2", "rosybrown3")
my_font <- "Roboto Condensed"

df_for_ploting %>% 
  mutate(BPE = factor(BPE, levels = order_x), Res = factor(Res, levels = Res[7:1])) -> df_odered
df_odered
## # A tibble: 35 x 5
##    BPE   Res                  n percent bar_text
##    <fct> <fct>            <int>   <dbl> <chr>   
##  1 PHB1  R<U+1EA5>t không d<U+1ED3>ng ý    25    2.91 2.91%   
##  2 PHB1  Không d<U+1ED3>ng ý        18    2.1  2.1%    
##  3 PHB1  Khá không d<U+1ED3>ng ý    37    4.31 4.31%   
##  4 PHB1  Bình thu<U+1EDD>ng         97   11.3  11.31%  
##  5 PHB1  Khá d<U+1ED3>ng ý         215   25.1  25.06%  
##  6 PHB1  Ð<U+1ED3>ng ý             352   41.0  41.03%  
##  7 PHB1  R<U+1EA5>t d<U+1ED3>ng ý         114   13.3  13.29%  
##  8 PHB2  R<U+1EA5>t không d<U+1ED3>ng ý    13    1.52 1.52%   
##  9 PHB2  Không d<U+1ED3>ng ý        21    2.45 2.45%   
## 10 PHB2  Khá không d<U+1ED3>ng ý    26    3.03 3.03%   
## # ... with 25 more rows
library(extrafont)
theme_set(theme_minimal())
gg_v <- df_odered %>% 
  ggplot(aes(x = BPE, y = percent, fill = Res)) + 
  geom_col(width = 0.8) + 
  coord_flip() + 
  scale_fill_manual(values = my_colors[7:1], name = "") + 
  theme(legend.position = "top") + 
  theme(text = element_text(family = my_font)) + 
  guides(fill = guide_legend(reverse = TRUE)) + 
  scale_y_continuous(labels = paste0(seq(0, 100, 25), "%"), expand = c(0, 0)) + 
  theme(plot.title = element_text(size = 18), plot.subtitle = element_text(size = 11, color = "grey20")) + 
  theme(axis.text = element_text(color = "grey20", size = 10.2)) + 
  theme(plot.margin = unit(rep(0.7, 4), "cm")) + 
  theme(panel.grid.major.y = element_blank(), panel.grid.minor.x = element_blank()) + 
  theme(legend.key.height = unit(0.15, "mm")) + 
  labs(x = NULL, y = NULL, 
       title = "C\u1EA3m nh\u1EADn v\u1EC1 l\u1EE3i \u00EDch s\u1EE9c kh\u1ECFe (PHB) c\u1EE7a h\u00E0nh kh\u00E1ch \u0111\u1ED1i v\u1EDBi h\u1EC7 th\u1ED1ng xe bu\u00FDt \u0111\u00F4 thi Vi\u1EC7t Nam ", 
       subtitle = "Thang \u0111o Likert l\u00E0 lo\u1EA1i thang \u0111o \u0111i\u1EC3m \u0111\u00E1nh gi\u00E1 \u0111\u01B0\u1EE3c s\u1EED d\u1EE5ng ph\u1ED5 bi\u1EBFn trong kh\u1EA3o s\u00E1t. Nghi\u00EAn c\u1EE9u s\u1EED d\u1EE5ng thang \u0111o 7 m\u1EE9c \u0111\u1ED9 t\u01B0\u01A1ng \u1EE9ng v\u1EDBi 1 - R\u1EA5t kh\u00F4ng \u0111\u1ED3ng \u00FD \u0111\u1EBFn 7 - R\u1EA5t \u0111\u1ED3ng \u00FD.")
gg_v
## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

# For displaying percent of "Very Disagree": Điều chỉnh percent để thể hiện giá trị của %
df_odered %>% 
  filter(Res == "R\u1EA5t kh\u00F4ng \u0111\u1ED3ng \u00FD") %>% 
  filter(percent >= 0) -> df_for_text1
df_for_text1
## # A tibble: 5 x 5
##   BPE   Res                  n percent bar_text
##   <fct> <fct>            <int>   <dbl> <chr>   
## 1 PHB1  R<U+1EA5>t không d<U+1ED3>ng ý    25    2.91 2.91%   
## 2 PHB2  R<U+1EA5>t không d<U+1ED3>ng ý    13    1.52 1.52%   
## 3 PHB3  R<U+1EA5>t không d<U+1ED3>ng ý    15    1.75 1.75%   
## 4 PHB4  R<U+1EA5>t không d<U+1ED3>ng ý    13    1.52 1.52%   
## 5 PHB5  R<U+1EA5>t không d<U+1ED3>ng ý    22    2.56 2.56%
# For displaying percent of "Disagree": 
df_odered %>% 
  filter(Res == "Kh\u00F4ng \u0111\u1ED3ng \u00FD") %>% 
  filter(percent >= 0) -> df_for_text2
df_for_text2
## # A tibble: 5 x 5
##   BPE   Res              n percent bar_text
##   <fct> <fct>        <int>   <dbl> <chr>   
## 1 PHB1  Không d<U+1ED3>ng ý    18    2.1  2.1%    
## 2 PHB2  Không d<U+1ED3>ng ý    21    2.45 2.45%   
## 3 PHB3  Không d<U+1ED3>ng ý    19    2.21 2.21%   
## 4 PHB4  Không d<U+1ED3>ng ý     7    0.82 0.82%   
## 5 PHB5  Không d<U+1ED3>ng ý     8    0.93 0.93%
# For displaying percent of "Quite Disagree": 
df_odered %>% 
  filter(Res == "Kh\u00E1 kh\u00F4ng \u0111\u1ED3ng \u00FD") %>% 
  filter(percent >= 0) -> df_for_text3
df_for_text3
## # A tibble: 5 x 5
##   BPE   Res                  n percent bar_text
##   <fct> <fct>            <int>   <dbl> <chr>   
## 1 PHB1  Khá không d<U+1ED3>ng ý    37   4.31  4.31%   
## 2 PHB2  Khá không d<U+1ED3>ng ý    26   3.03  3.03%   
## 3 PHB3  Khá không d<U+1ED3>ng ý    38   4.43  4.43%   
## 4 PHB4  Khá không d<U+1ED3>ng ý    10   1.17  1.17%   
## 5 PHB5  Khá không d<U+1ED3>ng ý     5   0.580 0.58%
# For displaying percent of "Normal": 
df_odered %>% 
  filter(Res == "B\u00ECnh th\u01B0\u1EDDng") %>% 
  filter(percent >= 0) -> df_for_text4
df_for_text4
## # A tibble: 5 x 5
##   BPE   Res             n percent bar_text
##   <fct> <fct>       <int>   <dbl> <chr>   
## 1 PHB1  Bình thu<U+1EDD>ng    97   11.3  11.31%  
## 2 PHB2  Bình thu<U+1EDD>ng    69    8.04 8.04%   
## 3 PHB3  Bình thu<U+1EDD>ng    88   10.3  10.26%  
## 4 PHB4  Bình thu<U+1EDD>ng    53    6.18 6.18%   
## 5 PHB5  Bình thu<U+1EDD>ng    63    7.34 7.34%
# For displaying percent of "Quite Agree": 
df_odered %>% 
  filter(Res == "Kh\u00E1 \u0111\u1ED3ng \u00FD") %>% 
  filter(percent >= 0) -> df_for_text5
df_for_text5
## # A tibble: 5 x 5
##   BPE   Res            n percent bar_text
##   <fct> <fct>      <int>   <dbl> <chr>   
## 1 PHB1  Khá d<U+1ED3>ng ý   215    25.1 25.06%  
## 2 PHB2  Khá d<U+1ED3>ng ý   163    19   19%     
## 3 PHB3  Khá d<U+1ED3>ng ý   174    20.3 20.28%  
## 4 PHB4  Khá d<U+1ED3>ng ý   133    15.5 15.5%   
## 5 PHB5  Khá d<U+1ED3>ng ý   116    13.5 13.52%
# For displaying percent of "Agree": 
df_odered %>% 
  filter(Res == "\u0110\u1ED3ng \u00FD") %>% 
  filter(percent >= 0) -> df_for_text6
df_for_text6
## # A tibble: 5 x 5
##   BPE   Res        n percent bar_text
##   <fct> <fct>  <int>   <dbl> <chr>   
## 1 PHB1  Ð<U+1ED3>ng ý   352    41.0 41.03%  
## 2 PHB2  Ð<U+1ED3>ng ý   378    44.1 44.06%  
## 3 PHB3  Ð<U+1ED3>ng ý   384    44.8 44.76%  
## 4 PHB4  Ð<U+1ED3>ng ý   390    45.4 45.45%  
## 5 PHB5  Ð<U+1ED3>ng ý   415    48.4 48.37%
# For displaying percent of "Very Agree": 
df_odered %>% 
  filter(Res == "R\u1EA5t \u0111\u1ED3ng \u00FD") %>% 
  filter(percent >= 0) -> df_for_text7
df_for_text7
## # A tibble: 5 x 5
##   BPE   Res            n percent bar_text
##   <fct> <fct>      <int>   <dbl> <chr>   
## 1 PHB1  R<U+1EA5>t d<U+1ED3>ng ý   114    13.3 13.29%  
## 2 PHB2  R<U+1EA5>t d<U+1ED3>ng ý   188    21.9 21.91%  
## 3 PHB3  R<U+1EA5>t d<U+1ED3>ng ý   140    16.3 16.32%  
## 4 PHB4  R<U+1EA5>t d<U+1ED3>ng ý   252    29.4 29.37%  
## 5 PHB5  R<U+1EA5>t d<U+1ED3>ng ý   229    26.7 26.69%
# For displaying percent of "Very Agree": 
df_odered %>% 
  filter(Res == "R\u1EA5t \u0111\u1ED3ng \u00FD") -> df_for_text
df_for_text
## # A tibble: 5 x 5
##   BPE   Res            n percent bar_text
##   <fct> <fct>      <int>   <dbl> <chr>   
## 1 PHB1  R<U+1EA5>t d<U+1ED3>ng ý   114    13.3 13.29%  
## 2 PHB2  R<U+1EA5>t d<U+1ED3>ng ý   188    21.9 21.91%  
## 3 PHB3  R<U+1EA5>t d<U+1ED3>ng ý   140    16.3 16.32%  
## 4 PHB4  R<U+1EA5>t d<U+1ED3>ng ý   252    29.4 29.37%  
## 5 PHB5  R<U+1EA5>t d<U+1ED3>ng ý   229    26.7 26.69%
# Ad text layers-thay đổi giá trị y để thể hiện vị trí ghi text phù hợp
gg_v + 
  geom_text(data = df_for_text1, aes(x = BPE, y = 3, label = bar_text), size = 4, color = "white", family = my_font) + 
  geom_text(data = df_for_text5, aes(x = BPE, y = 22, label = bar_text), size = 4, color = "white", family = my_font) +
  geom_text(data = df_for_text6, aes(x = BPE, y = 100-40, label = bar_text), size = 4, color = "white", family = my_font) +
  geom_text(data = df_for_text7, aes(x = BPE, y = 100-4, label = bar_text), size = 4, color = "white", family = my_font)
## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database
## Warning in grid.Call.graphics(C_text, as.graphicsAnnot(x$label), x$x, x$y, :
## font family not found in Windows font database
## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

3.8.17. Construct PEB - Nhãn tiếng anh

# Plot Likert graph for people in both cities for construct PEV
library(tidyverse)
library(compareGroups)
head(DN_HCM_SEM5_PEB)
##   Res  BPE
## 1   4 PEB1
## 2   5 PEB1
## 3   6 PEB1
## 4   5 PEB1
## 5   6 PEB1
## 6   7 PEB1
dim(DN_HCM_SEM5_PEB)
## [1] 3432    2
attach(DN_HCM_SEM5_PEB)
## The following objects are masked from DN_HCM_SEM5_PHB:
## 
##     BPE, Res
## The following objects are masked from DN_HCM_SEM5_IMA:
## 
##     BPE, Res
## The following objects are masked from DN_HCM_SEM5_SAT:
## 
##     BPE, Res
## The following objects are masked from DN_HCM_SEM5_PSQR:
## 
##     BPE, Res
## The following objects are masked from DN_HCM_SEM5_PSQP:
## 
##     BPE, Res
## The following objects are masked from DN_HCM_SEM5_PSQC:
## 
##     BPE, Res
## The following objects are masked from DN_HCM_SEM5_PSQT:
## 
##     BPE, Res
## The following objects are masked from DN_HCM_SEM5_PSB:
## 
##     BPE, Res
## The following objects are masked from HCM_SEM5:
## 
##     BPE, Res
## The following objects are masked from DN_SEM5:
## 
##     BPE, Res
## The following objects are masked from DN_HCM_SEM5:
## 
##     BPE, Res
DN_HCM_SEM5_PEB = within(DN_HCM_SEM5_PEB, {
  Res = factor(Res, labels = c("Very Disagree", "Disagree", "Quite Disagree", "Normal", "Quite Agree", "Agree", "Very Agree"))
  BPE = factor(BPE, labels = c("PEB1", "PEB2", "PEB3", "PEB4"))
  })
str(DN_HCM_SEM5_PEB)
## 'data.frame':    3432 obs. of  2 variables:
##  $ Res: Factor w/ 7 levels "Very Disagree",..: 4 5 6 5 6 7 4 6 7 7 ...
##  $ BPE: Factor w/ 4 levels "PEB1","PEB2",..: 1 1 1 1 1 1 1 1 1 1 ...
summary(DN_HCM_SEM5_PEB)
##              Res         BPE     
##  Very Disagree :  98   PEB1:858  
##  Disagree      :  64   PEB2:858  
##  Quite Disagree:  78   PEB3:858  
##  Normal        : 297   PEB4:858  
##  Quite Agree   : 632             
##  Agree         :1456             
##  Very Agree    : 807
    ## t <- compareGroups(Res ~ BPE, data = DN_SEM1)
    ## createTable(t)
DN_HCM_SEM5_PEB %>% 
  group_by(BPE, Res) %>% 
  count() %>% 
  ungroup() %>% 
  group_by(BPE) %>% 
  mutate(percent = 100*n / sum(n)) %>% 
  mutate(percent = round(percent, 2)) %>% 
  mutate(bar_text = paste0(percent, "%")) %>% 
  ungroup() -> df_for_ploting
df_for_ploting %>% 
  filter(Res == Res[7]) %>% 
  arrange(percent) %>% # sắp xếp theo %
  pull(BPE) -> order_x
order_x
## [1] PEB4 PEB3 PEB2 PEB1
## Levels: PEB1 PEB2 PEB3 PEB4
# Make a draft plot: 
my_colors <- c("#3e6487", "#829cb2", "pink", "pink3", "palevioletred", "rosybrown2", "rosybrown3")
my_font <- "Roboto Condensed"

df_for_ploting %>% 
  mutate(BPE = factor(BPE, levels = order_x), Res = factor(Res, levels = Res[7:1])) -> df_odered
df_odered
## # A tibble: 28 x 5
##    BPE   Res                n percent bar_text
##    <fct> <fct>          <int>   <dbl> <chr>   
##  1 PEB1  Very Disagree     24    2.8  2.8%    
##  2 PEB1  Disagree           8    0.93 0.93%   
##  3 PEB1  Quite Disagree    13    1.52 1.52%   
##  4 PEB1  Normal            60    6.99 6.99%   
##  5 PEB1  Quite Agree      127   14.8  14.8%   
##  6 PEB1  Agree            391   45.6  45.57%  
##  7 PEB1  Very Agree       235   27.4  27.39%  
##  8 PEB2  Very Disagree     25    2.91 2.91%   
##  9 PEB2  Disagree          17    1.98 1.98%   
## 10 PEB2  Quite Disagree    21    2.45 2.45%   
## # ... with 18 more rows
library(extrafont)
theme_set(theme_minimal())
gg <- df_odered %>% 
  ggplot(aes(x = BPE, y = percent, fill = Res)) + 
  geom_col(width = 0.8) + 
  coord_flip() + 
  scale_fill_manual(values = my_colors[7:1], name = "") + 
  theme(legend.position = "top") + 
  theme(text = element_text(family = my_font)) + 
  guides(fill = guide_legend(reverse = TRUE)) + 
  scale_y_continuous(labels = paste0(seq(0, 100, 25), "%"), expand = c(0, 0)) + 
  theme(plot.title = element_text(size = 18), plot.subtitle = element_text(size = 11, color = "grey20")) + 
  theme(axis.text = element_text(color = "grey20", size = 10.2)) + 
  theme(plot.margin = unit(rep(0.7, 4), "cm")) + 
  theme(panel.grid.major.y = element_blank(), panel.grid.minor.x = element_blank()) + 
  theme(legend.key.height = unit(0.15, "mm")) + 
  labs(x = NULL, y = NULL, 
       title = "Perceived environmental benefits (PEB) towards urban bus systems of Viet Nam", 
       subtitle = "Likert scale is a type of rating scale commonly used in surveys. When responding to a Likert type question,\nrespondents simply state their level of agreement or disagreement on a symmetric agree-disagree scale.")
gg
## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

# For displaying percent of "Very Disagree": Điều chỉnh percent để thể hiện giá trị của %
df_odered %>% 
  filter(Res == "Very Disagree") %>% 
  filter(percent >= 0) -> df_for_text1
df_for_text1
## # A tibble: 4 x 5
##   BPE   Res               n percent bar_text
##   <fct> <fct>         <int>   <dbl> <chr>   
## 1 PEB1  Very Disagree    24    2.8  2.8%    
## 2 PEB2  Very Disagree    25    2.91 2.91%   
## 3 PEB3  Very Disagree    25    2.91 2.91%   
## 4 PEB4  Very Disagree    24    2.8  2.8%
# For displaying percent of "Disagree": 
df_odered %>% 
  filter(Res == "Disagree") %>% 
  filter(percent >= 3) -> df_for_text2
df_for_text2
## # A tibble: 0 x 5
## # ... with 5 variables: BPE <fct>, Res <fct>, n <int>, percent <dbl>,
## #   bar_text <chr>
# For displaying percent of "Quite Disagree": 
df_odered %>% 
  filter(Res == "Quite Disagree") %>% 
  filter(percent >= 0) -> df_for_text3
df_for_text3
## # A tibble: 4 x 5
##   BPE   Res                n percent bar_text
##   <fct> <fct>          <int>   <dbl> <chr>   
## 1 PEB1  Quite Disagree    13    1.52 1.52%   
## 2 PEB2  Quite Disagree    21    2.45 2.45%   
## 3 PEB3  Quite Disagree    22    2.56 2.56%   
## 4 PEB4  Quite Disagree    22    2.56 2.56%
# For displaying percent of "Normal": 
df_odered %>% 
  filter(Res == "Normal") %>% 
  filter(percent >= 0) -> df_for_text4
df_for_text4
## # A tibble: 4 x 5
##   BPE   Res        n percent bar_text
##   <fct> <fct>  <int>   <dbl> <chr>   
## 1 PEB1  Normal    60    6.99 6.99%   
## 2 PEB2  Normal    67    7.81 7.81%   
## 3 PEB3  Normal    77    8.97 8.97%   
## 4 PEB4  Normal    93   10.8  10.84%
# For displaying percent of "Quite Agree": 
df_odered %>% 
  filter(Res == "Quite Agree") %>% 
  filter(percent >= 0) -> df_for_text5
df_for_text5
## # A tibble: 4 x 5
##   BPE   Res             n percent bar_text
##   <fct> <fct>       <int>   <dbl> <chr>   
## 1 PEB1  Quite Agree   127    14.8 14.8%   
## 2 PEB2  Quite Agree   170    19.8 19.81%  
## 3 PEB3  Quite Agree   168    19.6 19.58%  
## 4 PEB4  Quite Agree   167    19.5 19.46%
# For displaying percent of "Agree": 
df_odered %>% 
  filter(Res == "Agree") %>% 
  filter(percent >= 0) -> df_for_text6
df_for_text6
## # A tibble: 4 x 5
##   BPE   Res       n percent bar_text
##   <fct> <fct> <int>   <dbl> <chr>   
## 1 PEB1  Agree   391    45.6 45.57%  
## 2 PEB2  Agree   353    41.1 41.14%  
## 3 PEB3  Agree   354    41.3 41.26%  
## 4 PEB4  Agree   358    41.7 41.72%
# For displaying percent of "Very Agree": 
df_odered %>% 
  filter(Res == "Very Agree") %>% 
  filter(percent >= 0) -> df_for_text7 # Chỉ thể hiện giá trị có % lựa chọn >0
df_for_text7
## # A tibble: 4 x 5
##   BPE   Res            n percent bar_text
##   <fct> <fct>      <int>   <dbl> <chr>   
## 1 PEB1  Very Agree   235    27.4 27.39%  
## 2 PEB2  Very Agree   205    23.9 23.89%  
## 3 PEB3  Very Agree   192    22.4 22.38%  
## 4 PEB4  Very Agree   175    20.4 20.4%
# For displaying percent of "Very Agree": 
df_odered %>% 
  filter(Res == "Very Agree") -> df_for_text
df_for_text
## # A tibble: 4 x 5
##   BPE   Res            n percent bar_text
##   <fct> <fct>      <int>   <dbl> <chr>   
## 1 PEB1  Very Agree   235    27.4 27.39%  
## 2 PEB2  Very Agree   205    23.9 23.89%  
## 3 PEB3  Very Agree   192    22.4 22.38%  
## 4 PEB4  Very Agree   175    20.4 20.4%
# Ad text layers-thay đổi giá trị y để thể hiện vị trí ghi text phù hợp
gg + 
  geom_text(data = df_for_text1, aes(x = BPE, y = 3, label = bar_text), size = 4, color = "white", family = my_font) + 
  geom_text(data = df_for_text5, aes(x = BPE, y = 22, label = bar_text), size = 4, color = "white", family = my_font) +
  geom_text(data = df_for_text6, aes(x = BPE, y = 100-40, label = bar_text), size = 4, color = "white", family = my_font) +
  geom_text(data = df_for_text7, aes(x = BPE, y = 100-4, label = bar_text), size = 4, color = "white", family = my_font)
## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database
## Warning in grid.Call.graphics(C_text, as.graphicsAnnot(x$label), x$x, x$y, :
## font family not found in Windows font database
## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

3.8.18. Construct PEB - Nhãn tiếng việt

DN_HCM_SEM5_PEB_v = within(DN_HCM_SEM5_PEB, {
  Res = factor(Res, labels = c("R\u1EA5t kh\u00F4ng \u0111\u1ED3ng \u00FD", "Kh\u00F4ng \u0111\u1ED3ng \u00FD", "Kh\u00E1 kh\u00F4ng \u0111\u1ED3ng \u00FD", "B\u00ECnh th\u01B0\u1EDDng", "Kh\u00E1 \u0111\u1ED3ng \u00FD", "\u0110\u1ED3ng \u00FD", "R\u1EA5t \u0111\u1ED3ng \u00FD"))
  BPE = factor(BPE, labels = c("PEB1", "PEB2", "PEB3", "PEB4"))
  })
str(DN_HCM_SEM5_PEB_v)
## 'data.frame':    3432 obs. of  2 variables:
##  $ Res: Factor w/ 7 levels "R<U+1EA5>t không d<U+1ED3>ng ý",..: 4 5 6 5 6 7 4 6 7 7 ...
##  $ BPE: Factor w/ 4 levels "PEB1","PEB2",..: 1 1 1 1 1 1 1 1 1 1 ...
summary(DN_HCM_SEM5_PEB_v)
##                              Res         BPE     
##  R<U+1EA5>t không d<U+1ED3>ng ý:  98   PEB1:858  
##  Không d<U+1ED3>ng ý           :  64   PEB2:858  
##  Khá không d<U+1ED3>ng ý       :  78   PEB3:858  
##  Bình thu<U+1EDD>ng            : 297   PEB4:858  
##  Khá d<U+1ED3>ng ý             : 632             
##  Ð<U+1ED3>ng ý                 :1456             
##  R<U+1EA5>t d<U+1ED3>ng ý      : 807
    ## t <- compareGroups(Res ~ BPE, data = DN_SEM1)
    ## createTable(t)
DN_HCM_SEM5_PEB_v %>% 
  group_by(BPE, Res) %>% 
  count() %>% 
  ungroup() %>% 
  group_by(BPE) %>% 
  mutate(percent = 100*n / sum(n)) %>% 
  mutate(percent = round(percent, 2)) %>% 
  mutate(bar_text = paste0(percent, "%")) %>% 
  ungroup() -> df_for_ploting
df_for_ploting %>% 
  filter(Res == Res[7]) %>% 
  arrange(percent) %>% # sắp xếp theo %
  pull(BPE) -> order_x
order_x
## [1] PEB4 PEB3 PEB2 PEB1
## Levels: PEB1 PEB2 PEB3 PEB4
# Make a draft plot: 
my_colors <- c("#3e6487", "#829cb2", "pink", "pink3", "palevioletred", "rosybrown2", "rosybrown3")
my_font <- "Roboto Condensed"

df_for_ploting %>% 
  mutate(BPE = factor(BPE, levels = order_x), Res = factor(Res, levels = Res[7:1])) -> df_odered
df_odered
## # A tibble: 28 x 5
##    BPE   Res                  n percent bar_text
##    <fct> <fct>            <int>   <dbl> <chr>   
##  1 PEB1  R<U+1EA5>t không d<U+1ED3>ng ý    24    2.8  2.8%    
##  2 PEB1  Không d<U+1ED3>ng ý         8    0.93 0.93%   
##  3 PEB1  Khá không d<U+1ED3>ng ý    13    1.52 1.52%   
##  4 PEB1  Bình thu<U+1EDD>ng         60    6.99 6.99%   
##  5 PEB1  Khá d<U+1ED3>ng ý         127   14.8  14.8%   
##  6 PEB1  Ð<U+1ED3>ng ý             391   45.6  45.57%  
##  7 PEB1  R<U+1EA5>t d<U+1ED3>ng ý         235   27.4  27.39%  
##  8 PEB2  R<U+1EA5>t không d<U+1ED3>ng ý    25    2.91 2.91%   
##  9 PEB2  Không d<U+1ED3>ng ý        17    1.98 1.98%   
## 10 PEB2  Khá không d<U+1ED3>ng ý    21    2.45 2.45%   
## # ... with 18 more rows
library(extrafont)
theme_set(theme_minimal())
gg_v <- df_odered %>% 
  ggplot(aes(x = BPE, y = percent, fill = Res)) + 
  geom_col(width = 0.8) + 
  coord_flip() + 
  scale_fill_manual(values = my_colors[7:1], name = "") + 
  theme(legend.position = "top") + 
  theme(text = element_text(family = my_font)) + 
  guides(fill = guide_legend(reverse = TRUE)) + 
  scale_y_continuous(labels = paste0(seq(0, 100, 25), "%"), expand = c(0, 0)) + 
  theme(plot.title = element_text(size = 18), plot.subtitle = element_text(size = 11, color = "grey20")) + 
  theme(axis.text = element_text(color = "grey20", size = 10.2)) + 
  theme(plot.margin = unit(rep(0.7, 4), "cm")) + 
  theme(panel.grid.major.y = element_blank(), panel.grid.minor.x = element_blank()) + 
  theme(legend.key.height = unit(0.15, "mm")) + 
  labs(x = NULL, y = NULL, 
       title = "C\u1EA3m nh\u1EADn v\u1EC1 gi\u00E1 tr\u1ECB m\u00F4i tr\u01B0\u1EDDng (PEB) c\u1EE7a h\u00E0nh kh\u00E1ch \u0111\u1ED1i v\u1EDBi h\u1EC7 th\u1ED1ng xe bu\u00FDt \u0111\u00F4 thi Vi\u1EC7t Nam ", 
       subtitle = "Thang \u0111o Likert l\u00E0 lo\u1EA1i thang \u0111o \u0111i\u1EC3m \u0111\u00E1nh gi\u00E1 \u0111\u01B0\u1EE3c s\u1EED d\u1EE5ng ph\u1ED5 bi\u1EBFn trong kh\u1EA3o s\u00E1t. Nghi\u00EAn c\u1EE9u s\u1EED d\u1EE5ng thang \u0111o 7 m\u1EE9c \u0111\u1ED9 t\u01B0\u01A1ng \u1EE9ng v\u1EDBi 1 - R\u1EA5t kh\u00F4ng \u0111\u1ED3ng \u00FD \u0111\u1EBFn 7 - R\u1EA5t \u0111\u1ED3ng \u00FD.")
gg_v
## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

# For displaying percent of "Very Disagree": Điều chỉnh percent để thể hiện giá trị của %
df_odered %>% 
  filter(Res == "R\u1EA5t kh\u00F4ng \u0111\u1ED3ng \u00FD") %>% 
  filter(percent >= 0) -> df_for_text1
df_for_text1
## # A tibble: 4 x 5
##   BPE   Res                  n percent bar_text
##   <fct> <fct>            <int>   <dbl> <chr>   
## 1 PEB1  R<U+1EA5>t không d<U+1ED3>ng ý    24    2.8  2.8%    
## 2 PEB2  R<U+1EA5>t không d<U+1ED3>ng ý    25    2.91 2.91%   
## 3 PEB3  R<U+1EA5>t không d<U+1ED3>ng ý    25    2.91 2.91%   
## 4 PEB4  R<U+1EA5>t không d<U+1ED3>ng ý    24    2.8  2.8%
# For displaying percent of "Disagree": 
df_odered %>% 
  filter(Res == "Kh\u00F4ng \u0111\u1ED3ng \u00FD") %>% 
  filter(percent >= 0) -> df_for_text2
df_for_text2
## # A tibble: 4 x 5
##   BPE   Res              n percent bar_text
##   <fct> <fct>        <int>   <dbl> <chr>   
## 1 PEB1  Không d<U+1ED3>ng ý     8    0.93 0.93%   
## 2 PEB2  Không d<U+1ED3>ng ý    17    1.98 1.98%   
## 3 PEB3  Không d<U+1ED3>ng ý    20    2.33 2.33%   
## 4 PEB4  Không d<U+1ED3>ng ý    19    2.21 2.21%
# For displaying percent of "Quite Disagree": 
df_odered %>% 
  filter(Res == "Kh\u00E1 kh\u00F4ng \u0111\u1ED3ng \u00FD") %>% 
  filter(percent >= 0) -> df_for_text3
df_for_text3
## # A tibble: 4 x 5
##   BPE   Res                  n percent bar_text
##   <fct> <fct>            <int>   <dbl> <chr>   
## 1 PEB1  Khá không d<U+1ED3>ng ý    13    1.52 1.52%   
## 2 PEB2  Khá không d<U+1ED3>ng ý    21    2.45 2.45%   
## 3 PEB3  Khá không d<U+1ED3>ng ý    22    2.56 2.56%   
## 4 PEB4  Khá không d<U+1ED3>ng ý    22    2.56 2.56%
# For displaying percent of "Normal": 
df_odered %>% 
  filter(Res == "B\u00ECnh th\u01B0\u1EDDng") %>% 
  filter(percent >= 0) -> df_for_text4
df_for_text4
## # A tibble: 4 x 5
##   BPE   Res             n percent bar_text
##   <fct> <fct>       <int>   <dbl> <chr>   
## 1 PEB1  Bình thu<U+1EDD>ng    60    6.99 6.99%   
## 2 PEB2  Bình thu<U+1EDD>ng    67    7.81 7.81%   
## 3 PEB3  Bình thu<U+1EDD>ng    77    8.97 8.97%   
## 4 PEB4  Bình thu<U+1EDD>ng    93   10.8  10.84%
# For displaying percent of "Quite Agree": 
df_odered %>% 
  filter(Res == "Kh\u00E1 \u0111\u1ED3ng \u00FD") %>% 
  filter(percent >= 0) -> df_for_text5
df_for_text5
## # A tibble: 4 x 5
##   BPE   Res            n percent bar_text
##   <fct> <fct>      <int>   <dbl> <chr>   
## 1 PEB1  Khá d<U+1ED3>ng ý   127    14.8 14.8%   
## 2 PEB2  Khá d<U+1ED3>ng ý   170    19.8 19.81%  
## 3 PEB3  Khá d<U+1ED3>ng ý   168    19.6 19.58%  
## 4 PEB4  Khá d<U+1ED3>ng ý   167    19.5 19.46%
# For displaying percent of "Agree": 
df_odered %>% 
  filter(Res == "\u0110\u1ED3ng \u00FD") %>% 
  filter(percent >= 0) -> df_for_text6
df_for_text6
## # A tibble: 4 x 5
##   BPE   Res        n percent bar_text
##   <fct> <fct>  <int>   <dbl> <chr>   
## 1 PEB1  Ð<U+1ED3>ng ý   391    45.6 45.57%  
## 2 PEB2  Ð<U+1ED3>ng ý   353    41.1 41.14%  
## 3 PEB3  Ð<U+1ED3>ng ý   354    41.3 41.26%  
## 4 PEB4  Ð<U+1ED3>ng ý   358    41.7 41.72%
# For displaying percent of "Very Agree": 
df_odered %>% 
  filter(Res == "R\u1EA5t \u0111\u1ED3ng \u00FD") %>% 
  filter(percent >= 0) -> df_for_text7
df_for_text7
## # A tibble: 4 x 5
##   BPE   Res            n percent bar_text
##   <fct> <fct>      <int>   <dbl> <chr>   
## 1 PEB1  R<U+1EA5>t d<U+1ED3>ng ý   235    27.4 27.39%  
## 2 PEB2  R<U+1EA5>t d<U+1ED3>ng ý   205    23.9 23.89%  
## 3 PEB3  R<U+1EA5>t d<U+1ED3>ng ý   192    22.4 22.38%  
## 4 PEB4  R<U+1EA5>t d<U+1ED3>ng ý   175    20.4 20.4%
# For displaying percent of "Very Agree": 
df_odered %>% 
  filter(Res == "R\u1EA5t \u0111\u1ED3ng \u00FD") -> df_for_text
df_for_text
## # A tibble: 4 x 5
##   BPE   Res            n percent bar_text
##   <fct> <fct>      <int>   <dbl> <chr>   
## 1 PEB1  R<U+1EA5>t d<U+1ED3>ng ý   235    27.4 27.39%  
## 2 PEB2  R<U+1EA5>t d<U+1ED3>ng ý   205    23.9 23.89%  
## 3 PEB3  R<U+1EA5>t d<U+1ED3>ng ý   192    22.4 22.38%  
## 4 PEB4  R<U+1EA5>t d<U+1ED3>ng ý   175    20.4 20.4%
# Ad text layers-thay đổi giá trị y để thể hiện vị trí ghi text phù hợp
gg_v + 
  geom_text(data = df_for_text1, aes(x = BPE, y = 3, label = bar_text), size = 4, color = "white", family = my_font) + 
  geom_text(data = df_for_text5, aes(x = BPE, y = 22, label = bar_text), size = 4, color = "white", family = my_font) +
  geom_text(data = df_for_text6, aes(x = BPE, y = 100-40, label = bar_text), size = 4, color = "white", family = my_font) +
  geom_text(data = df_for_text7, aes(x = BPE, y = 100-4, label = bar_text), size = 4, color = "white", family = my_font)
## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database
## Warning in grid.Call.graphics(C_text, as.graphicsAnnot(x$label), x$x, x$y, :
## font family not found in Windows font database
## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

3.8.19. Construct PVA - Nhãn tiếng anh

# Plot Likert graph for people in both cities for construct PVA
library(tidyverse)
library(compareGroups)
head(DN_HCM_SEM5_PVA)
##   Res  BPE
## 1   6 PVA1
## 2   5 PVA1
## 3   6 PVA1
## 4   5 PVA1
## 5   6 PVA1
## 6   6 PVA1
dim(DN_HCM_SEM5_PVA)
## [1] 2574    2
attach(DN_HCM_SEM5_PVA)
## The following objects are masked from DN_HCM_SEM5_PEB:
## 
##     BPE, Res
## The following objects are masked from DN_HCM_SEM5_PHB:
## 
##     BPE, Res
## The following objects are masked from DN_HCM_SEM5_IMA:
## 
##     BPE, Res
## The following objects are masked from DN_HCM_SEM5_SAT:
## 
##     BPE, Res
## The following objects are masked from DN_HCM_SEM5_PSQR:
## 
##     BPE, Res
## The following objects are masked from DN_HCM_SEM5_PSQP:
## 
##     BPE, Res
## The following objects are masked from DN_HCM_SEM5_PSQC:
## 
##     BPE, Res
## The following objects are masked from DN_HCM_SEM5_PSQT:
## 
##     BPE, Res
## The following objects are masked from DN_HCM_SEM5_PSB:
## 
##     BPE, Res
## The following objects are masked from HCM_SEM5:
## 
##     BPE, Res
## The following objects are masked from DN_SEM5:
## 
##     BPE, Res
## The following objects are masked from DN_HCM_SEM5:
## 
##     BPE, Res
DN_HCM_SEM5_PVA = within(DN_HCM_SEM5_PVA, {
  Res = factor(Res, labels = c("Very Disagree", "Disagree", "Quite Disagree", "Normal", "Quite Agree", "Agree", "Very Agree"))
  BPE = factor(BPE, labels = c("PVA1", "PVA2", "PVA3"))
  })
str(DN_HCM_SEM5_PVA)
## 'data.frame':    2574 obs. of  2 variables:
##  $ Res: Factor w/ 7 levels "Very Disagree",..: 6 5 6 5 6 6 6 6 6 6 ...
##  $ BPE: Factor w/ 3 levels "PVA1","PVA2",..: 1 1 1 1 1 1 1 1 1 1 ...
summary(DN_HCM_SEM5_PVA)
##              Res         BPE     
##  Very Disagree :  11   PVA1:858  
##  Disagree      :  49   PVA2:858  
##  Quite Disagree:  79   PVA3:858  
##  Normal        : 225             
##  Quite Agree   : 485             
##  Agree         :1168             
##  Very Agree    : 557
    ## t <- compareGroups(Res ~ BPE, data = DN_SEM1)
    ## createTable(t)
DN_HCM_SEM5_PVA %>% 
  group_by(BPE, Res) %>% 
  count() %>% 
  ungroup() %>% 
  group_by(BPE) %>% 
  mutate(percent = 100*n / sum(n)) %>% 
  mutate(percent = round(percent, 2)) %>% 
  mutate(bar_text = paste0(percent, "%")) %>% 
  ungroup() -> df_for_ploting
df_for_ploting %>% 
  filter(Res == Res[7]) %>% 
  arrange(percent) %>% # sắp xếp theo %
  pull(BPE) -> order_x
order_x
## [1] PVA2 PVA3 PVA1
## Levels: PVA1 PVA2 PVA3
# Make a draft plot: 
my_colors <- c("#3e6487", "#829cb2", "pink", "pink3", "palevioletred", "rosybrown2", "rosybrown3")
my_font <- "Roboto Condensed"

df_for_ploting %>% 
  mutate(BPE = factor(BPE, levels = order_x), Res = factor(Res, levels = Res[7:1])) -> df_odered
df_odered
## # A tibble: 21 x 5
##    BPE   Res                n percent bar_text
##    <fct> <fct>          <int>   <dbl> <chr>   
##  1 PVA1  Very Disagree      5   0.580 0.58%   
##  2 PVA1  Disagree           9   1.05  1.05%   
##  3 PVA1  Quite Disagree    18   2.1   2.1%    
##  4 PVA1  Normal            56   6.53  6.53%   
##  5 PVA1  Quite Agree      131  15.3   15.27%  
##  6 PVA1  Agree            413  48.1   48.14%  
##  7 PVA1  Very Agree       226  26.3   26.34%  
##  8 PVA2  Very Disagree      4   0.47  0.47%   
##  9 PVA2  Disagree          26   3.03  3.03%   
## 10 PVA2  Quite Disagree    39   4.55  4.55%   
## # ... with 11 more rows
library(extrafont)
theme_set(theme_minimal())
gg <- df_odered %>% 
  ggplot(aes(x = BPE, y = percent, fill = Res)) + 
  geom_col(width = 0.8) + 
  coord_flip() + 
  scale_fill_manual(values = my_colors[7:1], name = "") + 
  theme(legend.position = "top") + 
  theme(text = element_text(family = my_font)) + 
  guides(fill = guide_legend(reverse = TRUE)) + 
  scale_y_continuous(labels = paste0(seq(0, 100, 25), "%"), expand = c(0, 0)) + 
  theme(plot.title = element_text(size = 18), plot.subtitle = element_text(size = 11, color = "grey20")) + 
  theme(axis.text = element_text(color = "grey20", size = 10.2)) + 
  theme(plot.margin = unit(rep(0.7, 4), "cm")) + 
  theme(panel.grid.major.y = element_blank(), panel.grid.minor.x = element_blank()) + 
  theme(legend.key.height = unit(0.15, "mm")) + 
  labs(x = NULL, y = NULL, 
       title = "Perceived value (PVA) towards urban bus systems of Viet Nam", 
       subtitle = "Likert scale is a type of rating scale commonly used in surveys. When responding to a Likert type question,\nrespondents simply state their level of agreement or disagreement on a symmetric agree-disagree scale.")
gg
## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

# For displaying percent of "Very Disagree": Điều chỉnh percent để thể hiện giá trị của %
df_odered %>% 
  filter(Res == "Very Disagree") %>% 
  filter(percent >= 0) -> df_for_text1
df_for_text1
## # A tibble: 3 x 5
##   BPE   Res               n percent bar_text
##   <fct> <fct>         <int>   <dbl> <chr>   
## 1 PVA1  Very Disagree     5   0.580 0.58%   
## 2 PVA2  Very Disagree     4   0.47  0.47%   
## 3 PVA3  Very Disagree     2   0.23  0.23%
# For displaying percent of "Disagree": 
df_odered %>% 
  filter(Res == "Disagree") %>% 
  filter(percent >= 3) -> df_for_text2
df_for_text2
## # A tibble: 1 x 5
##   BPE   Res          n percent bar_text
##   <fct> <fct>    <int>   <dbl> <chr>   
## 1 PVA2  Disagree    26    3.03 3.03%
# For displaying percent of "Quite Disagree": 
df_odered %>% 
  filter(Res == "Quite Disagree") %>% 
  filter(percent >= 0) -> df_for_text3
df_for_text3
## # A tibble: 3 x 5
##   BPE   Res                n percent bar_text
##   <fct> <fct>          <int>   <dbl> <chr>   
## 1 PVA1  Quite Disagree    18    2.1  2.1%    
## 2 PVA2  Quite Disagree    39    4.55 4.55%   
## 3 PVA3  Quite Disagree    22    2.56 2.56%
# For displaying percent of "Normal": 
df_odered %>% 
  filter(Res == "Normal") %>% 
  filter(percent >= 0) -> df_for_text4
df_for_text4
## # A tibble: 3 x 5
##   BPE   Res        n percent bar_text
##   <fct> <fct>  <int>   <dbl> <chr>   
## 1 PVA1  Normal    56    6.53 6.53%   
## 2 PVA2  Normal   100   11.7  11.66%  
## 3 PVA3  Normal    69    8.04 8.04%
# For displaying percent of "Quite Agree": 
df_odered %>% 
  filter(Res == "Quite Agree") %>% 
  filter(percent >= 0) -> df_for_text5
df_for_text5
## # A tibble: 3 x 5
##   BPE   Res             n percent bar_text
##   <fct> <fct>       <int>   <dbl> <chr>   
## 1 PVA1  Quite Agree   131    15.3 15.27%  
## 2 PVA2  Quite Agree   194    22.6 22.61%  
## 3 PVA3  Quite Agree   160    18.6 18.65%
# For displaying percent of "Agree": 
df_odered %>% 
  filter(Res == "Agree") %>% 
  filter(percent >= 0) -> df_for_text6
df_for_text6
## # A tibble: 3 x 5
##   BPE   Res       n percent bar_text
##   <fct> <fct> <int>   <dbl> <chr>   
## 1 PVA1  Agree   413    48.1 48.14%  
## 2 PVA2  Agree   344    40.1 40.09%  
## 3 PVA3  Agree   411    47.9 47.9%
# For displaying percent of "Very Agree": 
df_odered %>% 
  filter(Res == "Very Agree") %>% 
  filter(percent >= 0) -> df_for_text7 # Chỉ thể hiện giá trị có % lựa chọn >0
df_for_text7
## # A tibble: 3 x 5
##   BPE   Res            n percent bar_text
##   <fct> <fct>      <int>   <dbl> <chr>   
## 1 PVA1  Very Agree   226    26.3 26.34%  
## 2 PVA2  Very Agree   151    17.6 17.6%   
## 3 PVA3  Very Agree   180    21.0 20.98%
# For displaying percent of "Very Agree": 
df_odered %>% 
  filter(Res == "Very Agree") -> df_for_text
df_for_text
## # A tibble: 3 x 5
##   BPE   Res            n percent bar_text
##   <fct> <fct>      <int>   <dbl> <chr>   
## 1 PVA1  Very Agree   226    26.3 26.34%  
## 2 PVA2  Very Agree   151    17.6 17.6%   
## 3 PVA3  Very Agree   180    21.0 20.98%
# Ad text layers-thay đổi giá trị y để thể hiện vị trí ghi text phù hợp
gg + 
  geom_text(data = df_for_text1, aes(x = BPE, y = 3, label = bar_text), size = 4, color = "white", family = my_font) + 
  geom_text(data = df_for_text5, aes(x = BPE, y = 23, label = bar_text), size = 4, color = "white", family = my_font) +
  geom_text(data = df_for_text6, aes(x = BPE, y = 100-40, label = bar_text), size = 4, color = "white", family = my_font) +
  geom_text(data = df_for_text7, aes(x = BPE, y = 100-4, label = bar_text), size = 4, color = "white", family = my_font)
## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database
## Warning in grid.Call.graphics(C_text, as.graphicsAnnot(x$label), x$x, x$y, :
## font family not found in Windows font database
## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

3.8.20. Construct PVA - Nhãn tiếng việt

DN_HCM_SEM5_PVA_v = within(DN_HCM_SEM5_PVA, {
  Res = factor(Res, labels = c("R\u1EA5t kh\u00F4ng \u0111\u1ED3ng \u00FD", "Kh\u00F4ng \u0111\u1ED3ng \u00FD", "Kh\u00E1 kh\u00F4ng \u0111\u1ED3ng \u00FD", "B\u00ECnh th\u01B0\u1EDDng", "Kh\u00E1 \u0111\u1ED3ng \u00FD", "\u0110\u1ED3ng \u00FD", "R\u1EA5t \u0111\u1ED3ng \u00FD"))
  BPE = factor(BPE, labels = c("PVA1", "PVA2", "PVA3"))
  })
str(DN_HCM_SEM5_PVA_v)
## 'data.frame':    2574 obs. of  2 variables:
##  $ Res: Factor w/ 7 levels "R<U+1EA5>t không d<U+1ED3>ng ý",..: 6 5 6 5 6 6 6 6 6 6 ...
##  $ BPE: Factor w/ 3 levels "PVA1","PVA2",..: 1 1 1 1 1 1 1 1 1 1 ...
summary(DN_HCM_SEM5_PVA_v)
##                              Res         BPE     
##  R<U+1EA5>t không d<U+1ED3>ng ý:  11   PVA1:858  
##  Không d<U+1ED3>ng ý           :  49   PVA2:858  
##  Khá không d<U+1ED3>ng ý       :  79   PVA3:858  
##  Bình thu<U+1EDD>ng            : 225             
##  Khá d<U+1ED3>ng ý             : 485             
##  Ð<U+1ED3>ng ý                 :1168             
##  R<U+1EA5>t d<U+1ED3>ng ý      : 557
    ## t <- compareGroups(Res ~ BPE, data = DN_SEM1)
    ## createTable(t)
DN_HCM_SEM5_PVA_v %>% 
  group_by(BPE, Res) %>% 
  count() %>% 
  ungroup() %>% 
  group_by(BPE) %>% 
  mutate(percent = 100*n / sum(n)) %>% 
  mutate(percent = round(percent, 2)) %>% 
  mutate(bar_text = paste0(percent, "%")) %>% 
  ungroup() -> df_for_ploting
df_for_ploting %>% 
  filter(Res == Res[7]) %>% 
  arrange(percent) %>% # sắp xếp theo %
  pull(BPE) -> order_x
order_x
## [1] PVA2 PVA3 PVA1
## Levels: PVA1 PVA2 PVA3
# Make a draft plot: 
my_colors <- c("#3e6487", "#829cb2", "pink", "pink3", "palevioletred", "rosybrown2", "rosybrown3")
my_font <- "Roboto Condensed"

df_for_ploting %>% 
  mutate(BPE = factor(BPE, levels = order_x), Res = factor(Res, levels = Res[7:1])) -> df_odered
df_odered
## # A tibble: 21 x 5
##    BPE   Res                  n percent bar_text
##    <fct> <fct>            <int>   <dbl> <chr>   
##  1 PVA1  R<U+1EA5>t không d<U+1ED3>ng ý     5   0.580 0.58%   
##  2 PVA1  Không d<U+1ED3>ng ý         9   1.05  1.05%   
##  3 PVA1  Khá không d<U+1ED3>ng ý    18   2.1   2.1%    
##  4 PVA1  Bình thu<U+1EDD>ng         56   6.53  6.53%   
##  5 PVA1  Khá d<U+1ED3>ng ý         131  15.3   15.27%  
##  6 PVA1  Ð<U+1ED3>ng ý             413  48.1   48.14%  
##  7 PVA1  R<U+1EA5>t d<U+1ED3>ng ý         226  26.3   26.34%  
##  8 PVA2  R<U+1EA5>t không d<U+1ED3>ng ý     4   0.47  0.47%   
##  9 PVA2  Không d<U+1ED3>ng ý        26   3.03  3.03%   
## 10 PVA2  Khá không d<U+1ED3>ng ý    39   4.55  4.55%   
## # ... with 11 more rows
library(extrafont)
theme_set(theme_minimal())
gg_v <- df_odered %>% 
  ggplot(aes(x = BPE, y = percent, fill = Res)) + 
  geom_col(width = 0.8) + 
  coord_flip() + 
  scale_fill_manual(values = my_colors[7:1], name = "") + 
  theme(legend.position = "top") + 
  theme(text = element_text(family = my_font)) + 
  guides(fill = guide_legend(reverse = TRUE)) + 
  scale_y_continuous(labels = paste0(seq(0, 100, 25), "%"), expand = c(0, 0)) + 
  theme(plot.title = element_text(size = 18), plot.subtitle = element_text(size = 11, color = "grey20")) + 
  theme(axis.text = element_text(color = "grey20", size = 10.2)) + 
  theme(plot.margin = unit(rep(0.7, 4), "cm")) + 
  theme(panel.grid.major.y = element_blank(), panel.grid.minor.x = element_blank()) + 
  theme(legend.key.height = unit(0.15, "mm")) + 
  labs(x = NULL, y = NULL, 
       title = "C\u1EA3m nh\u1EADn v\u1EC1 gi\u00E1 tr\u1ECB c\u1EE7a h\u00E0nh kh\u00E1ch (PVA) \u0111\u1ED1i v\u1EDBi h\u1EC7 th\u1ED1ng xe bu\u00FDt \u0111\u00F4 th\u1ECB Vi\u1EC7t Nam", 
       subtitle = "Thang \u0111o Likert l\u00E0 lo\u1EA1i thang \u0111o \u0111i\u1EC3m \u0111\u00E1nh gi\u00E1 \u0111\u01B0\u1EE3c s\u1EED d\u1EE5ng ph\u1ED5 bi\u1EBFn trong kh\u1EA3o s\u00E1t. Nghi\u00EAn c\u1EE9u s\u1EED d\u1EE5ng thang \u0111o 7 m\u1EE9c \u0111\u1ED9 t\u01B0\u01A1ng \u1EE9ng v\u1EDBi 1 - R\u1EA5t kh\u00F4ng \u0111\u1ED3ng \u00FD \u0111\u1EBFn 7 - R\u1EA5t \u0111\u1ED3ng \u00FD.")
gg_v
## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

# For displaying percent of "Very Disagree": Điều chỉnh percent để thể hiện giá trị của %
df_odered %>% 
  filter(Res == "R\u1EA5t kh\u00F4ng \u0111\u1ED3ng \u00FD") %>% 
  filter(percent >= 0) -> df_for_text1
df_for_text1
## # A tibble: 3 x 5
##   BPE   Res                  n percent bar_text
##   <fct> <fct>            <int>   <dbl> <chr>   
## 1 PVA1  R<U+1EA5>t không d<U+1ED3>ng ý     5   0.580 0.58%   
## 2 PVA2  R<U+1EA5>t không d<U+1ED3>ng ý     4   0.47  0.47%   
## 3 PVA3  R<U+1EA5>t không d<U+1ED3>ng ý     2   0.23  0.23%
# For displaying percent of "Disagree": 
df_odered %>% 
  filter(Res == "Kh\u00F4ng \u0111\u1ED3ng \u00FD") %>% 
  filter(percent >= 0) -> df_for_text2
df_for_text2
## # A tibble: 3 x 5
##   BPE   Res              n percent bar_text
##   <fct> <fct>        <int>   <dbl> <chr>   
## 1 PVA1  Không d<U+1ED3>ng ý     9    1.05 1.05%   
## 2 PVA2  Không d<U+1ED3>ng ý    26    3.03 3.03%   
## 3 PVA3  Không d<U+1ED3>ng ý    14    1.63 1.63%
# For displaying percent of "Quite Disagree": 
df_odered %>% 
  filter(Res == "Kh\u00E1 kh\u00F4ng \u0111\u1ED3ng \u00FD") %>% 
  filter(percent >= 0) -> df_for_text3
df_for_text3
## # A tibble: 3 x 5
##   BPE   Res                  n percent bar_text
##   <fct> <fct>            <int>   <dbl> <chr>   
## 1 PVA1  Khá không d<U+1ED3>ng ý    18    2.1  2.1%    
## 2 PVA2  Khá không d<U+1ED3>ng ý    39    4.55 4.55%   
## 3 PVA3  Khá không d<U+1ED3>ng ý    22    2.56 2.56%
# For displaying percent of "Normal": 
df_odered %>% 
  filter(Res == "B\u00ECnh th\u01B0\u1EDDng") %>% 
  filter(percent >= 0) -> df_for_text4
df_for_text4
## # A tibble: 3 x 5
##   BPE   Res             n percent bar_text
##   <fct> <fct>       <int>   <dbl> <chr>   
## 1 PVA1  Bình thu<U+1EDD>ng    56    6.53 6.53%   
## 2 PVA2  Bình thu<U+1EDD>ng   100   11.7  11.66%  
## 3 PVA3  Bình thu<U+1EDD>ng    69    8.04 8.04%
# For displaying percent of "Quite Agree": 
df_odered %>% 
  filter(Res == "Kh\u00E1 \u0111\u1ED3ng \u00FD") %>% 
  filter(percent >= 0) -> df_for_text5
df_for_text5
## # A tibble: 3 x 5
##   BPE   Res            n percent bar_text
##   <fct> <fct>      <int>   <dbl> <chr>   
## 1 PVA1  Khá d<U+1ED3>ng ý   131    15.3 15.27%  
## 2 PVA2  Khá d<U+1ED3>ng ý   194    22.6 22.61%  
## 3 PVA3  Khá d<U+1ED3>ng ý   160    18.6 18.65%
# For displaying percent of "Agree": 
df_odered %>% 
  filter(Res == "\u0110\u1ED3ng \u00FD") %>% 
  filter(percent >= 0) -> df_for_text6
df_for_text6
## # A tibble: 3 x 5
##   BPE   Res        n percent bar_text
##   <fct> <fct>  <int>   <dbl> <chr>   
## 1 PVA1  Ð<U+1ED3>ng ý   413    48.1 48.14%  
## 2 PVA2  Ð<U+1ED3>ng ý   344    40.1 40.09%  
## 3 PVA3  Ð<U+1ED3>ng ý   411    47.9 47.9%
# For displaying percent of "Very Agree": 
df_odered %>% 
  filter(Res == "R\u1EA5t \u0111\u1ED3ng \u00FD") %>% 
  filter(percent >= 0) -> df_for_text7
df_for_text7
## # A tibble: 3 x 5
##   BPE   Res            n percent bar_text
##   <fct> <fct>      <int>   <dbl> <chr>   
## 1 PVA1  R<U+1EA5>t d<U+1ED3>ng ý   226    26.3 26.34%  
## 2 PVA2  R<U+1EA5>t d<U+1ED3>ng ý   151    17.6 17.6%   
## 3 PVA3  R<U+1EA5>t d<U+1ED3>ng ý   180    21.0 20.98%
# For displaying percent of "Very Agree": 
df_odered %>% 
  filter(Res == "R\u1EA5t \u0111\u1ED3ng \u00FD") -> df_for_text
df_for_text
## # A tibble: 3 x 5
##   BPE   Res            n percent bar_text
##   <fct> <fct>      <int>   <dbl> <chr>   
## 1 PVA1  R<U+1EA5>t d<U+1ED3>ng ý   226    26.3 26.34%  
## 2 PVA2  R<U+1EA5>t d<U+1ED3>ng ý   151    17.6 17.6%   
## 3 PVA3  R<U+1EA5>t d<U+1ED3>ng ý   180    21.0 20.98%
# Ad text layers-thay đổi giá trị y để thể hiện vị trí ghi text phù hợp
gg_v + 
  geom_text(data = df_for_text1, aes(x = BPE, y = 3, label = bar_text), size = 4, color = "white", family = my_font) + 
  geom_text(data = df_for_text5, aes(x = BPE, y = 22, label = bar_text), size = 4, color = "white", family = my_font) +
  geom_text(data = df_for_text6, aes(x = BPE, y = 100-40, label = bar_text), size = 4, color = "white", family = my_font) +
  geom_text(data = df_for_text7, aes(x = BPE, y = 100-4, label = bar_text), size = 4, color = "white", family = my_font)
## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database
## Warning in grid.Call.graphics(C_text, as.graphicsAnnot(x$label), x$x, x$y, :
## font family not found in Windows font database
## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database