1. Read and set up Data Loyalty for SEM4
# Read Data directly
t = "F:/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-outliersSEM4.csv"
SEM4 = read.csv(t, header = T)
head(SEM4)
## 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 PSQ1 PSQ2 PSQ3 PSQ4 PSQu1 PSQu2
## 1 4 6 6 4 6 5 6 6 6 6 6 4 4 6 4
## 2 2 3 3 4 4 6 6 6 6 4 6 5 4 4 5
## 3 2 2 6 6 4 6 6 4 2 2 2 2 2 2 4
## 4 6 5 6 6 5 5 6 7 6 6 5 4 5 5 5
## 5 2 2 2 5 5 5 6 4 3 6 3 6 3 6 6
## 6 2 2 5 4 4 4 6 4 2 4 4 5 4 5 5
## PSQu3 PSQu4 PSQu5 PSQ10 PSQ11 PSQ12 PSQ13 PSQu6 PSQ15 PSQu7 PSQ17 PSQu8 SAT1
## 1 4 4 6 6 6 5 6 4 4 6 4 2 6
## 2 6 4 6 6 4 4 5 4 3 4 3 6 5
## 3 1 2 1 1 1 6 6 2 6 2 5 2 2
## 4 5 4 4 5 5 5 5 4 5 5 5 5 5
## 5 4 3 6 4 4 4 5 5 3 5 3 5 4
## 6 4 3 3 4 4 4 5 3 3 3 3 4 4
## SAT2 SAT3 LOY1 LOY2 LOY3 LOY4 LOY5 LOY6 LOY7 IMA1 IMA2 IMA3 IMA4 IMA5 PHB1
## 1 6 6 4 6 5 7 6 6 6 6 6 6 4 6 6
## 2 5 4 4 5 4 4 4 4 5 4 5 6 5 4 3
## 3 2 2 2 6 6 4 4 2 2 4 2 5 2 2 5
## 4 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5
## 5 4 4 4 5 5 4 4 4 6 5 4 5 4 5 5
## 6 5 5 4 3 2 5 5 6 6 4 3 2 2 4 4
## PHB2 PHB3 PHB4 PHB5 PEB1 PEB2 PEB3 PEB4 ATM1 ATM2 ATM3 ATM4 ATM5 ATM6 ATM7
## 1 7 6 7 7 4 4 4 4 3 5 6 4 2 4 6
## 2 4 3 4 6 5 6 6 4 3 5 4 4 4 4 5
## 3 2 6 6 6 6 5 6 6 2 6 4 2 2 4 2
## 4 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 3
## 6 6 7 6 4 7 7 5 2 1 4 5 2 1 4 2
## PPI1 PPI2 PPI3 SIM1 SIM2 SIM3 SIM4 PPA1 PPA2 PPA3 PPA4 SBE1 SBE2 SBE3 SBE4
## 1 6 6 6 4 4 4 2 4 6 4 4 4 4 4 4
## 2 4 4 4 4 4 4 4 4 4 4 4 5 4 5 5
## 3 4 2 2 4 4 4 2 4 6 6 2 6 6 6 6
## 4 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5
## 5 2 3 4 6 6 5 5 5 5 5 5 5 5 5 5
## 6 5 2 2 2 2 2 2 2 3 3 2 2 2 2 2
## EXB1 EXB2 EXB3 PVA1 PVA2 PVA3 EC_Stop WC_Stop EC_Bus WC_Bus Gender
## 1 4 4 3 6 6 6 0 1 0 1 0
## 2 4 5 3 5 5 3 0 0 1 0 0
## 3 4 6 2 6 2 4 0 0 0 0 1
## 4 5 5 5 5 5 5 0 1 0 1 1
## 5 5 5 4 6 2 3 0 1 0 1 1
## 6 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(SEM4)
## [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" "PSQ1" "PSQ2" "PSQ3"
## [37] "PSQ4" "PSQu1" "PSQu2" "PSQu3"
## [41] "PSQu4" "PSQu5" "PSQ10" "PSQ11"
## [45] "PSQ12" "PSQ13" "PSQu6" "PSQ15"
## [49] "PSQu7" "PSQ17" "PSQu8" "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(SEM4)
## [1] 858 112
2. Desscriptive statistic
# 2.1. Subset Data SEM1 (6 constructs and 32 items)
SEM4 <- SEM4[, c(2, 3, 5, 6, 7, 8, 9, 10, 11, 38, 39, 40, 41, 42, 47, 49, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 104, 105, 106, 107, 108, 109, 110, 111, 112)]
head(SEM4)
## MCCar MCMotor AGE CITY FRE TripPurpose Departure TimeUseonBus TravelTime
## 1 0 0 1 2 1 2 0 4 3.00
## 2 0 0 1 2 2 4 0 4 2.00
## 3 0 0 1 2 1 2 1 4 0.17
## 4 0 0 1 2 1 2 1 1 4.00
## 5 0 0 1 2 1 2 1 4 2.00
## 6 0 1 1 2 1 2 1 6 2.00
## PSQu1 PSQu2 PSQu3 PSQu4 PSQu5 PSQu6 PSQu7 PSQu8 SAT1 SAT2 SAT3 LOY1 LOY2 LOY3
## 1 6 4 4 4 6 4 6 2 6 6 6 4 6 5
## 2 4 5 6 4 6 4 4 6 5 5 4 4 5 4
## 3 2 4 1 2 1 2 2 2 2 2 2 2 6 6
## 4 5 5 5 4 4 4 5 5 5 5 5 5 5 5
## 5 6 6 4 3 6 5 5 5 4 4 4 4 5 5
## 6 5 5 4 3 3 3 3 4 4 5 5 4 3 2
## LOY4 LOY5 LOY6 LOY7 IMA1 IMA2 IMA3 IMA4 IMA5 PHB1 PHB2 PHB3 PHB4 PHB5 PEB1
## 1 7 6 6 6 6 6 6 4 6 6 7 6 7 7 4
## 2 4 4 4 5 4 5 6 5 4 3 4 3 4 6 5
## 3 4 4 2 2 4 2 5 2 2 5 2 6 6 6 6
## 4 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5
## 5 4 4 4 6 5 4 5 4 5 5 6 6 6 5 6
## 6 5 5 6 6 4 3 2 2 4 4 6 7 6 4 7
## PEB2 PEB3 PEB4 EC_Stop WC_Stop EC_Bus WC_Bus Gender MarriedStatus Occupation
## 1 4 4 4 0 1 0 1 0 1 1
## 2 6 6 4 0 0 1 0 0 1 1
## 3 5 6 6 0 0 0 0 1 1 1
## 4 5 5 5 0 1 0 1 1 1 1
## 5 6 6 6 0 1 0 1 1 1 1
## 6 7 5 2 0 1 0 1 0 1 1
## Education Income
## 1 2 1
## 2 2 1
## 3 2 1
## 4 2 1
## 5 2 1
## 6 3 1
names(SEM4)
## [1] "MCCar" "MCMotor" "AGE" "CITY"
## [5] "FRE" "TripPurpose" "Departure" "TimeUseonBus"
## [9] "TravelTime" "PSQu1" "PSQu2" "PSQu3"
## [13] "PSQu4" "PSQu5" "PSQu6" "PSQu7"
## [17] "PSQu8" "SAT1" "SAT2" "SAT3"
## [21] "LOY1" "LOY2" "LOY3" "LOY4"
## [25] "LOY5" "LOY6" "LOY7" "IMA1"
## [29] "IMA2" "IMA3" "IMA4" "IMA5"
## [33] "PHB1" "PHB2" "PHB3" "PHB4"
## [37] "PHB5" "PEB1" "PEB2" "PEB3"
## [41] "PEB4" "EC_Stop" "WC_Stop" "EC_Bus"
## [45] "WC_Bus" "Gender" "MarriedStatus" "Occupation"
## [49] "Education" "Income"
dim(SEM4)
## [1] 858 50
# Data coding
str(SEM4)
## 'data.frame': 858 obs. of 50 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 ...
## $ PSQu1 : int 6 4 2 5 6 5 2 6 3 7 ...
## $ PSQu2 : int 4 5 4 5 6 5 2 6 4 7 ...
## $ PSQu3 : int 4 6 1 5 4 4 2 3 4 7 ...
## $ PSQu4 : int 4 4 2 4 3 3 2 4 4 4 ...
## $ PSQu5 : int 6 6 1 4 6 3 2 3 3 4 ...
## $ PSQu6 : int 4 4 2 4 5 3 2 5 3 4 ...
## $ PSQu7 : int 6 4 2 5 5 3 1 3 5 4 ...
## $ PSQu8 : 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 ...
## $ LOY1 : int 4 4 2 5 4 4 2 6 6 6 ...
## $ LOY2 : int 6 5 6 5 5 3 1 6 5 6 ...
## $ LOY3 : int 5 4 6 5 5 2 1 6 6 6 ...
## $ LOY4 : int 7 4 4 5 4 5 2 7 5 6 ...
## $ LOY5 : int 6 4 4 5 4 5 2 7 5 4 ...
## $ LOY6 : int 6 4 2 5 4 6 1 7 5 6 ...
## $ LOY7 : int 6 5 2 5 6 6 2 7 5 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 ...
## $ 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(SEM4)
SEM4 = within(SEM4, {
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(SEM4)
## 'data.frame': 858 obs. of 50 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 ...
## $ PSQu1 : int 6 4 2 5 6 5 2 6 3 7 ...
## $ PSQu2 : int 4 5 4 5 6 5 2 6 4 7 ...
## $ PSQu3 : int 4 6 1 5 4 4 2 3 4 7 ...
## $ PSQu4 : int 4 4 2 4 3 3 2 4 4 4 ...
## $ PSQu5 : int 6 6 1 4 6 3 2 3 3 4 ...
## $ PSQu6 : int 4 4 2 4 5 3 2 5 3 4 ...
## $ PSQu7 : int 6 4 2 5 5 3 1 3 5 4 ...
## $ PSQu8 : 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 ...
## $ LOY1 : int 4 4 2 5 4 4 2 6 6 6 ...
## $ LOY2 : int 6 5 6 5 5 3 1 6 5 6 ...
## $ LOY3 : int 5 4 6 5 5 2 1 6 6 6 ...
## $ LOY4 : int 7 4 4 5 4 5 2 7 5 6 ...
## $ LOY5 : int 6 4 4 5 4 5 2 7 5 4 ...
## $ LOY6 : int 6 4 2 5 4 6 1 7 5 6 ...
## $ LOY7 : int 6 5 2 5 6 6 2 7 5 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 ...
## $ 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(SEM4)
## [1] 858 50
# 2.2. Descritive Table
library(tableone)
require(tableone)
library(magrittr)
summary(SEM4)
## MCCar MCMotor AGE CITY FRE
## No :838 No :696 16-25:418 DaNang :410 >=3 days/week :499
## Yes: 20 Yes:162 26-35:169 HoChiMinh:448 2days/month-2days/week:164
## 36-45:101 2days/year-1day/month : 97
## 46-55: 76 <2 days/year : 98
## >55 : 94
##
##
## TripPurpose Departure TimeUseonBus TravelTime
## Working :305 Normal :216 Using.telephone:199 Min. : 0.000
## Studying :296 Peak-Hour:642 Reading : 53 1st Qu.: 0.500
## Shopping : 58 Listening :136 Median : 1.000
## Entertaining: 96 Nothing :417 Mean : 1.271
## Others :103 Talking : 33 3rd Qu.: 2.000
## Others : 20 Max. :20.000
##
## PSQu1 PSQu2 PSQu3 PSQu4
## Min. :1.000 Min. :1.000 Min. :1.000 Min. :1.000
## 1st Qu.:4.000 1st Qu.:5.000 1st Qu.:4.000 1st Qu.:4.000
## Median :6.000 Median :6.000 Median :6.000 Median :5.000
## Mean :5.134 Mean :5.568 Mean :5.115 Mean :4.768
## 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
##
## PSQu5 PSQu6 PSQu7 PSQu8 SAT1
## Min. :1.000 Min. :1.00 Min. :1.00 Min. :1.00 Min. :1.000
## 1st Qu.:4.000 1st Qu.:4.00 1st Qu.:4.00 1st Qu.:5.00 1st Qu.:5.000
## Median :5.000 Median :5.00 Median :5.00 Median :6.00 Median :6.000
## Mean :5.026 Mean :4.95 Mean :5.02 Mean :5.53 Mean :5.333
## 3rd Qu.:6.000 3rd Qu.:6.00 3rd Qu.:6.00 3rd Qu.:6.00 3rd Qu.:6.000
## Max. :7.000 Max. :7.00 Max. :7.00 Max. :7.00 Max. :7.000
##
## SAT2 SAT3 LOY1 LOY2 LOY3
## 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.507 Mean :5.501 Mean :5.49 Mean :5.516 Mean :5.598
## 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
##
## LOY4 LOY5 LOY6 LOY7
## Min. :1.000 Min. :1.000 Min. :1.000 Min. :1.000
## 1st Qu.:5.000 1st Qu.:5.000 1st Qu.:4.000 1st Qu.:5.000
## Median :6.000 Median :6.000 Median :5.000 Median :6.000
## Mean :5.324 Mean :5.378 Mean :5.079 Mean :5.629
## 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
##
## IMA1 IMA2 IMA3 IMA4 IMA5
## Min. :1.000 Min. :1.00 Min. :1.000 Min. :1.000 Min. :1.00
## 1st Qu.:5.000 1st Qu.:5.00 1st Qu.:5.000 1st Qu.:5.000 1st Qu.:5.00
## Median :5.000 Median :6.00 Median :6.000 Median :6.000 Median :6.00
## Mean :5.206 Mean :5.22 Mean :5.365 Mean :5.367 Mean :5.41
## 3rd Qu.:6.000 3rd Qu.:6.00 3rd Qu.:6.000 3rd Qu.:6.000 3rd Qu.:6.00
## Max. :7.000 Max. :7.00 Max. :7.000 Max. :7.000 Max. :7.00
##
## PHB1 PHB2 PHB3 PHB4
## 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.297 Mean :5.604 Mean :5.442 Mean :5.868
## 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
##
## PHB5 PEB1 PEB2 PEB3 PEB4
## Min. :1.000 Min. :1.00 Min. :1.000 Min. :1.000 Min. :1.000
## 1st Qu.:5.250 1st Qu.:5.00 1st Qu.:5.000 1st Qu.:5.000 1st Qu.:5.000
## Median :6.000 Median :6.00 Median :6.000 Median :6.000 Median :6.000
## Mean :5.797 Mean :5.76 Mean :5.585 Mean :5.528 Mean :5.483
## 3rd Qu.:7.000 3rd Qu.:7.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
##
## EC_Stop WC_Stop EC_Bus WC_Bus Gender MarriedStatus
## Never:822 Never:737 Never:818 Never:743 Female:501 Married:332
## Ever : 36 Ever :121 Ever : 40 Ever :115 Male :357 Single :526
##
##
##
##
##
## Occupation Education Income
## Students/Pupils:359 Secondary.school: 59 <5millions :456
## Full.time.job :304 Undergraduate :276 5-10millions :248
## Part.time.job : 67 High.school :362 10-15millions:117
## Retirement : 46 Postgraduate :105 >15millions : 37
## No.job : 4 Others : 56
## Housewife : 51
## Others : 27
library(table1)
##
## Attaching package: 'table1'
## The following objects are masked from 'package:base':
##
## units, units<-
Tab1_SEM4 <- table1(~ PSQu1 + PSQu2 + PSQu3 + PSQu4 + PSQu5 + PSQu6 + PSQu7 + PSQu8 + SAT1 + SAT2 + SAT3 + LOY1 + LOY2 + LOY3 + LOY4 + LOY5 + LOY6 + LOY7 + IMA1 + IMA2 + IMA3 + IMA4 + IMA5 + PHB1 + PHB2 + PHB3 + PHB4 + PHB5 + PEB1 + PEB2 + PEB3 + PEB4 + EC_Stop + WC_Stop + EC_Bus + WC_Bus + Gender + MarriedStatus + Occupation + Education + Income + MCCar + MCMotor + AGE + CITY + FRE + TripPurpose + Departure + TimeUseonBus + TravelTime| CITY , data = SEM4)
Tab1_SEM4
| DaNang (N=410) |
HoChiMinh (N=448) |
Overall (N=858) |
|
|---|---|---|---|
| PSQu1 | |||
| Mean (SD) | 5.20 (1.29) | 5.07 (1.49) | 5.13 (1.40) |
| Median [Min, Max] | 5.00 [1.00, 7.00] | 6.00 [1.00, 7.00] | 6.00 [1.00, 7.00] |
| PSQu2 | |||
| Mean (SD) | 5.74 (1.06) | 5.41 (1.40) | 5.57 (1.26) |
| Median [Min, Max] | 6.00 [1.00, 7.00] | 6.00 [1.00, 7.00] | 6.00 [1.00, 7.00] |
| PSQu3 | |||
| Mean (SD) | 5.09 (1.42) | 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] |
| PSQu4 | |||
| Mean (SD) | 4.80 (1.36) | 4.73 (1.40) | 4.77 (1.38) |
| Median [Min, Max] | 5.00 [1.00, 7.00] | 5.00 [1.00, 7.00] | 5.00 [1.00, 7.00] |
| PSQu5 | |||
| Mean (SD) | 5.15 (1.31) | 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] |
| PSQu6 | |||
| 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] |
| PSQu7 | |||
| Mean (SD) | 5.19 (1.30) | 4.86 (1.46) | 5.02 (1.40) |
| Median [Min, Max] | 5.50 [1.00, 7.00] | 5.00 [1.00, 7.00] | 5.00 [1.00, 7.00] |
| PSQu8 | |||
| Mean (SD) | 5.57 (1.20) | 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] |
| SAT1 | |||
| Mean (SD) | 5.53 (1.05) | 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.70 (0.979) | 5.33 (1.25) | 5.51 (1.14) |
| 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.75 (0.931) | 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] |
| LOY1 | |||
| Mean (SD) | 5.74 (0.890) | 5.26 (1.24) | 5.49 (1.11) |
| Median [Min, Max] | 6.00 [2.00, 7.00] | 6.00 [1.00, 7.00] | 6.00 [1.00, 7.00] |
| LOY2 | |||
| Mean (SD) | 5.79 (0.864) | 5.26 (1.31) | 5.52 (1.15) |
| Median [Min, Max] | 6.00 [2.00, 7.00] | 6.00 [1.00, 7.00] | 6.00 [1.00, 7.00] |
| LOY3 | |||
| Mean (SD) | 5.82 (0.881) | 5.39 (1.21) | 5.60 (1.09) |
| Median [Min, Max] | 6.00 [2.00, 7.00] | 6.00 [1.00, 7.00] | 6.00 [1.00, 7.00] |
| LOY4 | |||
| Mean (SD) | 5.54 (1.04) | 5.13 (1.38) | 5.32 (1.25) |
| Median [Min, Max] | 6.00 [1.00, 7.00] | 6.00 [1.00, 7.00] | 6.00 [1.00, 7.00] |
| LOY5 | |||
| Mean (SD) | 5.63 (1.03) | 5.14 (1.39) | 5.38 (1.25) |
| Median [Min, Max] | 6.00 [1.00, 7.00] | 6.00 [1.00, 7.00] | 6.00 [1.00, 7.00] |
| LOY6 | |||
| Mean (SD) | 5.35 (1.33) | 4.83 (1.59) | 5.08 (1.49) |
| Median [Min, Max] | 6.00 [1.00, 7.00] | 5.00 [1.00, 7.00] | 5.00 [1.00, 7.00] |
| LOY7 | |||
| Mean (SD) | 5.91 (0.899) | 5.37 (1.38) | 5.63 (1.21) |
| 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.979) | 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.882) | 4.95 (1.34) | 5.22 (1.18) |
| Median [Min, Max] | 6.00 [2.00, 7.00] | 5.00 [1.00, 7.00] | 6.00 [1.00, 7.00] |
| IMA3 | |||
| Mean (SD) | 5.61 (0.858) | 5.14 (1.28) | 5.36 (1.13) |
| Median [Min, Max] | 6.00 [2.00, 7.00] | 5.00 [1.00, 7.00] | 6.00 [1.00, 7.00] |
| IMA4 | |||
| Mean (SD) | 5.69 (0.873) | 5.07 (1.34) | 5.37 (1.18) |
| Median [Min, Max] | 6.00 [1.00, 7.00] | 5.00 [1.00, 7.00] | 6.00 [1.00, 7.00] |
| IMA5 | |||
| Mean (SD) | 5.72 (0.831) | 5.13 (1.27) | 5.41 (1.12) |
| Median [Min, Max] | 6.00 [2.00, 7.00] | 5.00 [1.00, 7.00] | 6.00 [1.00, 7.00] |
| PHB1 | |||
| Mean (SD) | 5.42 (1.08) | 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 (0.998) | 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.46 (1.18) | 5.42 (1.38) | 5.44 (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.06 (0.854) | 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.03 (0.863) | 5.59 (1.46) | 5.80 (1.23) |
| Median [Min, Max] | 6.00 [1.00, 7.00] | 6.00 [1.00, 7.00] | 6.00 [1.00, 7.00] |
| PEB1 | |||
| Mean (SD) | 5.96 (0.860) | 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.01) | 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.71 (1.10) | 5.36 (1.59) | 5.53 (1.39) |
| Median [Min, Max] | 6.00 [1.00, 7.00] | 6.00 [1.00, 7.00] | 6.00 [1.00, 7.00] |
| PEB4 | |||
| Mean (SD) | 5.69 (1.07) | 5.29 (1.57) | 5.48 (1.37) |
| 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 | 229 (55.9%) | 272 (60.7%) | 501 (58.4%) |
| Male | 181 (44.1%) | 176 (39.3%) | 357 (41.6%) |
| MarriedStatus | |||
| Married | 148 (36.1%) | 184 (41.1%) | 332 (38.7%) |
| Single | 262 (63.9%) | 264 (58.9%) | 526 (61.3%) |
| Occupation | |||
| Students/Pupils | 199 (48.5%) | 160 (35.7%) | 359 (41.8%) |
| Full.time.job | 115 (28.0%) | 189 (42.2%) | 304 (35.4%) |
| Part.time.job | 27 (6.6%) | 40 (8.9%) | 67 (7.8%) |
| Retirement | 33 (8.0%) | 13 (2.9%) | 46 (5.4%) |
| No.job | 3 (0.7%) | 1 (0.2%) | 4 (0.5%) |
| Housewife | 26 (6.3%) | 25 (5.6%) | 51 (5.9%) |
| Others | 7 (1.7%) | 20 (4.5%) | 27 (3.1%) |
| Education | |||
| Secondary.school | 30 (7.3%) | 29 (6.5%) | 59 (6.9%) |
| Undergraduate | 128 (31.2%) | 148 (33.0%) | 276 (32.2%) |
| High.school | 170 (41.5%) | 192 (42.9%) | 362 (42.2%) |
| Postgraduate | 63 (15.4%) | 42 (9.4%) | 105 (12.2%) |
| Others | 19 (4.6%) | 37 (8.3%) | 56 (6.5%) |
| Income | |||
| <5millions | 268 (65.4%) | 188 (42.0%) | 456 (53.1%) |
| 5-10millions | 83 (20.2%) | 165 (36.8%) | 248 (28.9%) |
| 10-15millions | 50 (12.2%) | 67 (15.0%) | 117 (13.6%) |
| >15millions | 9 (2.2%) | 28 (6.2%) | 37 (4.3%) |
| 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 | 218 (53.2%) | 200 (44.6%) | 418 (48.7%) |
| 26-35 | 76 (18.5%) | 93 (20.8%) | 169 (19.7%) |
| 36-45 | 35 (8.5%) | 66 (14.7%) | 101 (11.8%) |
| 46-55 | 34 (8.3%) | 42 (9.4%) | 76 (8.9%) |
| >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 | 262 (63.9%) | 237 (52.9%) | 499 (58.2%) |
| 2days/month-2days/week | 84 (20.5%) | 80 (17.9%) | 164 (19.1%) |
| 2days/year-1day/month | 27 (6.6%) | 70 (15.6%) | 97 (11.3%) |
| <2 days/year | 37 (9.0%) | 61 (13.6%) | 98 (11.4%) |
| TripPurpose | |||
| Working | 116 (28.3%) | 189 (42.2%) | 305 (35.5%) |
| Studying | 162 (39.5%) | 134 (29.9%) | 296 (34.5%) |
| Shopping | 45 (11.0%) | 13 (2.9%) | 58 (6.8%) |
| Entertaining | 49 (12.0%) | 47 (10.5%) | 96 (11.2%) |
| Others | 38 (9.3%) | 65 (14.5%) | 103 (12.0%) |
| Departure | |||
| Normal | 144 (35.1%) | 72 (16.1%) | 216 (25.2%) |
| Peak-Hour | 266 (64.9%) | 376 (83.9%) | 642 (74.8%) |
| TimeUseonBus | |||
| Using.telephone | 105 (25.6%) | 94 (21.0%) | 199 (23.2%) |
| Reading | 22 (5.4%) | 31 (6.9%) | 53 (6.2%) |
| Listening | 53 (12.9%) | 83 (18.5%) | 136 (15.9%) |
| Nothing | 201 (49.0%) | 216 (48.2%) | 417 (48.6%) |
| 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.830) | 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(PEB1)
hist(PEB2)
hist(PEB3)
hist(PEB4)
hist(LOY1)
hist(LOY2)
hist(LOY3)
hist(LOY4)
## 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(SEM4)
## 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 PSQu1 PSQu2 PSQu3 PSQu4 PSQu5 PSQu6 PSQu7 PSQu8
## 1 Nothing 3.00 6 4 4 4 6 4 6 2
## 2 Nothing 2.00 4 5 6 4 6 4 4 6
## 3 Nothing 0.17 2 4 1 2 1 2 2 2
## 4 Using.telephone 4.00 5 5 5 4 4 4 5 5
## 5 Nothing 2.00 6 6 4 3 6 5 5 5
## 6 Others 2.00 5 5 4 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 EC_Stop WC_Stop EC_Bus WC_Bus
## 1 6 7 6 7 7 4 4 4 4 Never Ever Never Ever
## 2 3 4 3 4 6 5 6 6 4 Never Never Ever Never
## 3 5 2 6 6 6 6 5 6 6 Never Never Never Never
## 4 5 5 5 5 5 5 5 5 5 Never Ever Never Ever
## 5 5 6 6 6 5 6 6 6 6 Never Ever Never Ever
## 6 4 6 7 6 4 7 7 5 2 Never Ever Never Ever
## Gender MarriedStatus Occupation Education Income
## 1 Female Single Students/Pupils Undergraduate <5millions
## 2 Female Single Students/Pupils Undergraduate <5millions
## 3 Male Single Students/Pupils Undergraduate <5millions
## 4 Male Single Students/Pupils Undergraduate <5millions
## 5 Male Single Students/Pupils Undergraduate <5millions
## 6 Female Single Students/Pupils High.school <5millions
str(SEM4)
## 'data.frame': 858 obs. of 50 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 ...
## $ PSQu1 : int 6 4 2 5 6 5 2 6 3 7 ...
## $ PSQu2 : int 4 5 4 5 6 5 2 6 4 7 ...
## $ PSQu3 : int 4 6 1 5 4 4 2 3 4 7 ...
## $ PSQu4 : int 4 4 2 4 3 3 2 4 4 4 ...
## $ PSQu5 : int 6 6 1 4 6 3 2 3 3 4 ...
## $ PSQu6 : int 4 4 2 4 5 3 2 5 3 4 ...
## $ PSQu7 : int 6 4 2 5 5 3 1 3 5 4 ...
## $ PSQu8 : 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 ...
## $ LOY1 : int 4 4 2 5 4 4 2 6 6 6 ...
## $ LOY2 : int 6 5 6 5 5 3 1 6 5 6 ...
## $ LOY3 : int 5 4 6 5 5 2 1 6 6 6 ...
## $ LOY4 : int 7 4 4 5 4 5 2 7 5 6 ...
## $ LOY5 : int 6 4 4 5 4 5 2 7 5 4 ...
## $ LOY6 : int 6 4 2 5 4 6 1 7 5 6 ...
## $ LOY7 : int 6 5 2 5 6 6 2 7 5 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 ...
## $ 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(SEM4)
## [1] 858 50
names(SEM4)
## [1] "MCCar" "MCMotor" "AGE" "CITY"
## [5] "FRE" "TripPurpose" "Departure" "TimeUseonBus"
## [9] "TravelTime" "PSQu1" "PSQu2" "PSQu3"
## [13] "PSQu4" "PSQu5" "PSQu6" "PSQu7"
## [17] "PSQu8" "SAT1" "SAT2" "SAT3"
## [21] "LOY1" "LOY2" "LOY3" "LOY4"
## [25] "LOY5" "LOY6" "LOY7" "IMA1"
## [29] "IMA2" "IMA3" "IMA4" "IMA5"
## [33] "PHB1" "PHB2" "PHB3" "PHB4"
## [37] "PHB5" "PEB1" "PEB2" "PEB3"
## [41] "PEB4" "EC_Stop" "WC_Stop" "EC_Bus"
## [45] "WC_Bus" "Gender" "MarriedStatus" "Occupation"
## [49] "Education" "Income"
SEM4_likert = SEM4[,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)] # BPE gom cac bien tu 10-41
head(SEM4_likert)
## AGE CITY PSQu1 PSQu2 PSQu3 PSQu4 PSQu5 PSQu6 PSQu7 PSQu8 SAT1 SAT2
## 1 16-25 HoChiMinh 6 4 4 4 6 4 6 2 6 6
## 2 16-25 HoChiMinh 4 5 6 4 6 4 4 6 5 5
## 3 16-25 HoChiMinh 2 4 1 2 1 2 2 2 2 2
## 4 16-25 HoChiMinh 5 5 5 4 4 4 5 5 5 5
## 5 16-25 HoChiMinh 6 6 4 3 6 5 5 5 4 4
## 6 16-25 HoChiMinh 5 5 4 3 3 3 3 4 4 5
## SAT3 LOY1 LOY2 LOY3 LOY4 LOY5 LOY6 LOY7 IMA1 IMA2 IMA3 IMA4 IMA5 PHB1 PHB2
## 1 6 4 6 5 7 6 6 6 6 6 6 4 6 6 7
## 2 4 4 5 4 4 4 4 5 4 5 6 5 4 3 4
## 3 2 2 6 6 4 4 2 2 4 2 5 2 2 5 2
## 4 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5
## 5 4 4 5 5 4 4 4 6 5 4 5 4 5 5 6
## 6 5 4 3 2 5 5 6 6 4 3 2 2 4 4 6
## PHB3 PHB4 PHB5 PEB1 PEB2 PEB3 PEB4 EC_Stop WC_Stop EC_Bus WC_Bus Gender
## 1 6 7 7 4 4 4 4 Never Ever Never Ever Female
## 2 3 4 6 5 6 6 4 Never Never Ever Never Female
## 3 6 6 6 6 5 6 6 Never Never Never Never Male
## 4 5 5 5 5 5 5 5 Never Ever Never Ever Male
## 5 6 6 5 6 6 6 6 Never Ever Never Ever Male
## 6 7 6 4 7 7 5 2 Never Ever Never Ever Female
str(SEM4_likert)
## 'data.frame': 858 obs. of 39 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 ...
## $ PSQu1 : int 6 4 2 5 6 5 2 6 3 7 ...
## $ PSQu2 : int 4 5 4 5 6 5 2 6 4 7 ...
## $ PSQu3 : int 4 6 1 5 4 4 2 3 4 7 ...
## $ PSQu4 : int 4 4 2 4 3 3 2 4 4 4 ...
## $ PSQu5 : int 6 6 1 4 6 3 2 3 3 4 ...
## $ PSQu6 : int 4 4 2 4 5 3 2 5 3 4 ...
## $ PSQu7 : int 6 4 2 5 5 3 1 3 5 4 ...
## $ PSQu8 : 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 ...
## $ LOY1 : int 4 4 2 5 4 4 2 6 6 6 ...
## $ LOY2 : int 6 5 6 5 5 3 1 6 5 6 ...
## $ LOY3 : int 5 4 6 5 5 2 1 6 6 6 ...
## $ LOY4 : int 7 4 4 5 4 5 2 7 5 6 ...
## $ LOY5 : int 6 4 4 5 4 5 2 7 5 4 ...
## $ LOY6 : int 6 4 2 5 4 6 1 7 5 6 ...
## $ LOY7 : int 6 5 2 5 6 6 2 7 5 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 ...
## $ 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(SEM4_likert)
## [1] 858 39
## Creat dat_PSQu1 - cot 3 cua SEM4_likert
dat_PSQu1 <- SEM4_likert [, c(1,2,3,35, 36, 37, 38, 39)]
head(dat_PSQu1)
## AGE CITY PSQu1 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_PSQu1)
## [1] 858 8
size <- 858
dat_PSQu1$BPE <- rep("PSQu1", size = size) # Tạo biến mới BPE
names(dat_PSQu1)[names(dat_PSQu1) == "PSQu1"] <- "Res" # Đổi tên biến BST thành Res
head(dat_PSQu1)
## AGE CITY Res EC_Stop WC_Stop EC_Bus WC_Bus Gender BPE
## 1 16-25 HoChiMinh 6 Never Ever Never Ever Female PSQu1
## 2 16-25 HoChiMinh 4 Never Never Ever Never Female PSQu1
## 3 16-25 HoChiMinh 2 Never Never Never Never Male PSQu1
## 4 16-25 HoChiMinh 5 Never Ever Never Ever Male PSQu1
## 5 16-25 HoChiMinh 6 Never Ever Never Ever Male PSQu1
## 6 16-25 HoChiMinh 5 Never Ever Never Ever Female PSQu1
## Creat dat_PSQu2 - cot 4 cua SEM4_likert
dat_PSQu2 <- SEM4_likert [, c(1,2,4,35, 36, 37, 38, 39)]
head(dat_PSQu2)
## AGE CITY PSQu2 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_PSQu2)
## [1] 858 8
size <- 858
dat_PSQu2$BPE <- rep("PSQu2", size = size) # Tạo biến mới BPE
names(dat_PSQu2)[names(dat_PSQu2) == "PSQu2"] <- "Res" # Đổi tên biến BST thành Res
head(dat_PSQu2)
## AGE CITY Res EC_Stop WC_Stop EC_Bus WC_Bus Gender BPE
## 1 16-25 HoChiMinh 4 Never Ever Never Ever Female PSQu2
## 2 16-25 HoChiMinh 5 Never Never Ever Never Female PSQu2
## 3 16-25 HoChiMinh 4 Never Never Never Never Male PSQu2
## 4 16-25 HoChiMinh 5 Never Ever Never Ever Male PSQu2
## 5 16-25 HoChiMinh 6 Never Ever Never Ever Male PSQu2
## 6 16-25 HoChiMinh 5 Never Ever Never Ever Female PSQu2
## Creat dat_PSQu3 - cot 5 cua SEN4_likert
dat_PSQu3 <- SEM4_likert [, c(1,2,5,35, 36, 37, 38, 39)]
head(dat_PSQu3)
## AGE CITY PSQu3 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_PSQu3)
## [1] 858 8
size <- 858
dat_PSQu3$BPE <- rep("PSQu3", size = size) # Tạo biến mới BPE
names(dat_PSQu3)[names(dat_PSQu3) == "PSQu3"] <- "Res" # Đổi tên biến BST thành Res
head(dat_PSQu3)
## AGE CITY Res EC_Stop WC_Stop EC_Bus WC_Bus Gender BPE
## 1 16-25 HoChiMinh 4 Never Ever Never Ever Female PSQu3
## 2 16-25 HoChiMinh 6 Never Never Ever Never Female PSQu3
## 3 16-25 HoChiMinh 1 Never Never Never Never Male PSQu3
## 4 16-25 HoChiMinh 5 Never Ever Never Ever Male PSQu3
## 5 16-25 HoChiMinh 4 Never Ever Never Ever Male PSQu3
## 6 16-25 HoChiMinh 4 Never Ever Never Ever Female PSQu3
## Creat dat_PSQu4 - cot 6 cua SEM4_likert
dat_PSQu4 <- SEM4_likert [, c(1,2,6,35, 36, 37, 38, 39)]
head(dat_PSQu4)
## AGE CITY PSQu4 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_PSQu4)
## [1] 858 8
size <- 858
dat_PSQu4$BPE <- rep("PSQu4", size = size) # Tạo biến mới BPE
names(dat_PSQu4)[names(dat_PSQu4) == "PSQu4"] <- "Res" # Đổi tên biến BST thành Res
head(dat_PSQu4)
## AGE CITY Res EC_Stop WC_Stop EC_Bus WC_Bus Gender BPE
## 1 16-25 HoChiMinh 4 Never Ever Never Ever Female PSQu4
## 2 16-25 HoChiMinh 4 Never Never Ever Never Female PSQu4
## 3 16-25 HoChiMinh 2 Never Never Never Never Male PSQu4
## 4 16-25 HoChiMinh 4 Never Ever Never Ever Male PSQu4
## 5 16-25 HoChiMinh 3 Never Ever Never Ever Male PSQu4
## 6 16-25 HoChiMinh 3 Never Ever Never Ever Female PSQu4
## Creat dat_PSQu5 - cot 7 cua SEM4_likert
dat_PSQu5 <- SEM4_likert [, c(1,2,7,35, 36, 37, 38, 39)]
head(dat_PSQu5)
## AGE CITY PSQu5 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_PSQu5)
## [1] 858 8
size <- 858
dat_PSQu5$BPE <- rep("PSQu5", size = size) # Tạo biến mới BPE
names(dat_PSQu5)[names(dat_PSQu5) == "PSQu5"] <- "Res" # Đổi tên biến BST thành Res
head(dat_PSQu5)
## AGE CITY Res EC_Stop WC_Stop EC_Bus WC_Bus Gender BPE
## 1 16-25 HoChiMinh 6 Never Ever Never Ever Female PSQu5
## 2 16-25 HoChiMinh 6 Never Never Ever Never Female PSQu5
## 3 16-25 HoChiMinh 1 Never Never Never Never Male PSQu5
## 4 16-25 HoChiMinh 4 Never Ever Never Ever Male PSQu5
## 5 16-25 HoChiMinh 6 Never Ever Never Ever Male PSQu5
## 6 16-25 HoChiMinh 3 Never Ever Never Ever Female PSQu5
## Creat dat_PSQu6 - cot 8 cua SEM4_likert
dat_PSQu6 <- SEM4_likert [, c(1,2,8,35, 36, 37, 38, 39)]
head(dat_PSQu6)
## AGE CITY PSQu6 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_PSQu6)
## [1] 858 8
size <- 858
dat_PSQu6$BPE <- rep("PSQu6", size = size) # Tạo biến mới BPE
names(dat_PSQu6)[names(dat_PSQu6) == "PSQu6"] <- "Res" # Đổi tên biến BST thành Res
head(dat_PSQu6)
## AGE CITY Res EC_Stop WC_Stop EC_Bus WC_Bus Gender BPE
## 1 16-25 HoChiMinh 4 Never Ever Never Ever Female PSQu6
## 2 16-25 HoChiMinh 4 Never Never Ever Never Female PSQu6
## 3 16-25 HoChiMinh 2 Never Never Never Never Male PSQu6
## 4 16-25 HoChiMinh 4 Never Ever Never Ever Male PSQu6
## 5 16-25 HoChiMinh 5 Never Ever Never Ever Male PSQu6
## 6 16-25 HoChiMinh 3 Never Ever Never Ever Female PSQu6
## Creat dat_PSQu7 - cot 9 cua SEM4_likert
dat_PSQu7 <- SEM4_likert [, c(1,2,9,35, 36, 37, 38, 39)]
head(dat_PSQu7)
## AGE CITY PSQu7 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_PSQu7)
## [1] 858 8
size <- 858
dat_PSQu7$BPE <- rep("PSQu7", size = size) # Tạo biến mới BPE
names(dat_PSQu7)[names(dat_PSQu7) == "PSQu7"] <- "Res" # Đổi tên biến BST thành Res
head(dat_PSQu7)
## AGE CITY Res EC_Stop WC_Stop EC_Bus WC_Bus Gender BPE
## 1 16-25 HoChiMinh 6 Never Ever Never Ever Female PSQu7
## 2 16-25 HoChiMinh 4 Never Never Ever Never Female PSQu7
## 3 16-25 HoChiMinh 2 Never Never Never Never Male PSQu7
## 4 16-25 HoChiMinh 5 Never Ever Never Ever Male PSQu7
## 5 16-25 HoChiMinh 5 Never Ever Never Ever Male PSQu7
## 6 16-25 HoChiMinh 3 Never Ever Never Ever Female PSQu7
## Creat dat_PSQu8 - cot 10 cua SEM4_likert
dat_PSQu8 <- SEM4_likert [, c(1,2,10,35, 36, 37, 38, 39)]
head(dat_PSQu8)
## AGE CITY PSQu8 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_PSQu8)
## [1] 858 8
size <- 858
dat_PSQu8$BPE <- rep("PSQu8", size = size) # Tạo biến mới BPE
names(dat_PSQu8)[names(dat_PSQu8) == "PSQu8"] <- "Res" # Đổi tên biến BST thành Res
head(dat_PSQu8)
## AGE CITY Res EC_Stop WC_Stop EC_Bus WC_Bus Gender BPE
## 1 16-25 HoChiMinh 2 Never Ever Never Ever Female PSQu8
## 2 16-25 HoChiMinh 6 Never Never Ever Never Female PSQu8
## 3 16-25 HoChiMinh 2 Never Never Never Never Male PSQu8
## 4 16-25 HoChiMinh 5 Never Ever Never Ever Male PSQu8
## 5 16-25 HoChiMinh 5 Never Ever Never Ever Male PSQu8
## 6 16-25 HoChiMinh 4 Never Ever Never Ever Female PSQu8
## Creat dat_SAT1 - cot 11 cua SEM4_likert
dat_SAT1 <- SEM4_likert [, c(1,2,11,35, 36, 37, 38, 39)]
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 12 cua SEM4_likert
dat_SAT2 <- SEM4_likert [, c(1,2,12,35, 36, 37, 38, 39)]
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 13 cua SEM4_likert
dat_SAT3 <- SEM4_likert [, c(1,2,13,35, 36, 37, 38, 39)]
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_LOY1 - cot 14 cua SEM4_likert
dat_LOY1 <- SEM4_likert [, c(1,2,14,35, 36, 37, 38, 39)]
head(dat_LOY1)
## AGE CITY LOY1 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 4 Never Ever Never Ever Male
## 6 16-25 HoChiMinh 4 Never Ever Never Ever Female
dim(dat_LOY1)
## [1] 858 8
size <- 858
dat_LOY1$BPE <- rep("LOY1", size = size) # Tạo biến mới BPE
names(dat_LOY1)[names(dat_LOY1) == "LOY1"] <- "Res" # Đổi tên biến BST thành Res
head(dat_LOY1)
## AGE CITY Res EC_Stop WC_Stop EC_Bus WC_Bus Gender BPE
## 1 16-25 HoChiMinh 4 Never Ever Never Ever Female LOY1
## 2 16-25 HoChiMinh 4 Never Never Ever Never Female LOY1
## 3 16-25 HoChiMinh 2 Never Never Never Never Male LOY1
## 4 16-25 HoChiMinh 5 Never Ever Never Ever Male LOY1
## 5 16-25 HoChiMinh 4 Never Ever Never Ever Male LOY1
## 6 16-25 HoChiMinh 4 Never Ever Never Ever Female LOY1
## Creat dat_LOY2 - cot 15 cua SEM4_likert
dat_LOY2 <- SEM4_likert [, c(1,2,15,35, 36, 37, 38, 39)]
head(dat_LOY2)
## AGE CITY LOY2 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 3 Never Ever Never Ever Female
dim(dat_LOY2)
## [1] 858 8
size <- 858
dat_LOY2$BPE <- rep("LOY2", size = size) # Tạo biến mới BPE
names(dat_LOY2)[names(dat_LOY2) == "LOY2"] <- "Res" # Đổi tên biến BST thành Res
head(dat_LOY2)
## AGE CITY Res EC_Stop WC_Stop EC_Bus WC_Bus Gender BPE
## 1 16-25 HoChiMinh 6 Never Ever Never Ever Female LOY2
## 2 16-25 HoChiMinh 5 Never Never Ever Never Female LOY2
## 3 16-25 HoChiMinh 6 Never Never Never Never Male LOY2
## 4 16-25 HoChiMinh 5 Never Ever Never Ever Male LOY2
## 5 16-25 HoChiMinh 5 Never Ever Never Ever Male LOY2
## 6 16-25 HoChiMinh 3 Never Ever Never Ever Female LOY2
## Creat dat_LOY3 - cot 16 cua SEM4_likert
dat_LOY3 <- SEM4_likert [, c(1,2,16,35, 36, 37, 38, 39)]
head(dat_LOY3)
## AGE CITY LOY3 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 5 Never Ever Never Ever Male
## 6 16-25 HoChiMinh 2 Never Ever Never Ever Female
dim(dat_LOY3)
## [1] 858 8
size <- 858
dat_LOY3$BPE <- rep("LOY3", size = size) # Tạo biến mới BPE
names(dat_LOY3)[names(dat_LOY3) == "LOY3"] <- "Res" # Đổi tên biến BST thành Res
head(dat_LOY3)
## AGE CITY Res EC_Stop WC_Stop EC_Bus WC_Bus Gender BPE
## 1 16-25 HoChiMinh 5 Never Ever Never Ever Female LOY3
## 2 16-25 HoChiMinh 4 Never Never Ever Never Female LOY3
## 3 16-25 HoChiMinh 6 Never Never Never Never Male LOY3
## 4 16-25 HoChiMinh 5 Never Ever Never Ever Male LOY3
## 5 16-25 HoChiMinh 5 Never Ever Never Ever Male LOY3
## 6 16-25 HoChiMinh 2 Never Ever Never Ever Female LOY3
## Creat dat_LOY4 - cot 17 cua SEM4_likert
dat_LOY4 <- SEM4_likert [, c(1,2,17,35, 36, 37, 38, 39)]
head(dat_LOY4)
## AGE CITY LOY4 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 4 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_LOY4)
## [1] 858 8
size <- 858
dat_LOY4$BPE <- rep("LOY4", size = size) # Tạo biến mới BPE
names(dat_LOY4)[names(dat_LOY4) == "LOY4"] <- "Res" # Đổi tên biến BST thành Res
head(dat_LOY4)
## AGE CITY Res EC_Stop WC_Stop EC_Bus WC_Bus Gender BPE
## 1 16-25 HoChiMinh 7 Never Ever Never Ever Female LOY4
## 2 16-25 HoChiMinh 4 Never Never Ever Never Female LOY4
## 3 16-25 HoChiMinh 4 Never Never Never Never Male LOY4
## 4 16-25 HoChiMinh 5 Never Ever Never Ever Male LOY4
## 5 16-25 HoChiMinh 4 Never Ever Never Ever Male LOY4
## 6 16-25 HoChiMinh 5 Never Ever Never Ever Female LOY4
## Creat dat_LOY5 - cot 18 cua SEM4_likert
dat_LOY5 <- SEM4_likert [, c(1,2,18,35, 36, 37, 38, 39)]
head(dat_LOY5)
## AGE CITY LOY5 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 4 Never Ever Never Ever Male
## 6 16-25 HoChiMinh 5 Never Ever Never Ever Female
dim(dat_LOY5)
## [1] 858 8
size <- 858
dat_LOY5$BPE <- rep("LOY5", size = size) # Tạo biến mới BPE
names(dat_LOY5)[names(dat_LOY5) == "LOY5"] <- "Res" # Đổi tên biến BST thành Res
head(dat_LOY5)
## AGE CITY Res EC_Stop WC_Stop EC_Bus WC_Bus Gender BPE
## 1 16-25 HoChiMinh 6 Never Ever Never Ever Female LOY5
## 2 16-25 HoChiMinh 4 Never Never Ever Never Female LOY5
## 3 16-25 HoChiMinh 4 Never Never Never Never Male LOY5
## 4 16-25 HoChiMinh 5 Never Ever Never Ever Male LOY5
## 5 16-25 HoChiMinh 4 Never Ever Never Ever Male LOY5
## 6 16-25 HoChiMinh 5 Never Ever Never Ever Female LOY5
## Creat dat_LOY6 - cot 19 cua SEM4_likert
dat_LOY6 <- SEM4_likert [, c(1,2,19,35, 36, 37, 38, 39)]
head(dat_LOY6)
## AGE CITY LOY6 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 6 Never Ever Never Ever Female
dim(dat_LOY6)
## [1] 858 8
size <- 858
dat_LOY6$BPE <- rep("LOY6", size = size) # Tạo biến mới BPE
names(dat_LOY6)[names(dat_LOY6) == "LOY6"] <- "Res" # Đổi tên biến BST thành Res
head(dat_LOY6)
## AGE CITY Res EC_Stop WC_Stop EC_Bus WC_Bus Gender BPE
## 1 16-25 HoChiMinh 6 Never Ever Never Ever Female LOY6
## 2 16-25 HoChiMinh 4 Never Never Ever Never Female LOY6
## 3 16-25 HoChiMinh 2 Never Never Never Never Male LOY6
## 4 16-25 HoChiMinh 5 Never Ever Never Ever Male LOY6
## 5 16-25 HoChiMinh 4 Never Ever Never Ever Male LOY6
## 6 16-25 HoChiMinh 6 Never Ever Never Ever Female LOY6
## Creat dat_LOY7 - cot 20 cua SEM4_likert
dat_LOY7 <- SEM4_likert [, c(1,2,20,35, 36, 37, 38, 39)]
head(dat_LOY7)
## AGE CITY LOY7 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 6 Never Ever Never Ever Male
## 6 16-25 HoChiMinh 6 Never Ever Never Ever Female
dim(dat_LOY7)
## [1] 858 8
size <- 858
dat_LOY7$BPE <- rep("LOY7", size = size) # Tạo biến mới BPE
names(dat_LOY7)[names(dat_LOY7) == "LOY7"] <- "Res" # Đổi tên biến BST thành Res
head(dat_LOY7)
## AGE CITY Res EC_Stop WC_Stop EC_Bus WC_Bus Gender BPE
## 1 16-25 HoChiMinh 6 Never Ever Never Ever Female LOY7
## 2 16-25 HoChiMinh 5 Never Never Ever Never Female LOY7
## 3 16-25 HoChiMinh 2 Never Never Never Never Male LOY7
## 4 16-25 HoChiMinh 5 Never Ever Never Ever Male LOY7
## 5 16-25 HoChiMinh 6 Never Ever Never Ever Male LOY7
## 6 16-25 HoChiMinh 6 Never Ever Never Ever Female LOY7
## Creat dat_IMA1 - cot 21 cua SEM4_likert
dat_IMA1 <- SEM4_likert [, c(1,2,21,35, 36, 37, 38, 39)]
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 22 cua SEM4_likert
dat_IMA2 <- SEM4_likert [, c(1,2,22,35, 36, 37, 38, 39)]
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 23 cua SEM4_likert
dat_IMA3 <- SEM4_likert [, c(1,2,23,35, 36, 37, 38, 39)]
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 24 cua SEM4_likert
dat_IMA4 <- SEM4_likert [, c(1,2,24,35, 36, 37, 38, 39)]
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
## Creat dat_IMA5 - cot 25 cua SEM4_likert
dat_IMA5 <- SEM4_likert [, c(1,2,25,35, 36, 37, 38, 39)]
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
## Creat dat_PHB1 - cot 26 cua SEM4_likert
dat_PHB1 <- SEM4_likert [, c(1,2,26,35, 36, 37, 38, 39)]
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
## Creat dat_PHB2 - cot 27 cua SEM4_likert
dat_PHB2 <- SEM4_likert [, c(1,2,27,35, 36, 37, 38, 39)]
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
## Creat dat_PHB3 - cot 28 cua SEN4_likert
dat_PHB3 <- SEM4_likert [, c(1,2,28,35, 36, 37, 38, 39)]
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
## Creat dat_PHB4 - cot 29 cua SEM4_likert
dat_PHB4 <- SEM4_likert [, c(1,2,29,35, 36, 37, 38, 39)]
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
## Creat dat_PHB5 - cot 30 cua SEM4_likert
dat_PHB5 <- SEM4_likert [, c(1,2,30,35, 36, 37, 38, 39)]
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
## Creat dat_PEB1 - cot 31 cua SEM4_likert
dat_PEB1 <- SEM4_likert [, c(1,2,31,35, 36, 37, 38, 39)]
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 32 cua SEM4_likert
dat_PEB2 <- SEM4_likert [, c(1,2,32,35, 36, 37, 38, 39)]
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 33 cua SEM4_likert
dat_PEB3 <- SEM4_likert [, c(1,2,33,35, 36, 37, 38, 39)]
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 34 cua SEM4_likert
dat_PEB4 <- SEM4_likert [, c(1,2,34,35, 36, 37, 38, 39)]
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(PEB4)
## NULL
## Tạo dữ liệu likert từ 32 dữ liệu: dat_PSQu1-8,dat_SAT1-3, dat_LOY1-7, dat_IMA1-5, dat_PHB1-5, dat_PEB1-4
B.Per <- rbind(dat_PSQu1, dat_PSQu2, dat_PSQu3, dat_PSQu4, dat_PSQu5, dat_PSQu6, dat_PSQu7, dat_PSQu8, dat_SAT1, dat_SAT2, dat_SAT3, dat_LOY1, dat_LOY2, dat_LOY3, dat_LOY4, dat_LOY5, dat_LOY6, dat_LOY7, 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)
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 PSQu1
## 2 16-25 HoChiMinh 4 Never Never Ever Never Female PSQu1
## 3 16-25 HoChiMinh 2 Never Never Never Never Male PSQu1
## 4 16-25 HoChiMinh 5 Never Ever Never Ever Male PSQu1
## 5 16-25 HoChiMinh 6 Never Ever Never Ever Male PSQu1
## 6 16-25 HoChiMinh 5 Never Ever Never Ever Female PSQu1
str(B.Per)
## 'data.frame': 27456 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 "PSQu1" "PSQu1" "PSQu1" "PSQu1" ...
dim(B.Per)
## [1] 27456 9
## Tạo dữ liệu likert theo constructs
B.Per_PSQ <- rbind(dat_PSQu1, dat_PSQu2, dat_PSQu3, dat_PSQu4, dat_PSQu5, dat_PSQu6, dat_PSQu7, dat_PSQu8)
head(B.Per_PSQ)
## AGE CITY Res EC_Stop WC_Stop EC_Bus WC_Bus Gender BPE
## 1 16-25 HoChiMinh 6 Never Ever Never Ever Female PSQu1
## 2 16-25 HoChiMinh 4 Never Never Ever Never Female PSQu1
## 3 16-25 HoChiMinh 2 Never Never Never Never Male PSQu1
## 4 16-25 HoChiMinh 5 Never Ever Never Ever Male PSQu1
## 5 16-25 HoChiMinh 6 Never Ever Never Ever Male PSQu1
## 6 16-25 HoChiMinh 5 Never Ever Never Ever Female PSQu1
str(B.Per_PSQ)
## 'data.frame': 6864 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 "PSQu1" "PSQu1" "PSQu1" "PSQu1" ...
dim(B.Per_PSQ)
## [1] 6864 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_LOY <- rbind(dat_LOY1, dat_LOY2, dat_LOY3, dat_LOY4, dat_LOY5, dat_LOY6, dat_LOY7)
head(B.Per_LOY)
## AGE CITY Res EC_Stop WC_Stop EC_Bus WC_Bus Gender BPE
## 1 16-25 HoChiMinh 4 Never Ever Never Ever Female LOY1
## 2 16-25 HoChiMinh 4 Never Never Ever Never Female LOY1
## 3 16-25 HoChiMinh 2 Never Never Never Never Male LOY1
## 4 16-25 HoChiMinh 5 Never Ever Never Ever Male LOY1
## 5 16-25 HoChiMinh 4 Never Ever Never Ever Male LOY1
## 6 16-25 HoChiMinh 4 Never Ever Never Ever Female LOY1
str(B.Per_LOY)
## 'data.frame': 6006 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 5 4 4 2 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 "LOY1" "LOY1" "LOY1" "LOY1" ...
dim(B.Per_LOY)
## [1] 6006 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
# 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_SEM4 = subset(B.Per, CITY == "DaNang")
head(DN_SEM4)
## AGE CITY Res EC_Stop WC_Stop EC_Bus WC_Bus Gender BPE
## 449 26-35 DaNang 6 Never Never Never Never Male PSQu1
## 450 46-55 DaNang 6 Never Never Never Never Female PSQu1
## 451 46-55 DaNang 6 Never Never Never Never Female PSQu1
## 452 26-35 DaNang 5 Never Never Never Never Female PSQu1
## 453 46-55 DaNang 6 Never Never Never Never Female PSQu1
## 454 16-25 DaNang 5 Never Never Never Never Female PSQu1
str(DN_SEM4)
## 'data.frame': 13120 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 5 1 7 3 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 "PSQu1" "PSQu1" "PSQu1" "PSQu1" ...
dim(DN_SEM4)
## [1] 13120 9
DN_SEM4 = DN_SEM4[ , c(3, 9)]
dim(DN_SEM4)
## [1] 13120 2
head(DN_SEM4)
## Res BPE
## 449 6 PSQu1
## 450 6 PSQu1
## 451 6 PSQu1
## 452 5 PSQu1
## 453 6 PSQu1
## 454 5 PSQu1
# Data Bus perception of people in Ho Chi Minh
HCM_SEM4 = subset(B.Per, CITY == "HoChiMinh")
head(HCM_SEM4)
## AGE CITY Res EC_Stop WC_Stop EC_Bus WC_Bus Gender BPE
## 1 16-25 HoChiMinh 6 Never Ever Never Ever Female PSQu1
## 2 16-25 HoChiMinh 4 Never Never Ever Never Female PSQu1
## 3 16-25 HoChiMinh 2 Never Never Never Never Male PSQu1
## 4 16-25 HoChiMinh 5 Never Ever Never Ever Male PSQu1
## 5 16-25 HoChiMinh 6 Never Ever Never Ever Male PSQu1
## 6 16-25 HoChiMinh 5 Never Ever Never Ever Female PSQu1
str(HCM_SEM4)
## 'data.frame': 14336 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 "PSQu1" "PSQu1" "PSQu1" "PSQu1" ...
dim(HCM_SEM4)
## [1] 14336 9
HCM_SEM4 = HCM_SEM4[ , c(3, 9)]
dim(HCM_SEM4)
## [1] 14336 2
head(HCM_SEM4)
## Res BPE
## 1 6 PSQu1
## 2 4 PSQu1
## 3 2 PSQu1
## 4 5 PSQu1
## 5 6 PSQu1
## 6 5 PSQu1
# Data Bus perception of people in both Da Nang and Ho Chi Minh cities
DN_HCM_SEM4 = B.Per[, c(3, 9)]
str(DN_HCM_SEM4)
## 'data.frame': 27456 obs. of 2 variables:
## $ Res: int 6 4 2 5 6 5 2 6 3 7 ...
## $ BPE: chr "PSQu1" "PSQu1" "PSQu1" "PSQu1" ...
dim(DN_HCM_SEM4)
## [1] 27456 2
head(DN_HCM_SEM4)
## Res BPE
## 1 6 PSQu1
## 2 4 PSQu1
## 3 2 PSQu1
## 4 5 PSQu1
## 5 6 PSQu1
## 6 5 PSQu1
# Data bus perception of people in both Da Nang and Ho Chi Minh cities - according constructs
## Construct PSA
DN_HCM_SEM4_PSQ = B.Per_PSQ[ , c(3, 9)]
dim(DN_HCM_SEM4_PSQ)
## [1] 6864 2
head(DN_HCM_SEM4_PSQ)
## Res BPE
## 1 6 PSQu1
## 2 4 PSQu1
## 3 2 PSQu1
## 4 5 PSQu1
## 5 6 PSQu1
## 6 5 PSQu1
## Construct SAT
DN_HCM_SEM4_SAT = B.Per_SAT[ , c(3, 9)]
dim(DN_HCM_SEM4_SAT)
## [1] 2574 2
head(DN_HCM_SEM4_SAT)
## Res BPE
## 1 6 SAT1
## 2 5 SAT1
## 3 2 SAT1
## 4 5 SAT1
## 5 4 SAT1
## 6 4 SAT1
## Construct LOY
DN_HCM_SEM4_LOY = B.Per_LOY[ , c(3, 9)]
dim(DN_HCM_SEM4_LOY)
## [1] 6006 2
head(DN_HCM_SEM4_LOY)
## Res BPE
## 1 4 LOY1
## 2 4 LOY1
## 3 2 LOY1
## 4 5 LOY1
## 5 4 LOY1
## 6 4 LOY1
## Construct IMA
DN_HCM_SEM4_IMA = B.Per_IMA[ , c(3, 9)]
dim(DN_HCM_SEM4_IMA)
## [1] 4290 2
head(DN_HCM_SEM4_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_SEM4_PHB = B.Per_PHB[ , c(3, 9)]
dim(DN_HCM_SEM4_PHB)
## [1] 4290 2
head(DN_HCM_SEM4_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_SEM4_PEB = B.Per_PEB[ , c(3, 9)]
dim(DN_HCM_SEM4_PEB)
## [1] 3432 2
head(DN_HCM_SEM4_PEB)
## Res BPE
## 1 4 PEB1
## 2 5 PEB1
## 3 6 PEB1
## 4 5 PEB1
## 5 6 PEB1
## 6 7 PEB1
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_SEM4)
## Res BPE
## 1 6 PSQu1
## 2 4 PSQu1
## 3 2 PSQu1
## 4 5 PSQu1
## 5 6 PSQu1
## 6 5 PSQu1
dim(DN_HCM_SEM4)
## [1] 27456 2
attach(DN_HCM_SEM4)
DN_HCM_SEM4 = within(DN_HCM_SEM4, {
Res = factor(Res, labels = c("Very Disagree", "Disagree", "Quite Disagree", "Normal", "Quite Agree", "Agree", "Very Agree"))
BPE = factor(BPE, labels = c("PSQu1", "PSQu2", "PSQu3", "PSQu4", "PSQu5", "PSQu6", "PSQu7", "PSQu8", "SAT1", "SAT2", "SAT3", "LOY1", "LOY2", "LOY3", "LOY4", "LOY5", "LOY6", "LOY7", "IMA1", "IMA2", "IMA3", "IMA4", "IMA5", "PHB1", "PHB2", "PHB3", "PHB4", "PHB5", "PEB1", "PEB2", "PEB3", "PEB4"))
})
str(DN_HCM_SEM4)
## 'data.frame': 27456 obs. of 2 variables:
## $ Res: Factor w/ 7 levels "Very Disagree",..: 6 4 2 5 6 5 2 6 3 7 ...
## $ BPE: Factor w/ 32 levels "PSQu1","PSQu2",..: 22 22 22 22 22 22 22 22 22 22 ...
summary(DN_HCM_SEM4)
## Res BPE
## Very Disagree : 456 PSQu1 : 858
## Disagree : 777 PSQu2 : 858
## Quite Disagree: 974 PSQu3 : 858
## Normal : 3386 PSQu4 : 858
## Quite Agree : 5847 PSQu5 : 858
## Agree :11905 PSQu6 : 858
## Very Agree : 4111 (Other):22308
## t <- compareGroups(Res ~ BPE, data = DN_HCM_SEM1)
## createTable(t)
DN_HCM_SEM4 %>%
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] PSQu1 PSQu2 PSQu3 PSQu4 PSQu5 PSQu6 PSQu7 PSQu8 SAT1 SAT2 SAT3 LOY1
## [13] LOY2 LOY3 LOY4 LOY5 LOY6 LOY7 IMA1 IMA2 IMA3 IMA4 IMA5 PHB1
## [25] PHB2 PHB3 PHB4 PHB5 PEB1 PEB2 PEB3 PEB4
## 32 Levels: PSQu1 PSQu2 PSQu3 PSQu4 PSQu5 PSQu6 PSQu7 PSQu8 SAT1 SAT2 ... 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: 224 x 5
## BPE Res n percent bar_text
## <fct> <fct> <int> <dbl> <chr>
## 1 PSQu1 Very Disagree 6 0.7 0.7%
## 2 PSQu1 Disagree 20 2.33 2.33%
## 3 PSQu1 Quite Disagree 32 3.73 3.73%
## 4 PSQu1 Normal 155 18.1 18.07%
## 5 PSQu1 Quite Agree 230 26.8 26.81%
## 6 PSQu1 Agree 350 40.8 40.79%
## 7 PSQu1 Very Agree 65 7.58 7.58%
## 8 PSQu2 Very Disagree 11 1.28 1.28%
## 9 PSQu2 Disagree 19 2.21 2.21%
## 10 PSQu2 Quite Disagree 25 2.91 2.91%
## # ... with 214 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: 32 x 5
## BPE Res n percent bar_text
## <fct> <fct> <int> <dbl> <chr>
## 1 PSQu1 Very Disagree 6 0.7 0.7%
## 2 PSQu2 Very Disagree 11 1.28 1.28%
## 3 PSQu3 Very Disagree 11 1.28 1.28%
## 4 PSQu4 Very Disagree 14 1.63 1.63%
## 5 PSQu5 Very Disagree 6 0.7 0.7%
## 6 PSQu6 Very Disagree 4 0.47 0.47%
## 7 PSQu7 Very Disagree 6 0.7 0.7%
## 8 PSQu8 Very Disagree 3 0.35 0.35%
## 9 SAT1 Very Disagree 13 1.52 1.52%
## 10 SAT2 Very Disagree 12 1.4 1.4%
## # ... with 22 more rows
# For displaying percent of "Disagree":
df_odered %>%
filter(Res == "Disagree") %>%
filter(percent >= 0) -> df_for_text2
df_for_text2
## # A tibble: 32 x 5
## BPE Res n percent bar_text
## <fct> <fct> <int> <dbl> <chr>
## 1 PSQu1 Disagree 20 2.33 2.33%
## 2 PSQu2 Disagree 19 2.21 2.21%
## 3 PSQu3 Disagree 11 1.28 1.28%
## 4 PSQu4 Disagree 14 1.63 1.63%
## 5 PSQu5 Disagree 21 2.45 2.45%
## 6 PSQu6 Disagree 18 2.1 2.1%
## 7 PSQu7 Disagree 22 2.56 2.56%
## 8 PSQu8 Disagree 16 1.86 1.86%
## 9 SAT1 Disagree 17 1.98 1.98%
## 10 SAT2 Disagree 23 2.68 2.68%
## # ... with 22 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: 32 x 5
## BPE Res n percent bar_text
## <fct> <fct> <int> <dbl> <chr>
## 1 PSQu1 Quite Disagree 32 3.73 3.73%
## 2 PSQu2 Quite Disagree 25 2.91 2.91%
## 3 PSQu3 Quite Disagree 20 2.33 2.33%
## 4 PSQu4 Quite Disagree 26 3.03 3.03%
## 5 PSQu5 Quite Disagree 21 2.45 2.45%
## 6 PSQu6 Quite Disagree 19 2.21 2.21%
## 7 PSQu7 Quite Disagree 16 1.86 1.86%
## 8 PSQu8 Quite Disagree 18 2.1 2.1%
## 9 SAT1 Quite Disagree 31 3.61 3.61%
## 10 SAT2 Quite Disagree 25 2.91 2.91%
## # ... with 22 more rows
# For displaying percent of "Normal":
df_odered %>%
filter(Res == "Normal") %>%
filter(percent >= 0) -> df_for_text4
df_for_text4
## # A tibble: 32 x 5
## BPE Res n percent bar_text
## <fct> <fct> <int> <dbl> <chr>
## 1 PSQu1 Normal 155 18.1 18.07%
## 2 PSQu2 Normal 158 18.4 18.41%
## 3 PSQu3 Normal 129 15.0 15.03%
## 4 PSQu4 Normal 113 13.2 13.17%
## 5 PSQu5 Normal 105 12.2 12.24%
## 6 PSQu6 Normal 114 13.3 13.29%
## 7 PSQu7 Normal 99 11.5 11.54%
## 8 PSQu8 Normal 92 10.7 10.72%
## 9 SAT1 Normal 130 15.2 15.15%
## 10 SAT2 Normal 111 12.9 12.94%
## # ... with 22 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: 32 x 5
## BPE Res n percent bar_text
## <fct> <fct> <int> <dbl> <chr>
## 1 PSQu1 Quite Agree 230 26.8 26.81%
## 2 PSQu2 Quite Agree 213 24.8 24.83%
## 3 PSQu3 Quite Agree 207 24.1 24.13%
## 4 PSQu4 Quite Agree 199 23.2 23.19%
## 5 PSQu5 Quite Agree 203 23.7 23.66%
## 6 PSQu6 Quite Agree 167 19.5 19.46%
## 7 PSQu7 Quite Agree 169 19.7 19.7%
## 8 PSQu8 Quite Agree 160 18.6 18.65%
## 9 SAT1 Quite Agree 212 24.7 24.71%
## 10 SAT2 Quite Agree 214 24.9 24.94%
## # ... with 22 more rows
# For displaying percent of "Agree":
df_odered %>%
filter(Res == "Agree") %>%
filter(percent >= 0) -> df_for_text6
df_for_text6
## # A tibble: 32 x 5
## BPE Res n percent bar_text
## <fct> <fct> <int> <dbl> <chr>
## 1 PSQu1 Agree 350 40.8 40.79%
## 2 PSQu2 Agree 366 42.7 42.66%
## 3 PSQu3 Agree 401 46.7 46.74%
## 4 PSQu4 Agree 406 47.3 47.32%
## 5 PSQu5 Agree 418 48.7 48.72%
## 6 PSQu6 Agree 430 50.1 50.12%
## 7 PSQu7 Agree 428 49.9 49.88%
## 8 PSQu8 Agree 437 50.9 50.93%
## 9 SAT1 Agree 337 39.3 39.28%
## 10 SAT2 Agree 344 40.1 40.09%
## # ... with 22 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: 32 x 5
## BPE Res n percent bar_text
## <fct> <fct> <int> <dbl> <chr>
## 1 PSQu1 Very Agree 65 7.58 7.58%
## 2 PSQu2 Very Agree 66 7.69 7.69%
## 3 PSQu3 Very Agree 79 9.21 9.21%
## 4 PSQu4 Very Agree 86 10.0 10.02%
## 5 PSQu5 Very Agree 84 9.79 9.79%
## 6 PSQu6 Very Agree 106 12.4 12.35%
## 7 PSQu7 Very Agree 118 13.8 13.75%
## 8 PSQu8 Very Agree 132 15.4 15.38%
## 9 SAT1 Very Agree 118 13.8 13.75%
## 10 SAT2 Very Agree 129 15.0 15.03%
## # ... with 22 more rows
# For displaying percent of "Very Agree":
df_odered %>%
filter(Res == "Very Agree") -> df_for_text
df_for_text
## # A tibble: 32 x 5
## BPE Res n percent bar_text
## <fct> <fct> <int> <dbl> <chr>
## 1 PSQu1 Very Agree 65 7.58 7.58%
## 2 PSQu2 Very Agree 66 7.69 7.69%
## 3 PSQu3 Very Agree 79 9.21 9.21%
## 4 PSQu4 Very Agree 86 10.0 10.02%
## 5 PSQu5 Very Agree 84 9.79 9.79%
## 6 PSQu6 Very Agree 106 12.4 12.35%
## 7 PSQu7 Very Agree 118 13.8 13.75%
## 8 PSQu8 Very Agree 132 15.4 15.38%
## 9 SAT1 Very Agree 118 13.8 13.75%
## 10 SAT2 Very Agree 129 15.0 15.03%
## # ... with 22 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_SEM4_v = within(DN_HCM_SEM4, {
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("PSQu1", "PSQu2", "PSQu3", "PSQu4", "PSQu5", "PSQu6", "PSQu7", "PSQu8", "SAT1", "SAT2", "SAT3", "LOY1", "LOY2", "LOY3", "LOY4", "LOY5", "LOY6", "LOY7", "IMA1", "IMA2", "IMA3", "IMA4", "IMA5", "PHB1", "PHB2", "PHB3", "PHB4", "PHB5", "PEB1", "PEB2", "PEB3", "PEB4"))
})
str(DN_HCM_SEM4_v)
## 'data.frame': 27456 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/ 32 levels "PSQu1","PSQu2",..: 22 22 22 22 22 22 22 22 22 22 ...
summary(DN_HCM_SEM4_v)
## Res BPE
## R<U+1EA5>t không d<U+1ED3>ng ý: 456 PSQu1 : 858
## Không d<U+1ED3>ng ý : 777 PSQu2 : 858
## Khá không d<U+1ED3>ng ý : 974 PSQu3 : 858
## Bình thu<U+1EDD>ng : 3386 PSQu4 : 858
## Khá d<U+1ED3>ng ý : 5847 PSQu5 : 858
## Ð<U+1ED3>ng ý :11905 PSQu6 : 858
## R<U+1EA5>t d<U+1ED3>ng ý : 4111 (Other):22308
## t <- compareGroups(Res ~ BPE, data = DN_HCM_SEM1)
## createTable(t)
DN_HCM_SEM4_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] PSQu1 PSQu2 PSQu3 PSQu4 PSQu5 PSQu6 PSQu7 PSQu8 SAT1 SAT2 SAT3 LOY1
## [13] LOY2 LOY3 LOY4 LOY5 LOY6 LOY7 IMA1 IMA2 IMA3 IMA4 IMA5 PHB1
## [25] PHB2 PHB3 PHB4 PHB5 PEB1 PEB2 PEB3 PEB4
## 32 Levels: PSQu1 PSQu2 PSQu3 PSQu4 PSQu5 PSQu6 PSQu7 PSQu8 SAT1 SAT2 ... 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: 224 x 5
## BPE Res n percent bar_text
## <fct> <fct> <int> <dbl> <chr>
## 1 PSQu1 R<U+1EA5>t không d<U+1ED3>ng ý 6 0.7 0.7%
## 2 PSQu1 Không d<U+1ED3>ng ý 20 2.33 2.33%
## 3 PSQu1 Khá không d<U+1ED3>ng ý 32 3.73 3.73%
## 4 PSQu1 Bình thu<U+1EDD>ng 155 18.1 18.07%
## 5 PSQu1 Khá d<U+1ED3>ng ý 230 26.8 26.81%
## 6 PSQu1 Ð<U+1ED3>ng ý 350 40.8 40.79%
## 7 PSQu1 R<U+1EA5>t d<U+1ED3>ng ý 65 7.58 7.58%
## 8 PSQu2 R<U+1EA5>t không d<U+1ED3>ng ý 11 1.28 1.28%
## 9 PSQu2 Không d<U+1ED3>ng ý 19 2.21 2.21%
## 10 PSQu2 Khá không d<U+1ED3>ng ý 25 2.91 2.91%
## # ... with 214 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: 32 x 5
## BPE Res n percent bar_text
## <fct> <fct> <int> <dbl> <chr>
## 1 PSQu1 R<U+1EA5>t không d<U+1ED3>ng ý 6 0.7 0.7%
## 2 PSQu2 R<U+1EA5>t không d<U+1ED3>ng ý 11 1.28 1.28%
## 3 PSQu3 R<U+1EA5>t không d<U+1ED3>ng ý 11 1.28 1.28%
## 4 PSQu4 R<U+1EA5>t không d<U+1ED3>ng ý 14 1.63 1.63%
## 5 PSQu5 R<U+1EA5>t không d<U+1ED3>ng ý 6 0.7 0.7%
## 6 PSQu6 R<U+1EA5>t không d<U+1ED3>ng ý 4 0.47 0.47%
## 7 PSQu7 R<U+1EA5>t không d<U+1ED3>ng ý 6 0.7 0.7%
## 8 PSQu8 R<U+1EA5>t không d<U+1ED3>ng ý 3 0.35 0.35%
## 9 SAT1 R<U+1EA5>t không d<U+1ED3>ng ý 13 1.52 1.52%
## 10 SAT2 R<U+1EA5>t không d<U+1ED3>ng ý 12 1.4 1.4%
## # ... with 22 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: 32 x 5
## BPE Res n percent bar_text
## <fct> <fct> <int> <dbl> <chr>
## 1 PSQu1 Không d<U+1ED3>ng ý 20 2.33 2.33%
## 2 PSQu2 Không d<U+1ED3>ng ý 19 2.21 2.21%
## 3 PSQu3 Không d<U+1ED3>ng ý 11 1.28 1.28%
## 4 PSQu4 Không d<U+1ED3>ng ý 14 1.63 1.63%
## 5 PSQu5 Không d<U+1ED3>ng ý 21 2.45 2.45%
## 6 PSQu6 Không d<U+1ED3>ng ý 18 2.1 2.1%
## 7 PSQu7 Không d<U+1ED3>ng ý 22 2.56 2.56%
## 8 PSQu8 Không d<U+1ED3>ng ý 16 1.86 1.86%
## 9 SAT1 Không d<U+1ED3>ng ý 17 1.98 1.98%
## 10 SAT2 Không d<U+1ED3>ng ý 23 2.68 2.68%
## # ... with 22 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: 32 x 5
## BPE Res n percent bar_text
## <fct> <fct> <int> <dbl> <chr>
## 1 PSQu1 Khá không d<U+1ED3>ng ý 32 3.73 3.73%
## 2 PSQu2 Khá không d<U+1ED3>ng ý 25 2.91 2.91%
## 3 PSQu3 Khá không d<U+1ED3>ng ý 20 2.33 2.33%
## 4 PSQu4 Khá không d<U+1ED3>ng ý 26 3.03 3.03%
## 5 PSQu5 Khá không d<U+1ED3>ng ý 21 2.45 2.45%
## 6 PSQu6 Khá không d<U+1ED3>ng ý 19 2.21 2.21%
## 7 PSQu7 Khá không d<U+1ED3>ng ý 16 1.86 1.86%
## 8 PSQu8 Khá không d<U+1ED3>ng ý 18 2.1 2.1%
## 9 SAT1 Khá không d<U+1ED3>ng ý 31 3.61 3.61%
## 10 SAT2 Khá không d<U+1ED3>ng ý 25 2.91 2.91%
## # ... with 22 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: 32 x 5
## BPE Res n percent bar_text
## <fct> <fct> <int> <dbl> <chr>
## 1 PSQu1 Bình thu<U+1EDD>ng 155 18.1 18.07%
## 2 PSQu2 Bình thu<U+1EDD>ng 158 18.4 18.41%
## 3 PSQu3 Bình thu<U+1EDD>ng 129 15.0 15.03%
## 4 PSQu4 Bình thu<U+1EDD>ng 113 13.2 13.17%
## 5 PSQu5 Bình thu<U+1EDD>ng 105 12.2 12.24%
## 6 PSQu6 Bình thu<U+1EDD>ng 114 13.3 13.29%
## 7 PSQu7 Bình thu<U+1EDD>ng 99 11.5 11.54%
## 8 PSQu8 Bình thu<U+1EDD>ng 92 10.7 10.72%
## 9 SAT1 Bình thu<U+1EDD>ng 130 15.2 15.15%
## 10 SAT2 Bình thu<U+1EDD>ng 111 12.9 12.94%
## # ... with 22 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: 32 x 5
## BPE Res n percent bar_text
## <fct> <fct> <int> <dbl> <chr>
## 1 PSQu1 Khá d<U+1ED3>ng ý 230 26.8 26.81%
## 2 PSQu2 Khá d<U+1ED3>ng ý 213 24.8 24.83%
## 3 PSQu3 Khá d<U+1ED3>ng ý 207 24.1 24.13%
## 4 PSQu4 Khá d<U+1ED3>ng ý 199 23.2 23.19%
## 5 PSQu5 Khá d<U+1ED3>ng ý 203 23.7 23.66%
## 6 PSQu6 Khá d<U+1ED3>ng ý 167 19.5 19.46%
## 7 PSQu7 Khá d<U+1ED3>ng ý 169 19.7 19.7%
## 8 PSQu8 Khá d<U+1ED3>ng ý 160 18.6 18.65%
## 9 SAT1 Khá d<U+1ED3>ng ý 212 24.7 24.71%
## 10 SAT2 Khá d<U+1ED3>ng ý 214 24.9 24.94%
## # ... with 22 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: 32 x 5
## BPE Res n percent bar_text
## <fct> <fct> <int> <dbl> <chr>
## 1 PSQu1 Ð<U+1ED3>ng ý 350 40.8 40.79%
## 2 PSQu2 Ð<U+1ED3>ng ý 366 42.7 42.66%
## 3 PSQu3 Ð<U+1ED3>ng ý 401 46.7 46.74%
## 4 PSQu4 Ð<U+1ED3>ng ý 406 47.3 47.32%
## 5 PSQu5 Ð<U+1ED3>ng ý 418 48.7 48.72%
## 6 PSQu6 Ð<U+1ED3>ng ý 430 50.1 50.12%
## 7 PSQu7 Ð<U+1ED3>ng ý 428 49.9 49.88%
## 8 PSQu8 Ð<U+1ED3>ng ý 437 50.9 50.93%
## 9 SAT1 Ð<U+1ED3>ng ý 337 39.3 39.28%
## 10 SAT2 Ð<U+1ED3>ng ý 344 40.1 40.09%
## # ... with 22 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: 32 x 5
## BPE Res n percent bar_text
## <fct> <fct> <int> <dbl> <chr>
## 1 PSQu1 R<U+1EA5>t d<U+1ED3>ng ý 65 7.58 7.58%
## 2 PSQu2 R<U+1EA5>t d<U+1ED3>ng ý 66 7.69 7.69%
## 3 PSQu3 R<U+1EA5>t d<U+1ED3>ng ý 79 9.21 9.21%
## 4 PSQu4 R<U+1EA5>t d<U+1ED3>ng ý 86 10.0 10.02%
## 5 PSQu5 R<U+1EA5>t d<U+1ED3>ng ý 84 9.79 9.79%
## 6 PSQu6 R<U+1EA5>t d<U+1ED3>ng ý 106 12.4 12.35%
## 7 PSQu7 R<U+1EA5>t d<U+1ED3>ng ý 118 13.8 13.75%
## 8 PSQu8 R<U+1EA5>t d<U+1ED3>ng ý 132 15.4 15.38%
## 9 SAT1 R<U+1EA5>t d<U+1ED3>ng ý 118 13.8 13.75%
## 10 SAT2 R<U+1EA5>t d<U+1ED3>ng ý 129 15.0 15.03%
## # ... with 22 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: 32 x 5
## BPE Res n percent bar_text
## <fct> <fct> <int> <dbl> <chr>
## 1 PSQu1 R<U+1EA5>t d<U+1ED3>ng ý 65 7.58 7.58%
## 2 PSQu2 R<U+1EA5>t d<U+1ED3>ng ý 66 7.69 7.69%
## 3 PSQu3 R<U+1EA5>t d<U+1ED3>ng ý 79 9.21 9.21%
## 4 PSQu4 R<U+1EA5>t d<U+1ED3>ng ý 86 10.0 10.02%
## 5 PSQu5 R<U+1EA5>t d<U+1ED3>ng ý 84 9.79 9.79%
## 6 PSQu6 R<U+1EA5>t d<U+1ED3>ng ý 106 12.4 12.35%
## 7 PSQu7 R<U+1EA5>t d<U+1ED3>ng ý 118 13.8 13.75%
## 8 PSQu8 R<U+1EA5>t d<U+1ED3>ng ý 132 15.4 15.38%
## 9 SAT1 R<U+1EA5>t d<U+1ED3>ng ý 118 13.8 13.75%
## 10 SAT2 R<U+1EA5>t d<U+1ED3>ng ý 129 15.0 15.03%
## # ... with 22 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_SEM4)
## Res BPE
## 449 6 PSQu1
## 450 6 PSQu1
## 451 6 PSQu1
## 452 5 PSQu1
## 453 6 PSQu1
## 454 5 PSQu1
dim(DN_SEM4)
## [1] 13120 2
attach(DN_SEM4)
## The following objects are masked from DN_HCM_SEM4:
##
## BPE, Res
DN_SEM4 = within(DN_SEM4, {
Res = factor(Res, labels = c("Very Disagree", "Disagree", "Quite Disagree", "Normal", "Quite Agree", "Agree", "Very Agree"))
BPE = factor(BPE, labels = c("PSQu1", "PSQu2", "PSQu3", "PSQu4", "PSQu5", "PSQu6", "PSQu7", "PSQu8", "SAT1", "SAT2", "SAT3", "LOY1", "LOY2", "LOY3", "LOY4", "LOy5", "LOY6", "LOY7", "IMA1", "IMA2", "IMA3", "IMA4", "IMA5", "PHB1", "PHB2", "PHB3", "PHB4", "PHB5", "PEB1", "PEB2", "PEB3", "PEB4"))
})
str(DN_SEM4)
## 'data.frame': 13120 obs. of 2 variables:
## $ Res: Factor w/ 7 levels "Very Disagree",..: 6 6 6 5 6 5 1 7 3 6 ...
## $ BPE: Factor w/ 32 levels "PSQu1","PSQu2",..: 22 22 22 22 22 22 22 22 22 22 ...
summary(DN_SEM4)
## Res BPE
## Very Disagree : 67 PSQu1 : 410
## Disagree : 181 PSQu2 : 410
## Quite Disagree: 457 PSQu3 : 410
## Normal :1091 PSQu4 : 410
## Quite Agree :3174 PSQu5 : 410
## Agree :5931 PSQu6 : 410
## Very Agree :2219 (Other):10660
## t <- compareGroups(Res ~ BPE, data = DN_SEM1)
## createTable(t)
DN_SEM4 %>%
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] PSQu1 PSQu2 PSQu3 PSQu4 PSQu5 PSQu6 PSQu7 PSQu8 SAT1 SAT2 SAT3 LOY1
## [13] LOY2 LOY3 LOY4 LOy5 LOY6 LOY7 IMA1 IMA2 IMA3 IMA4 IMA5 PHB1
## [25] PHB2 PHB3 PHB4 PHB5 PEB1 PEB2 PEB3 PEB4
## 32 Levels: PSQu1 PSQu2 PSQu3 PSQu4 PSQu5 PSQu6 PSQu7 PSQu8 SAT1 SAT2 ... 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: 208 x 5
## BPE Res n percent bar_text
## <fct> <fct> <int> <dbl> <chr>
## 1 PSQu1 Very Disagree 1 0.24 0.24%
## 2 PSQu1 Disagree 3 0.73 0.73%
## 3 PSQu1 Quite Disagree 11 2.68 2.68%
## 4 PSQu1 Normal 55 13.4 13.41%
## 5 PSQu1 Quite Agree 137 33.4 33.41%
## 6 PSQu1 Agree 170 41.5 41.46%
## 7 PSQu1 Very Agree 33 8.05 8.05%
## 8 PSQu2 Disagree 1 0.24 0.24%
## 9 PSQu2 Quite Disagree 7 1.71 1.71%
## 10 PSQu2 Normal 47 11.5 11.46%
## # ... with 198 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: 21 x 5
## BPE Res n percent bar_text
## <fct> <fct> <int> <dbl> <chr>
## 1 PSQu1 Very Disagree 1 0.24 0.24%
## 2 PSQu4 Very Disagree 1 0.24 0.24%
## 3 SAT1 Very Disagree 1 0.24 0.24%
## 4 SAT2 Very Disagree 1 0.24 0.24%
## 5 SAT3 Very Disagree 1 0.24 0.24%
## 6 LOY1 Very Disagree 1 0.24 0.24%
## 7 LOY2 Very Disagree 1 0.24 0.24%
## 8 LOY3 Very Disagree 1 0.24 0.24%
## 9 LOY4 Very Disagree 1 0.24 0.24%
## 10 LOY6 Very Disagree 1 0.24 0.24%
## # ... with 11 more rows
# For displaying percent of "Disagree":
df_odered %>%
filter(Res == "Disagree") %>%
filter(percent >= 0) -> df_for_text2
df_for_text2
## # A tibble: 27 x 5
## BPE Res n percent bar_text
## <fct> <fct> <int> <dbl> <chr>
## 1 PSQu1 Disagree 3 0.73 0.73%
## 2 PSQu2 Disagree 1 0.24 0.24%
## 3 PSQu3 Disagree 1 0.24 0.24%
## 4 PSQu5 Disagree 1 0.24 0.24%
## 5 PSQu6 Disagree 2 0.49 0.49%
## 6 PSQu7 Disagree 1 0.24 0.24%
## 7 PSQu8 Disagree 1 0.24 0.24%
## 8 SAT2 Disagree 2 0.49 0.49%
## 9 SAT3 Disagree 14 3.41 3.41%
## 10 LOY2 Disagree 1 0.24 0.24%
## # ... with 17 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: 32 x 5
## BPE Res n percent bar_text
## <fct> <fct> <int> <dbl> <chr>
## 1 PSQu1 Quite Disagree 11 2.68 2.68%
## 2 PSQu2 Quite Disagree 7 1.71 1.71%
## 3 PSQu3 Quite Disagree 4 0.98 0.98%
## 4 PSQu4 Quite Disagree 8 1.95 1.95%
## 5 PSQu5 Quite Disagree 6 1.46 1.46%
## 6 PSQu6 Quite Disagree 6 1.46 1.46%
## 7 PSQu7 Quite Disagree 6 1.46 1.46%
## 8 PSQu8 Quite Disagree 4 0.98 0.98%
## 9 SAT1 Quite Disagree 17 4.15 4.15%
## 10 SAT2 Quite Disagree 12 2.93 2.93%
## # ... with 22 more rows
# For displaying percent of "Normal":
df_odered %>%
filter(Res == "Normal") %>%
filter(percent >= 0) -> df_for_text4
df_for_text4
## # A tibble: 32 x 5
## BPE Res n percent bar_text
## <fct> <fct> <int> <dbl> <chr>
## 1 PSQu1 Normal 55 13.4 13.41%
## 2 PSQu2 Normal 47 11.5 11.46%
## 3 PSQu3 Normal 40 9.76 9.76%
## 4 PSQu4 Normal 25 6.1 6.1%
## 5 PSQu5 Normal 24 5.85 5.85%
## 6 PSQu6 Normal 27 6.59 6.59%
## 7 PSQu7 Normal 24 5.85 5.85%
## 8 PSQu8 Normal 31 7.56 7.56%
## 9 SAT1 Normal 40 9.76 9.76%
## 10 SAT2 Normal 33 8.05 8.05%
## # ... with 22 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: 32 x 5
## BPE Res n percent bar_text
## <fct> <fct> <int> <dbl> <chr>
## 1 PSQu1 Quite Agree 137 33.4 33.41%
## 2 PSQu2 Quite Agree 113 27.6 27.56%
## 3 PSQu3 Quite Agree 107 26.1 26.1%
## 4 PSQu4 Quite Agree 102 24.9 24.88%
## 5 PSQu5 Quite Agree 96 23.4 23.41%
## 6 PSQu6 Quite Agree 91 22.2 22.2%
## 7 PSQu7 Quite Agree 86 21.0 20.98%
## 8 PSQu8 Quite Agree 74 18.0 18.05%
## 9 SAT1 Quite Agree 122 29.8 29.76%
## 10 SAT2 Quite Agree 115 28.0 28.05%
## # ... with 22 more rows
# For displaying percent of "Agree":
df_odered %>%
filter(Res == "Agree") %>%
filter(percent >= 0) -> df_for_text6
df_for_text6
## # A tibble: 32 x 5
## BPE Res n percent bar_text
## <fct> <fct> <int> <dbl> <chr>
## 1 PSQu1 Agree 170 41.5 41.46%
## 2 PSQu2 Agree 208 50.7 50.73%
## 3 PSQu3 Agree 214 52.2 52.2%
## 4 PSQu4 Agree 221 53.9 53.9%
## 5 PSQu5 Agree 231 56.3 56.34%
## 6 PSQu6 Agree 218 53.2 53.17%
## 7 PSQu7 Agree 222 54.2 54.15%
## 8 PSQu8 Agree 220 53.7 53.66%
## 9 SAT1 Agree 160 39.0 39.02%
## 10 SAT2 Agree 167 40.7 40.73%
## # ... with 22 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: 32 x 5
## BPE Res n percent bar_text
## <fct> <fct> <int> <dbl> <chr>
## 1 PSQu1 Very Agree 33 8.05 8.05%
## 2 PSQu2 Very Agree 34 8.29 8.29%
## 3 PSQu3 Very Agree 44 10.7 10.73%
## 4 PSQu4 Very Agree 53 12.9 12.93%
## 5 PSQu5 Very Agree 52 12.7 12.68%
## 6 PSQu6 Very Agree 66 16.1 16.1%
## 7 PSQu7 Very Agree 71 17.3 17.32%
## 8 PSQu8 Very Agree 80 19.5 19.51%
## 9 SAT1 Very Agree 70 17.1 17.07%
## 10 SAT2 Very Agree 80 19.5 19.51%
## # ... with 22 more rows
# For displaying percent of "Very Agree":
df_odered %>%
filter(Res == "Very Agree") -> df_for_text
df_for_text
## # A tibble: 32 x 5
## BPE Res n percent bar_text
## <fct> <fct> <int> <dbl> <chr>
## 1 PSQu1 Very Agree 33 8.05 8.05%
## 2 PSQu2 Very Agree 34 8.29 8.29%
## 3 PSQu3 Very Agree 44 10.7 10.73%
## 4 PSQu4 Very Agree 53 12.9 12.93%
## 5 PSQu5 Very Agree 52 12.7 12.68%
## 6 PSQu6 Very Agree 66 16.1 16.1%
## 7 PSQu7 Very Agree 71 17.3 17.32%
## 8 PSQu8 Very Agree 80 19.5 19.51%
## 9 SAT1 Very Agree 70 17.1 17.07%
## 10 SAT2 Very Agree 80 19.5 19.51%
## # ... with 22 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_SEM4_viet = within(DN_SEM4, {
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("PSQu1", "PSQu2", "PSQu3", "PSQu4", "PSQu5", "PSQu6", "PSQu7", "PSQu8", "SAT1", "SAT2", "SAT3", "LOY1", "LOY2", "LOY3", "LOY4", "LOy5", "LOY6", "LOY7", "IMA1", "IMA2", "IMA3", "IMA4", "IMA5", "PHB1", "PHB2", "PHB3", "PHB4", "PHB5", "PEB1", "PEB2", "PEB3", "PEB4"))
})
str(DN_SEM4_viet)
## 'data.frame': 13120 obs. of 2 variables:
## $ Res: Factor w/ 7 levels "R<U+1EA5>t không d<U+1ED3>ng ý",..: 6 6 6 5 6 5 1 7 3 6 ...
## $ BPE: Factor w/ 32 levels "PSQu1","PSQu2",..: 22 22 22 22 22 22 22 22 22 22 ...
summary(DN_SEM4_viet)
## Res BPE
## R<U+1EA5>t không d<U+1ED3>ng ý: 67 PSQu1 : 410
## Không d<U+1ED3>ng ý : 181 PSQu2 : 410
## Khá không d<U+1ED3>ng ý : 457 PSQu3 : 410
## Bình thu<U+1EDD>ng :1091 PSQu4 : 410
## Khá d<U+1ED3>ng ý :3174 PSQu5 : 410
## Ð<U+1ED3>ng ý :5931 PSQu6 : 410
## R<U+1EA5>t d<U+1ED3>ng ý :2219 (Other):10660
## t <- compareGroups(Res ~ BPE, data = DN_SEM1)
## createTable(t)
DN_SEM4_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] PSQu1 PSQu2 PSQu3 PSQu4 PSQu5 PSQu6 PSQu7 PSQu8 SAT1 SAT2 SAT3 LOY1
## [13] LOY2 LOY3 LOY4 LOy5 LOY6 LOY7 IMA1 IMA2 IMA3 IMA4 IMA5 PHB1
## [25] PHB2 PHB3 PHB4 PHB5 PEB1 PEB2 PEB3 PEB4
## 32 Levels: PSQu1 PSQu2 PSQu3 PSQu4 PSQu5 PSQu6 PSQu7 PSQu8 SAT1 SAT2 ... 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: 208 x 5
## BPE Res n percent bar_text
## <fct> <fct> <int> <dbl> <chr>
## 1 PSQu1 R<U+1EA5>t không d<U+1ED3>ng ý 1 0.24 0.24%
## 2 PSQu1 Không d<U+1ED3>ng ý 3 0.73 0.73%
## 3 PSQu1 Khá không d<U+1ED3>ng ý 11 2.68 2.68%
## 4 PSQu1 Bình thu<U+1EDD>ng 55 13.4 13.41%
## 5 PSQu1 Khá d<U+1ED3>ng ý 137 33.4 33.41%
## 6 PSQu1 Ð<U+1ED3>ng ý 170 41.5 41.46%
## 7 PSQu1 R<U+1EA5>t d<U+1ED3>ng ý 33 8.05 8.05%
## 8 PSQu2 Không d<U+1ED3>ng ý 1 0.24 0.24%
## 9 PSQu2 Khá không d<U+1ED3>ng ý 7 1.71 1.71%
## 10 PSQu2 Bình thu<U+1EDD>ng 47 11.5 11.46%
## # ... with 198 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: 21 x 5
## BPE Res n percent bar_text
## <fct> <fct> <int> <dbl> <chr>
## 1 PSQu1 R<U+1EA5>t không d<U+1ED3>ng ý 1 0.24 0.24%
## 2 PSQu4 R<U+1EA5>t không d<U+1ED3>ng ý 1 0.24 0.24%
## 3 SAT1 R<U+1EA5>t không d<U+1ED3>ng ý 1 0.24 0.24%
## 4 SAT2 R<U+1EA5>t không d<U+1ED3>ng ý 1 0.24 0.24%
## 5 SAT3 R<U+1EA5>t không d<U+1ED3>ng ý 1 0.24 0.24%
## 6 LOY1 R<U+1EA5>t không d<U+1ED3>ng ý 1 0.24 0.24%
## 7 LOY2 R<U+1EA5>t không d<U+1ED3>ng ý 1 0.24 0.24%
## 8 LOY3 R<U+1EA5>t không d<U+1ED3>ng ý 1 0.24 0.24%
## 9 LOY4 R<U+1EA5>t không d<U+1ED3>ng ý 1 0.24 0.24%
## 10 LOY6 R<U+1EA5>t không d<U+1ED3>ng ý 1 0.24 0.24%
## # ... with 11 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: 27 x 5
## BPE Res n percent bar_text
## <fct> <fct> <int> <dbl> <chr>
## 1 PSQu1 Không d<U+1ED3>ng ý 3 0.73 0.73%
## 2 PSQu2 Không d<U+1ED3>ng ý 1 0.24 0.24%
## 3 PSQu3 Không d<U+1ED3>ng ý 1 0.24 0.24%
## 4 PSQu5 Không d<U+1ED3>ng ý 1 0.24 0.24%
## 5 PSQu6 Không d<U+1ED3>ng ý 2 0.49 0.49%
## 6 PSQu7 Không d<U+1ED3>ng ý 1 0.24 0.24%
## 7 PSQu8 Không d<U+1ED3>ng ý 1 0.24 0.24%
## 8 SAT2 Không d<U+1ED3>ng ý 2 0.49 0.49%
## 9 SAT3 Không d<U+1ED3>ng ý 14 3.41 3.41%
## 10 LOY2 Không d<U+1ED3>ng ý 1 0.24 0.24%
## # ... with 17 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: 32 x 5
## BPE Res n percent bar_text
## <fct> <fct> <int> <dbl> <chr>
## 1 PSQu1 Khá không d<U+1ED3>ng ý 11 2.68 2.68%
## 2 PSQu2 Khá không d<U+1ED3>ng ý 7 1.71 1.71%
## 3 PSQu3 Khá không d<U+1ED3>ng ý 4 0.98 0.98%
## 4 PSQu4 Khá không d<U+1ED3>ng ý 8 1.95 1.95%
## 5 PSQu5 Khá không d<U+1ED3>ng ý 6 1.46 1.46%
## 6 PSQu6 Khá không d<U+1ED3>ng ý 6 1.46 1.46%
## 7 PSQu7 Khá không d<U+1ED3>ng ý 6 1.46 1.46%
## 8 PSQu8 Khá không d<U+1ED3>ng ý 4 0.98 0.98%
## 9 SAT1 Khá không d<U+1ED3>ng ý 17 4.15 4.15%
## 10 SAT2 Khá không d<U+1ED3>ng ý 12 2.93 2.93%
## # ... with 22 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: 32 x 5
## BPE Res n percent bar_text
## <fct> <fct> <int> <dbl> <chr>
## 1 PSQu1 Bình thu<U+1EDD>ng 55 13.4 13.41%
## 2 PSQu2 Bình thu<U+1EDD>ng 47 11.5 11.46%
## 3 PSQu3 Bình thu<U+1EDD>ng 40 9.76 9.76%
## 4 PSQu4 Bình thu<U+1EDD>ng 25 6.1 6.1%
## 5 PSQu5 Bình thu<U+1EDD>ng 24 5.85 5.85%
## 6 PSQu6 Bình thu<U+1EDD>ng 27 6.59 6.59%
## 7 PSQu7 Bình thu<U+1EDD>ng 24 5.85 5.85%
## 8 PSQu8 Bình thu<U+1EDD>ng 31 7.56 7.56%
## 9 SAT1 Bình thu<U+1EDD>ng 40 9.76 9.76%
## 10 SAT2 Bình thu<U+1EDD>ng 33 8.05 8.05%
## # ... with 22 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: 32 x 5
## BPE Res n percent bar_text
## <fct> <fct> <int> <dbl> <chr>
## 1 PSQu1 Khá d<U+1ED3>ng ý 137 33.4 33.41%
## 2 PSQu2 Khá d<U+1ED3>ng ý 113 27.6 27.56%
## 3 PSQu3 Khá d<U+1ED3>ng ý 107 26.1 26.1%
## 4 PSQu4 Khá d<U+1ED3>ng ý 102 24.9 24.88%
## 5 PSQu5 Khá d<U+1ED3>ng ý 96 23.4 23.41%
## 6 PSQu6 Khá d<U+1ED3>ng ý 91 22.2 22.2%
## 7 PSQu7 Khá d<U+1ED3>ng ý 86 21.0 20.98%
## 8 PSQu8 Khá d<U+1ED3>ng ý 74 18.0 18.05%
## 9 SAT1 Khá d<U+1ED3>ng ý 122 29.8 29.76%
## 10 SAT2 Khá d<U+1ED3>ng ý 115 28.0 28.05%
## # ... with 22 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: 32 x 5
## BPE Res n percent bar_text
## <fct> <fct> <int> <dbl> <chr>
## 1 PSQu1 Ð<U+1ED3>ng ý 170 41.5 41.46%
## 2 PSQu2 Ð<U+1ED3>ng ý 208 50.7 50.73%
## 3 PSQu3 Ð<U+1ED3>ng ý 214 52.2 52.2%
## 4 PSQu4 Ð<U+1ED3>ng ý 221 53.9 53.9%
## 5 PSQu5 Ð<U+1ED3>ng ý 231 56.3 56.34%
## 6 PSQu6 Ð<U+1ED3>ng ý 218 53.2 53.17%
## 7 PSQu7 Ð<U+1ED3>ng ý 222 54.2 54.15%
## 8 PSQu8 Ð<U+1ED3>ng ý 220 53.7 53.66%
## 9 SAT1 Ð<U+1ED3>ng ý 160 39.0 39.02%
## 10 SAT2 Ð<U+1ED3>ng ý 167 40.7 40.73%
## # ... with 22 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: 32 x 5
## BPE Res n percent bar_text
## <fct> <fct> <int> <dbl> <chr>
## 1 PSQu1 R<U+1EA5>t d<U+1ED3>ng ý 33 8.05 8.05%
## 2 PSQu2 R<U+1EA5>t d<U+1ED3>ng ý 34 8.29 8.29%
## 3 PSQu3 R<U+1EA5>t d<U+1ED3>ng ý 44 10.7 10.73%
## 4 PSQu4 R<U+1EA5>t d<U+1ED3>ng ý 53 12.9 12.93%
## 5 PSQu5 R<U+1EA5>t d<U+1ED3>ng ý 52 12.7 12.68%
## 6 PSQu6 R<U+1EA5>t d<U+1ED3>ng ý 66 16.1 16.1%
## 7 PSQu7 R<U+1EA5>t d<U+1ED3>ng ý 71 17.3 17.32%
## 8 PSQu8 R<U+1EA5>t d<U+1ED3>ng ý 80 19.5 19.51%
## 9 SAT1 R<U+1EA5>t d<U+1ED3>ng ý 70 17.1 17.07%
## 10 SAT2 R<U+1EA5>t d<U+1ED3>ng ý 80 19.5 19.51%
## # ... with 22 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: 32 x 5
## BPE Res n percent bar_text
## <fct> <fct> <int> <dbl> <chr>
## 1 PSQu1 R<U+1EA5>t d<U+1ED3>ng ý 33 8.05 8.05%
## 2 PSQu2 R<U+1EA5>t d<U+1ED3>ng ý 34 8.29 8.29%
## 3 PSQu3 R<U+1EA5>t d<U+1ED3>ng ý 44 10.7 10.73%
## 4 PSQu4 R<U+1EA5>t d<U+1ED3>ng ý 53 12.9 12.93%
## 5 PSQu5 R<U+1EA5>t d<U+1ED3>ng ý 52 12.7 12.68%
## 6 PSQu6 R<U+1EA5>t d<U+1ED3>ng ý 66 16.1 16.1%
## 7 PSQu7 R<U+1EA5>t d<U+1ED3>ng ý 71 17.3 17.32%
## 8 PSQu8 R<U+1EA5>t d<U+1ED3>ng ý 80 19.5 19.51%
## 9 SAT1 R<U+1EA5>t d<U+1ED3>ng ý 70 17.1 17.07%
## 10 SAT2 R<U+1EA5>t d<U+1ED3>ng ý 80 19.5 19.51%
## # ... with 22 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_SEM4)
## Res BPE
## 1 6 PSQu1
## 2 4 PSQu1
## 3 2 PSQu1
## 4 5 PSQu1
## 5 6 PSQu1
## 6 5 PSQu1
dim(HCM_SEM4)
## [1] 14336 2
attach(HCM_SEM4)
## The following objects are masked from DN_SEM4:
##
## BPE, Res
## The following objects are masked from DN_HCM_SEM4:
##
## BPE, Res
HCM_SEM4 = within(HCM_SEM4, {
Res = factor(Res, labels = c("Very Disagree", "Disagree", "Quite Disagree", "Normal", "Quite Agree", "Agree", "Very Agree"))
BPE = factor(BPE, labels = c("PSQu1", "PSQu2", "PSQu3", "PSQu4", "PSQu5", "PSQu6", "PSQu7", "PSQu8", "SAT1", "SAT2", "SAT3", "LOY1", "LOY2", "LOY3", "LOY4", "LOY5", "LOY6", "LOY7", "IMA1", "IMA2", "IMA3", "IMA4", "IMA5", "PHB1", "PHB2", "PHB3", "PHB4", "PHB5", "PEB1", "PEB2", "PEB3", "PEB4"))
})
str(HCM_SEM4)
## 'data.frame': 14336 obs. of 2 variables:
## $ Res: Factor w/ 7 levels "Very Disagree",..: 6 4 2 5 6 5 2 6 3 7 ...
## $ BPE: Factor w/ 32 levels "PSQu1","PSQu2",..: 22 22 22 22 22 22 22 22 22 22 ...
summary(HCM_SEM4)
## Res BPE
## Very Disagree : 389 PSQu1 : 448
## Disagree : 596 PSQu2 : 448
## Quite Disagree: 517 PSQu3 : 448
## Normal :2295 PSQu4 : 448
## Quite Agree :2673 PSQu5 : 448
## Agree :5974 PSQu6 : 448
## Very Agree :1892 (Other):11648
## t <- compareGroups(Res ~ BPE, data = DN_SEM1)
## createTable(t)
HCM_SEM4 %>%
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] PSQu1 PSQu2 PSQu3 PSQu4 PSQu5 PSQu6 PSQu7 PSQu8 SAT1 SAT2 SAT3 LOY1
## [13] LOY2 LOY3 LOY4 LOY5 LOY6 LOY7 IMA1 IMA2 IMA3 IMA4 IMA5 PHB1
## [25] PHB2 PHB3 PHB4 PHB5 PEB1 PEB2 PEB3 PEB4
## 32 Levels: PSQu1 PSQu2 PSQu3 PSQu4 PSQu5 PSQu6 PSQu7 PSQu8 SAT1 SAT2 ... 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: 224 x 5
## BPE Res n percent bar_text
## <fct> <fct> <int> <dbl> <chr>
## 1 PSQu1 Very Disagree 5 1.12 1.12%
## 2 PSQu1 Disagree 17 3.79 3.79%
## 3 PSQu1 Quite Disagree 21 4.69 4.69%
## 4 PSQu1 Normal 100 22.3 22.32%
## 5 PSQu1 Quite Agree 93 20.8 20.76%
## 6 PSQu1 Agree 180 40.2 40.18%
## 7 PSQu1 Very Agree 32 7.14 7.14%
## 8 PSQu2 Very Disagree 11 2.46 2.46%
## 9 PSQu2 Disagree 18 4.02 4.02%
## 10 PSQu2 Quite Disagree 18 4.02 4.02%
## # ... with 214 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: 32 x 5
## BPE Res n percent bar_text
## <fct> <fct> <int> <dbl> <chr>
## 1 PSQu1 Very Disagree 5 1.12 1.12%
## 2 PSQu2 Very Disagree 11 2.46 2.46%
## 3 PSQu3 Very Disagree 11 2.46 2.46%
## 4 PSQu4 Very Disagree 13 2.9 2.9%
## 5 PSQu5 Very Disagree 6 1.34 1.34%
## 6 PSQu6 Very Disagree 4 0.89 0.89%
## 7 PSQu7 Very Disagree 6 1.34 1.34%
## 8 PSQu8 Very Disagree 3 0.67 0.67%
## 9 SAT1 Very Disagree 12 2.68 2.68%
## 10 SAT2 Very Disagree 11 2.46 2.46%
## # ... with 22 more rows
# For displaying percent of "Disagree":
df_odered %>%
filter(Res == "Disagree") %>%
filter(percent >= 0) -> df_for_text2
df_for_text2
## # A tibble: 32 x 5
## BPE Res n percent bar_text
## <fct> <fct> <int> <dbl> <chr>
## 1 PSQu1 Disagree 17 3.79 3.79%
## 2 PSQu2 Disagree 18 4.02 4.02%
## 3 PSQu3 Disagree 10 2.23 2.23%
## 4 PSQu4 Disagree 14 3.12 3.12%
## 5 PSQu5 Disagree 20 4.46 4.46%
## 6 PSQu6 Disagree 16 3.57 3.57%
## 7 PSQu7 Disagree 21 4.69 4.69%
## 8 PSQu8 Disagree 15 3.35 3.35%
## 9 SAT1 Disagree 17 3.79 3.79%
## 10 SAT2 Disagree 21 4.69 4.69%
## # ... with 22 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: 32 x 5
## BPE Res n percent bar_text
## <fct> <fct> <int> <dbl> <chr>
## 1 PSQu1 Quite Disagree 21 4.69 4.69%
## 2 PSQu2 Quite Disagree 18 4.02 4.02%
## 3 PSQu3 Quite Disagree 16 3.57 3.57%
## 4 PSQu4 Quite Disagree 18 4.02 4.02%
## 5 PSQu5 Quite Disagree 15 3.35 3.35%
## 6 PSQu6 Quite Disagree 13 2.9 2.9%
## 7 PSQu7 Quite Disagree 10 2.23 2.23%
## 8 PSQu8 Quite Disagree 14 3.12 3.12%
## 9 SAT1 Quite Disagree 14 3.12 3.12%
## 10 SAT2 Quite Disagree 13 2.9 2.9%
## # ... with 22 more rows
# For displaying percent of "Normal":
df_odered %>%
filter(Res == "Normal") %>%
filter(percent >= 0) -> df_for_text4
df_for_text4
## # A tibble: 32 x 5
## BPE Res n percent bar_text
## <fct> <fct> <int> <dbl> <chr>
## 1 PSQu1 Normal 100 22.3 22.32%
## 2 PSQu2 Normal 111 24.8 24.78%
## 3 PSQu3 Normal 89 19.9 19.87%
## 4 PSQu4 Normal 88 19.6 19.64%
## 5 PSQu5 Normal 81 18.1 18.08%
## 6 PSQu6 Normal 87 19.4 19.42%
## 7 PSQu7 Normal 75 16.7 16.74%
## 8 PSQu8 Normal 61 13.6 13.62%
## 9 SAT1 Normal 90 20.1 20.09%
## 10 SAT2 Normal 78 17.4 17.41%
## # ... with 22 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: 32 x 5
## BPE Res n percent bar_text
## <fct> <fct> <int> <dbl> <chr>
## 1 PSQu1 Quite Agree 93 20.8 20.76%
## 2 PSQu2 Quite Agree 100 22.3 22.32%
## 3 PSQu3 Quite Agree 100 22.3 22.32%
## 4 PSQu4 Quite Agree 97 21.6 21.65%
## 5 PSQu5 Quite Agree 107 23.9 23.88%
## 6 PSQu6 Quite Agree 76 17.0 16.96%
## 7 PSQu7 Quite Agree 83 18.5 18.53%
## 8 PSQu8 Quite Agree 86 19.2 19.2%
## 9 SAT1 Quite Agree 90 20.1 20.09%
## 10 SAT2 Quite Agree 99 22.1 22.1%
## # ... with 22 more rows
# For displaying percent of "Agree":
df_odered %>%
filter(Res == "Agree") %>%
filter(percent >= 0) -> df_for_text6
df_for_text6
## # A tibble: 32 x 5
## BPE Res n percent bar_text
## <fct> <fct> <int> <dbl> <chr>
## 1 PSQu1 Agree 180 40.2 40.18%
## 2 PSQu2 Agree 158 35.3 35.27%
## 3 PSQu3 Agree 187 41.7 41.74%
## 4 PSQu4 Agree 185 41.3 41.29%
## 5 PSQu5 Agree 187 41.7 41.74%
## 6 PSQu6 Agree 212 47.3 47.32%
## 7 PSQu7 Agree 206 46.0 45.98%
## 8 PSQu8 Agree 217 48.4 48.44%
## 9 SAT1 Agree 177 39.5 39.51%
## 10 SAT2 Agree 177 39.5 39.51%
## # ... with 22 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: 32 x 5
## BPE Res n percent bar_text
## <fct> <fct> <int> <dbl> <chr>
## 1 PSQu1 Very Agree 32 7.14 7.14%
## 2 PSQu2 Very Agree 32 7.14 7.14%
## 3 PSQu3 Very Agree 35 7.81 7.81%
## 4 PSQu4 Very Agree 33 7.37 7.37%
## 5 PSQu5 Very Agree 32 7.14 7.14%
## 6 PSQu6 Very Agree 40 8.93 8.93%
## 7 PSQu7 Very Agree 47 10.5 10.49%
## 8 PSQu8 Very Agree 52 11.6 11.61%
## 9 SAT1 Very Agree 48 10.7 10.71%
## 10 SAT2 Very Agree 49 10.9 10.94%
## # ... with 22 more rows
# For displaying percent of "Very Agree":
df_odered %>%
filter(Res == "Very Agree") -> df_for_text
df_for_text
## # A tibble: 32 x 5
## BPE Res n percent bar_text
## <fct> <fct> <int> <dbl> <chr>
## 1 PSQu1 Very Agree 32 7.14 7.14%
## 2 PSQu2 Very Agree 32 7.14 7.14%
## 3 PSQu3 Very Agree 35 7.81 7.81%
## 4 PSQu4 Very Agree 33 7.37 7.37%
## 5 PSQu5 Very Agree 32 7.14 7.14%
## 6 PSQu6 Very Agree 40 8.93 8.93%
## 7 PSQu7 Very Agree 47 10.5 10.49%
## 8 PSQu8 Very Agree 52 11.6 11.61%
## 9 SAT1 Very Agree 48 10.7 10.71%
## 10 SAT2 Very Agree 49 10.9 10.94%
## # ... with 22 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_SEM4_viet = within(HCM_SEM4, {
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("PSQu1", "PSQu2", "PSQu3", "PSQu4", "PSQu5", "PSQu6", "PSQu7", "PSQu8", "SAT1", "SAT2", "SAT3", "LOY1", "LOY2", "LOY3", "LOY4", "LOY5", "LOY6", "LOY7", "IMA1", "IMA2", "IMA3", "IMA4", "IMA5", "PHB1", "PHB2", "PHB3", "PHB4", "PHB5", "PEB1", "PEB2", "PEB3", "PEB4"))
})
str(HCM_SEM4_viet)
## 'data.frame': 14336 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/ 32 levels "PSQu1","PSQu2",..: 22 22 22 22 22 22 22 22 22 22 ...
summary(HCM_SEM4_viet)
## Res BPE
## R<U+1EA5>t không d<U+1ED3>ng ý: 389 PSQu1 : 448
## Không d<U+1ED3>ng ý : 596 PSQu2 : 448
## Khá không d<U+1ED3>ng ý : 517 PSQu3 : 448
## Bình thu<U+1EDD>ng :2295 PSQu4 : 448
## Khá d<U+1ED3>ng ý :2673 PSQu5 : 448
## Ð<U+1ED3>ng ý :5974 PSQu6 : 448
## R<U+1EA5>t d<U+1ED3>ng ý :1892 (Other):11648
## t <- compareGroups(Res ~ BPE, data = DN_SEM1)
## createTable(t)
HCM_SEM4_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] PSQu1 PSQu2 PSQu3 PSQu4 PSQu5 PSQu6 PSQu7 PSQu8 SAT1 SAT2 SAT3 LOY1
## [13] LOY2 LOY3 LOY4 LOY5 LOY6 LOY7 IMA1 IMA2 IMA3 IMA4 IMA5 PHB1
## [25] PHB2 PHB3 PHB4 PHB5 PEB1 PEB2 PEB3 PEB4
## 32 Levels: PSQu1 PSQu2 PSQu3 PSQu4 PSQu5 PSQu6 PSQu7 PSQu8 SAT1 SAT2 ... 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: 224 x 5
## BPE Res n percent bar_text
## <fct> <fct> <int> <dbl> <chr>
## 1 PSQu1 R<U+1EA5>t không d<U+1ED3>ng ý 5 1.12 1.12%
## 2 PSQu1 Không d<U+1ED3>ng ý 17 3.79 3.79%
## 3 PSQu1 Khá không d<U+1ED3>ng ý 21 4.69 4.69%
## 4 PSQu1 Bình thu<U+1EDD>ng 100 22.3 22.32%
## 5 PSQu1 Khá d<U+1ED3>ng ý 93 20.8 20.76%
## 6 PSQu1 Ð<U+1ED3>ng ý 180 40.2 40.18%
## 7 PSQu1 R<U+1EA5>t d<U+1ED3>ng ý 32 7.14 7.14%
## 8 PSQu2 R<U+1EA5>t không d<U+1ED3>ng ý 11 2.46 2.46%
## 9 PSQu2 Không d<U+1ED3>ng ý 18 4.02 4.02%
## 10 PSQu2 Khá không d<U+1ED3>ng ý 18 4.02 4.02%
## # ... with 214 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: 32 x 5
## BPE Res n percent bar_text
## <fct> <fct> <int> <dbl> <chr>
## 1 PSQu1 R<U+1EA5>t không d<U+1ED3>ng ý 5 1.12 1.12%
## 2 PSQu2 R<U+1EA5>t không d<U+1ED3>ng ý 11 2.46 2.46%
## 3 PSQu3 R<U+1EA5>t không d<U+1ED3>ng ý 11 2.46 2.46%
## 4 PSQu4 R<U+1EA5>t không d<U+1ED3>ng ý 13 2.9 2.9%
## 5 PSQu5 R<U+1EA5>t không d<U+1ED3>ng ý 6 1.34 1.34%
## 6 PSQu6 R<U+1EA5>t không d<U+1ED3>ng ý 4 0.89 0.89%
## 7 PSQu7 R<U+1EA5>t không d<U+1ED3>ng ý 6 1.34 1.34%
## 8 PSQu8 R<U+1EA5>t không d<U+1ED3>ng ý 3 0.67 0.67%
## 9 SAT1 R<U+1EA5>t không d<U+1ED3>ng ý 12 2.68 2.68%
## 10 SAT2 R<U+1EA5>t không d<U+1ED3>ng ý 11 2.46 2.46%
## # ... with 22 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: 32 x 5
## BPE Res n percent bar_text
## <fct> <fct> <int> <dbl> <chr>
## 1 PSQu1 Không d<U+1ED3>ng ý 17 3.79 3.79%
## 2 PSQu2 Không d<U+1ED3>ng ý 18 4.02 4.02%
## 3 PSQu3 Không d<U+1ED3>ng ý 10 2.23 2.23%
## 4 PSQu4 Không d<U+1ED3>ng ý 14 3.12 3.12%
## 5 PSQu5 Không d<U+1ED3>ng ý 20 4.46 4.46%
## 6 PSQu6 Không d<U+1ED3>ng ý 16 3.57 3.57%
## 7 PSQu7 Không d<U+1ED3>ng ý 21 4.69 4.69%
## 8 PSQu8 Không d<U+1ED3>ng ý 15 3.35 3.35%
## 9 SAT1 Không d<U+1ED3>ng ý 17 3.79 3.79%
## 10 SAT2 Không d<U+1ED3>ng ý 21 4.69 4.69%
## # ... with 22 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: 32 x 5
## BPE Res n percent bar_text
## <fct> <fct> <int> <dbl> <chr>
## 1 PSQu1 Khá không d<U+1ED3>ng ý 21 4.69 4.69%
## 2 PSQu2 Khá không d<U+1ED3>ng ý 18 4.02 4.02%
## 3 PSQu3 Khá không d<U+1ED3>ng ý 16 3.57 3.57%
## 4 PSQu4 Khá không d<U+1ED3>ng ý 18 4.02 4.02%
## 5 PSQu5 Khá không d<U+1ED3>ng ý 15 3.35 3.35%
## 6 PSQu6 Khá không d<U+1ED3>ng ý 13 2.9 2.9%
## 7 PSQu7 Khá không d<U+1ED3>ng ý 10 2.23 2.23%
## 8 PSQu8 Khá không d<U+1ED3>ng ý 14 3.12 3.12%
## 9 SAT1 Khá không d<U+1ED3>ng ý 14 3.12 3.12%
## 10 SAT2 Khá không d<U+1ED3>ng ý 13 2.9 2.9%
## # ... with 22 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: 32 x 5
## BPE Res n percent bar_text
## <fct> <fct> <int> <dbl> <chr>
## 1 PSQu1 Bình thu<U+1EDD>ng 100 22.3 22.32%
## 2 PSQu2 Bình thu<U+1EDD>ng 111 24.8 24.78%
## 3 PSQu3 Bình thu<U+1EDD>ng 89 19.9 19.87%
## 4 PSQu4 Bình thu<U+1EDD>ng 88 19.6 19.64%
## 5 PSQu5 Bình thu<U+1EDD>ng 81 18.1 18.08%
## 6 PSQu6 Bình thu<U+1EDD>ng 87 19.4 19.42%
## 7 PSQu7 Bình thu<U+1EDD>ng 75 16.7 16.74%
## 8 PSQu8 Bình thu<U+1EDD>ng 61 13.6 13.62%
## 9 SAT1 Bình thu<U+1EDD>ng 90 20.1 20.09%
## 10 SAT2 Bình thu<U+1EDD>ng 78 17.4 17.41%
## # ... with 22 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: 32 x 5
## BPE Res n percent bar_text
## <fct> <fct> <int> <dbl> <chr>
## 1 PSQu1 Khá d<U+1ED3>ng ý 93 20.8 20.76%
## 2 PSQu2 Khá d<U+1ED3>ng ý 100 22.3 22.32%
## 3 PSQu3 Khá d<U+1ED3>ng ý 100 22.3 22.32%
## 4 PSQu4 Khá d<U+1ED3>ng ý 97 21.6 21.65%
## 5 PSQu5 Khá d<U+1ED3>ng ý 107 23.9 23.88%
## 6 PSQu6 Khá d<U+1ED3>ng ý 76 17.0 16.96%
## 7 PSQu7 Khá d<U+1ED3>ng ý 83 18.5 18.53%
## 8 PSQu8 Khá d<U+1ED3>ng ý 86 19.2 19.2%
## 9 SAT1 Khá d<U+1ED3>ng ý 90 20.1 20.09%
## 10 SAT2 Khá d<U+1ED3>ng ý 99 22.1 22.1%
## # ... with 22 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: 32 x 5
## BPE Res n percent bar_text
## <fct> <fct> <int> <dbl> <chr>
## 1 PSQu1 Ð<U+1ED3>ng ý 180 40.2 40.18%
## 2 PSQu2 Ð<U+1ED3>ng ý 158 35.3 35.27%
## 3 PSQu3 Ð<U+1ED3>ng ý 187 41.7 41.74%
## 4 PSQu4 Ð<U+1ED3>ng ý 185 41.3 41.29%
## 5 PSQu5 Ð<U+1ED3>ng ý 187 41.7 41.74%
## 6 PSQu6 Ð<U+1ED3>ng ý 212 47.3 47.32%
## 7 PSQu7 Ð<U+1ED3>ng ý 206 46.0 45.98%
## 8 PSQu8 Ð<U+1ED3>ng ý 217 48.4 48.44%
## 9 SAT1 Ð<U+1ED3>ng ý 177 39.5 39.51%
## 10 SAT2 Ð<U+1ED3>ng ý 177 39.5 39.51%
## # ... with 22 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: 32 x 5
## BPE Res n percent bar_text
## <fct> <fct> <int> <dbl> <chr>
## 1 PSQu1 R<U+1EA5>t d<U+1ED3>ng ý 32 7.14 7.14%
## 2 PSQu2 R<U+1EA5>t d<U+1ED3>ng ý 32 7.14 7.14%
## 3 PSQu3 R<U+1EA5>t d<U+1ED3>ng ý 35 7.81 7.81%
## 4 PSQu4 R<U+1EA5>t d<U+1ED3>ng ý 33 7.37 7.37%
## 5 PSQu5 R<U+1EA5>t d<U+1ED3>ng ý 32 7.14 7.14%
## 6 PSQu6 R<U+1EA5>t d<U+1ED3>ng ý 40 8.93 8.93%
## 7 PSQu7 R<U+1EA5>t d<U+1ED3>ng ý 47 10.5 10.49%
## 8 PSQu8 R<U+1EA5>t d<U+1ED3>ng ý 52 11.6 11.61%
## 9 SAT1 R<U+1EA5>t d<U+1ED3>ng ý 48 10.7 10.71%
## 10 SAT2 R<U+1EA5>t d<U+1ED3>ng ý 49 10.9 10.94%
## # ... with 22 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: 32 x 5
## BPE Res n percent bar_text
## <fct> <fct> <int> <dbl> <chr>
## 1 PSQu1 R<U+1EA5>t d<U+1ED3>ng ý 32 7.14 7.14%
## 2 PSQu2 R<U+1EA5>t d<U+1ED3>ng ý 32 7.14 7.14%
## 3 PSQu3 R<U+1EA5>t d<U+1ED3>ng ý 35 7.81 7.81%
## 4 PSQu4 R<U+1EA5>t d<U+1ED3>ng ý 33 7.37 7.37%
## 5 PSQu5 R<U+1EA5>t d<U+1ED3>ng ý 32 7.14 7.14%
## 6 PSQu6 R<U+1EA5>t d<U+1ED3>ng ý 40 8.93 8.93%
## 7 PSQu7 R<U+1EA5>t d<U+1ED3>ng ý 47 10.5 10.49%
## 8 PSQu8 R<U+1EA5>t d<U+1ED3>ng ý 52 11.6 11.61%
## 9 SAT1 R<U+1EA5>t d<U+1ED3>ng ý 48 10.7 10.71%
## 10 SAT2 R<U+1EA5>t d<U+1ED3>ng ý 49 10.9 10.94%
## # ... with 22 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 PSQ - Nhãn tiếng anh
# Plot Likert graph for people in both cities for construct PSQ
library(tidyverse)
library(compareGroups)
head(DN_HCM_SEM4_PSQ)
## Res BPE
## 1 6 PSQu1
## 2 4 PSQu1
## 3 2 PSQu1
## 4 5 PSQu1
## 5 6 PSQu1
## 6 5 PSQu1
dim(DN_HCM_SEM4_PSQ)
## [1] 6864 2
attach(DN_HCM_SEM4_PSQ)
## The following objects are masked from HCM_SEM4:
##
## BPE, Res
## The following objects are masked from DN_SEM4:
##
## BPE, Res
## The following objects are masked from DN_HCM_SEM4:
##
## BPE, Res
DN_HCM_SEM4_PSQ = within(DN_HCM_SEM4_PSQ, {
Res = factor(Res, labels = c("Very Disagree", "Disagree", "Quite Disagree", "Normal", "Quite Agree", "Agree", "Very Agree"))
BPE = factor(BPE, labels = c("PSQu1", "PSQu2", "PSQu3", "PSQu4", "PSQu5", "PSQu6", "PSQu7", "PSQu8"))
})
str(DN_HCM_SEM4_PSQ)
## 'data.frame': 6864 obs. of 2 variables:
## $ Res: Factor w/ 7 levels "Very Disagree",..: 6 4 2 5 6 5 2 6 3 7 ...
## $ BPE: Factor w/ 8 levels "PSQu1","PSQu2",..: 1 1 1 1 1 1 1 1 1 1 ...
summary(DN_HCM_SEM4_PSQ)
## Res BPE
## Very Disagree : 132 PSQu1 : 858
## Disagree : 328 PSQu2 : 858
## Quite Disagree: 400 PSQu3 : 858
## Normal : 994 PSQu4 : 858
## Quite Agree :1486 PSQu5 : 858
## Agree :2789 PSQu6 : 858
## Very Agree : 735 (Other):1716
## t <- compareGroups(Res ~ BPE, data = DN_SEM1)
## createTable(t)
DN_HCM_SEM4_PSQ %>%
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] PSQu4 PSQu6 PSQu5 PSQu7 PSQu3 PSQu1 PSQu2 PSQu8
## Levels: PSQu1 PSQu2 PSQu3 PSQu4 PSQu5 PSQu6 PSQu7 PSQu8
# 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: 56 x 5
## BPE Res n percent bar_text
## <fct> <fct> <int> <dbl> <chr>
## 1 PSQu1 Very Disagree 18 2.1 2.1%
## 2 PSQu1 Disagree 40 4.66 4.66%
## 3 PSQu1 Quite Disagree 60 6.99 6.99%
## 4 PSQu1 Normal 98 11.4 11.42%
## 5 PSQu1 Quite Agree 205 23.9 23.89%
## 6 PSQu1 Agree 349 40.7 40.68%
## 7 PSQu1 Very Agree 88 10.3 10.26%
## 8 PSQu2 Very Disagree 12 1.4 1.4%
## 9 PSQu2 Disagree 33 3.85 3.85%
## 10 PSQu2 Quite Disagree 15 1.75 1.75%
## # ... with 46 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 (PSQ) 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: 8 x 5
## BPE Res n percent bar_text
## <fct> <fct> <int> <dbl> <chr>
## 1 PSQu1 Very Disagree 18 2.1 2.1%
## 2 PSQu2 Very Disagree 12 1.4 1.4%
## 3 PSQu3 Very Disagree 17 1.98 1.98%
## 4 PSQu4 Very Disagree 17 1.98 1.98%
## 5 PSQu5 Very Disagree 15 1.75 1.75%
## 6 PSQu6 Very Disagree 24 2.8 2.8%
## 7 PSQu7 Very Disagree 19 2.21 2.21%
## 8 PSQu8 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: 7 x 5
## BPE Res n percent bar_text
## <fct> <fct> <int> <dbl> <chr>
## 1 PSQu1 Disagree 40 4.66 4.66%
## 2 PSQu2 Disagree 33 3.85 3.85%
## 3 PSQu3 Disagree 43 5.01 5.01%
## 4 PSQu4 Disagree 50 5.83 5.83%
## 5 PSQu5 Disagree 48 5.59 5.59%
## 6 PSQu6 Disagree 47 5.48 5.48%
## 7 PSQu7 Disagree 42 4.9 4.9%
# For displaying percent of "Quite Disagree":
df_odered %>%
filter(Res == "Quite Disagree") %>%
filter(percent >= 0) -> df_for_text3
df_for_text3
## # A tibble: 8 x 5
## BPE Res n percent bar_text
## <fct> <fct> <int> <dbl> <chr>
## 1 PSQu1 Quite Disagree 60 6.99 6.99%
## 2 PSQu2 Quite Disagree 15 1.75 1.75%
## 3 PSQu3 Quite Disagree 61 7.11 7.11%
## 4 PSQu4 Quite Disagree 53 6.18 6.18%
## 5 PSQu5 Quite Disagree 42 4.9 4.9%
## 6 PSQu6 Quite Disagree 75 8.74 8.74%
## 7 PSQu7 Quite Disagree 62 7.23 7.23%
## 8 PSQu8 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: 8 x 5
## BPE Res n percent bar_text
## <fct> <fct> <int> <dbl> <chr>
## 1 PSQu1 Normal 98 11.4 11.42%
## 2 PSQu2 Normal 69 8.04 8.04%
## 3 PSQu3 Normal 101 11.8 11.77%
## 4 PSQu4 Normal 254 29.6 29.6%
## 5 PSQu5 Normal 183 21.3 21.33%
## 6 PSQu6 Normal 98 11.4 11.42%
## 7 PSQu7 Normal 125 14.6 14.57%
## 8 PSQu8 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: 8 x 5
## BPE Res n percent bar_text
## <fct> <fct> <int> <dbl> <chr>
## 1 PSQu1 Quite Agree 205 23.9 23.89%
## 2 PSQu2 Quite Agree 140 16.3 16.32%
## 3 PSQu3 Quite Agree 203 23.7 23.66%
## 4 PSQu4 Quite Agree 162 18.9 18.88%
## 5 PSQu5 Quite Agree 150 17.5 17.48%
## 6 PSQu6 Quite Agree 241 28.1 28.09%
## 7 PSQu7 Quite Agree 216 25.2 25.17%
## 8 PSQu8 Quite Agree 169 19.7 19.7%
# For displaying percent of "Agree":
df_odered %>%
filter(Res == "Agree") %>%
filter(percent >= 0) -> df_for_text6
df_for_text6
## # A tibble: 8 x 5
## BPE Res n percent bar_text
## <fct> <fct> <int> <dbl> <chr>
## 1 PSQu1 Agree 349 40.7 40.68%
## 2 PSQu2 Agree 445 51.9 51.86%
## 3 PSQu3 Agree 347 40.4 40.44%
## 4 PSQu4 Agree 265 30.9 30.89%
## 5 PSQu5 Agree 347 40.4 40.44%
## 6 PSQu6 Agree 304 35.4 35.43%
## 7 PSQu7 Agree 320 37.3 37.3%
## 8 PSQu8 Agree 412 48.0 48.02%
# 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: 8 x 5
## BPE Res n percent bar_text
## <fct> <fct> <int> <dbl> <chr>
## 1 PSQu1 Very Agree 88 10.3 10.26%
## 2 PSQu2 Very Agree 144 16.8 16.78%
## 3 PSQu3 Very Agree 86 10.0 10.02%
## 4 PSQu4 Very Agree 57 6.64 6.64%
## 5 PSQu5 Very Agree 73 8.51 8.51%
## 6 PSQu6 Very Agree 69 8.04 8.04%
## 7 PSQu7 Very Agree 74 8.62 8.62%
## 8 PSQu8 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: 8 x 5
## BPE Res n percent bar_text
## <fct> <fct> <int> <dbl> <chr>
## 1 PSQu1 Very Agree 88 10.3 10.26%
## 2 PSQu2 Very Agree 144 16.8 16.78%
## 3 PSQu3 Very Agree 86 10.0 10.02%
## 4 PSQu4 Very Agree 57 6.64 6.64%
## 5 PSQu5 Very Agree 73 8.51 8.51%
## 6 PSQu6 Very Agree 69 8.04 8.04%
## 7 PSQu7 Very Agree 74 8.62 8.62%
## 8 PSQu8 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 = 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 PSQ - Nhãn tiếng việt
DN_HCM_SEM4_PSQ_v = within(DN_HCM_SEM4_PSQ, {
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("PSQu1", "PSQu2", "PSQu3", "PSQu4", "PSQu5", "PSQu6", "PSQu7", "PSQu8"))
})
str(DN_HCM_SEM4_PSQ_v)
## 'data.frame': 6864 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/ 8 levels "PSQu1","PSQu2",..: 1 1 1 1 1 1 1 1 1 1 ...
summary(DN_HCM_SEM4_PSQ_v)
## Res BPE
## R<U+1EA5>t không d<U+1ED3>ng ý: 132 PSQu1 : 858
## Không d<U+1ED3>ng ý : 328 PSQu2 : 858
## Khá không d<U+1ED3>ng ý : 400 PSQu3 : 858
## Bình thu<U+1EDD>ng : 994 PSQu4 : 858
## Khá d<U+1ED3>ng ý :1486 PSQu5 : 858
## Ð<U+1ED3>ng ý :2789 PSQu6 : 858
## R<U+1EA5>t d<U+1ED3>ng ý : 735 (Other):1716
## t <- compareGroups(Res ~ BPE, data = DN_SEM1)
## createTable(t)
DN_HCM_SEM4_PSQ_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] PSQu4 PSQu6 PSQu5 PSQu7 PSQu3 PSQu1 PSQu2 PSQu8
## Levels: PSQu1 PSQu2 PSQu3 PSQu4 PSQu5 PSQu6 PSQu7 PSQu8
# 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: 56 x 5
## BPE Res n percent bar_text
## <fct> <fct> <int> <dbl> <chr>
## 1 PSQu1 R<U+1EA5>t không d<U+1ED3>ng ý 18 2.1 2.1%
## 2 PSQu1 Không d<U+1ED3>ng ý 40 4.66 4.66%
## 3 PSQu1 Khá không d<U+1ED3>ng ý 60 6.99 6.99%
## 4 PSQu1 Bình thu<U+1EDD>ng 98 11.4 11.42%
## 5 PSQu1 Khá d<U+1ED3>ng ý 205 23.9 23.89%
## 6 PSQu1 Ð<U+1ED3>ng ý 349 40.7 40.68%
## 7 PSQu1 R<U+1EA5>t d<U+1ED3>ng ý 88 10.3 10.26%
## 8 PSQu2 R<U+1EA5>t không d<U+1ED3>ng ý 12 1.4 1.4%
## 9 PSQu2 Không d<U+1ED3>ng ý 33 3.85 3.85%
## 10 PSQu2 Khá không d<U+1ED3>ng ý 15 1.75 1.75%
## # ... with 46 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 (PSQ) \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: 8 x 5
## BPE Res n percent bar_text
## <fct> <fct> <int> <dbl> <chr>
## 1 PSQu1 R<U+1EA5>t không d<U+1ED3>ng ý 18 2.1 2.1%
## 2 PSQu2 R<U+1EA5>t không d<U+1ED3>ng ý 12 1.4 1.4%
## 3 PSQu3 R<U+1EA5>t không d<U+1ED3>ng ý 17 1.98 1.98%
## 4 PSQu4 R<U+1EA5>t không d<U+1ED3>ng ý 17 1.98 1.98%
## 5 PSQu5 R<U+1EA5>t không d<U+1ED3>ng ý 15 1.75 1.75%
## 6 PSQu6 R<U+1EA5>t không d<U+1ED3>ng ý 24 2.8 2.8%
## 7 PSQu7 R<U+1EA5>t không d<U+1ED3>ng ý 19 2.21 2.21%
## 8 PSQu8 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: 8 x 5
## BPE Res n percent bar_text
## <fct> <fct> <int> <dbl> <chr>
## 1 PSQu1 Không d<U+1ED3>ng ý 40 4.66 4.66%
## 2 PSQu2 Không d<U+1ED3>ng ý 33 3.85 3.85%
## 3 PSQu3 Không d<U+1ED3>ng ý 43 5.01 5.01%
## 4 PSQu4 Không d<U+1ED3>ng ý 50 5.83 5.83%
## 5 PSQu5 Không d<U+1ED3>ng ý 48 5.59 5.59%
## 6 PSQu6 Không d<U+1ED3>ng ý 47 5.48 5.48%
## 7 PSQu7 Không d<U+1ED3>ng ý 42 4.9 4.9%
## 8 PSQu8 Không d<U+1ED3>ng ý 25 2.91 2.91%
# 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: 8 x 5
## BPE Res n percent bar_text
## <fct> <fct> <int> <dbl> <chr>
## 1 PSQu1 Khá không d<U+1ED3>ng ý 60 6.99 6.99%
## 2 PSQu2 Khá không d<U+1ED3>ng ý 15 1.75 1.75%
## 3 PSQu3 Khá không d<U+1ED3>ng ý 61 7.11 7.11%
## 4 PSQu4 Khá không d<U+1ED3>ng ý 53 6.18 6.18%
## 5 PSQu5 Khá không d<U+1ED3>ng ý 42 4.9 4.9%
## 6 PSQu6 Khá không d<U+1ED3>ng ý 75 8.74 8.74%
## 7 PSQu7 Khá không d<U+1ED3>ng ý 62 7.23 7.23%
## 8 PSQu8 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: 8 x 5
## BPE Res n percent bar_text
## <fct> <fct> <int> <dbl> <chr>
## 1 PSQu1 Bình thu<U+1EDD>ng 98 11.4 11.42%
## 2 PSQu2 Bình thu<U+1EDD>ng 69 8.04 8.04%
## 3 PSQu3 Bình thu<U+1EDD>ng 101 11.8 11.77%
## 4 PSQu4 Bình thu<U+1EDD>ng 254 29.6 29.6%
## 5 PSQu5 Bình thu<U+1EDD>ng 183 21.3 21.33%
## 6 PSQu6 Bình thu<U+1EDD>ng 98 11.4 11.42%
## 7 PSQu7 Bình thu<U+1EDD>ng 125 14.6 14.57%
## 8 PSQu8 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: 8 x 5
## BPE Res n percent bar_text
## <fct> <fct> <int> <dbl> <chr>
## 1 PSQu1 Khá d<U+1ED3>ng ý 205 23.9 23.89%
## 2 PSQu2 Khá d<U+1ED3>ng ý 140 16.3 16.32%
## 3 PSQu3 Khá d<U+1ED3>ng ý 203 23.7 23.66%
## 4 PSQu4 Khá d<U+1ED3>ng ý 162 18.9 18.88%
## 5 PSQu5 Khá d<U+1ED3>ng ý 150 17.5 17.48%
## 6 PSQu6 Khá d<U+1ED3>ng ý 241 28.1 28.09%
## 7 PSQu7 Khá d<U+1ED3>ng ý 216 25.2 25.17%
## 8 PSQu8 Khá d<U+1ED3>ng ý 169 19.7 19.7%
# For displaying percent of "Agree":
df_odered %>%
filter(Res == "\u0110\u1ED3ng \u00FD") %>%
filter(percent >= 0) -> df_for_text6
df_for_text6
## # A tibble: 8 x 5
## BPE Res n percent bar_text
## <fct> <fct> <int> <dbl> <chr>
## 1 PSQu1 Ð<U+1ED3>ng ý 349 40.7 40.68%
## 2 PSQu2 Ð<U+1ED3>ng ý 445 51.9 51.86%
## 3 PSQu3 Ð<U+1ED3>ng ý 347 40.4 40.44%
## 4 PSQu4 Ð<U+1ED3>ng ý 265 30.9 30.89%
## 5 PSQu5 Ð<U+1ED3>ng ý 347 40.4 40.44%
## 6 PSQu6 Ð<U+1ED3>ng ý 304 35.4 35.43%
## 7 PSQu7 Ð<U+1ED3>ng ý 320 37.3 37.3%
## 8 PSQu8 Ð<U+1ED3>ng ý 412 48.0 48.02%
# 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: 8 x 5
## BPE Res n percent bar_text
## <fct> <fct> <int> <dbl> <chr>
## 1 PSQu1 R<U+1EA5>t d<U+1ED3>ng ý 88 10.3 10.26%
## 2 PSQu2 R<U+1EA5>t d<U+1ED3>ng ý 144 16.8 16.78%
## 3 PSQu3 R<U+1EA5>t d<U+1ED3>ng ý 86 10.0 10.02%
## 4 PSQu4 R<U+1EA5>t d<U+1ED3>ng ý 57 6.64 6.64%
## 5 PSQu5 R<U+1EA5>t d<U+1ED3>ng ý 73 8.51 8.51%
## 6 PSQu6 R<U+1EA5>t d<U+1ED3>ng ý 69 8.04 8.04%
## 7 PSQu7 R<U+1EA5>t d<U+1ED3>ng ý 74 8.62 8.62%
## 8 PSQu8 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: 8 x 5
## BPE Res n percent bar_text
## <fct> <fct> <int> <dbl> <chr>
## 1 PSQu1 R<U+1EA5>t d<U+1ED3>ng ý 88 10.3 10.26%
## 2 PSQu2 R<U+1EA5>t d<U+1ED3>ng ý 144 16.8 16.78%
## 3 PSQu3 R<U+1EA5>t d<U+1ED3>ng ý 86 10.0 10.02%
## 4 PSQu4 R<U+1EA5>t d<U+1ED3>ng ý 57 6.64 6.64%
## 5 PSQu5 R<U+1EA5>t d<U+1ED3>ng ý 73 8.51 8.51%
## 6 PSQu6 R<U+1EA5>t d<U+1ED3>ng ý 69 8.04 8.04%
## 7 PSQu7 R<U+1EA5>t d<U+1ED3>ng ý 74 8.62 8.62%
## 8 PSQu8 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 = 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 LOY-Nhãn tiếng anh
# Plot Likert graph for people in both cities for construct LIN
library(tidyverse)
library(compareGroups)
head(DN_HCM_SEM4_LOY)
## Res BPE
## 1 4 LOY1
## 2 4 LOY1
## 3 2 LOY1
## 4 5 LOY1
## 5 4 LOY1
## 6 4 LOY1
dim(DN_HCM_SEM4_LOY)
## [1] 6006 2
attach(DN_HCM_SEM4_LOY)
## The following objects are masked from DN_HCM_SEM4_PSQ:
##
## BPE, Res
## The following objects are masked from HCM_SEM4:
##
## BPE, Res
## The following objects are masked from DN_SEM4:
##
## BPE, Res
## The following objects are masked from DN_HCM_SEM4:
##
## BPE, Res
DN_HCM_SEM4_LOY = within(DN_HCM_SEM4_LOY, {
Res = factor(Res, labels = c("Very Disagree", "Disagree", "Quite Disagree", "Normal", "Quite Agree", "Agree", "Very Agree"))
BPE = factor(BPE, labels = c("LOY1", "LOY2", "LOY3", "LOY4", "LOY5", "LOY6", "LOY7"))
})
str(DN_HCM_SEM4_LOY)
## 'data.frame': 6006 obs. of 2 variables:
## $ Res: Factor w/ 7 levels "Very Disagree",..: 4 4 2 5 4 4 2 6 6 6 ...
## $ BPE: Factor w/ 7 levels "LOY1","LOY2",..: 1 1 1 1 1 1 1 1 1 1 ...
summary(DN_HCM_SEM4_LOY)
## Res BPE
## Very Disagree : 66 LOY1:858
## Disagree : 169 LOY2:858
## Quite Disagree: 178 LOY3:858
## Normal : 767 LOY4:858
## Quite Agree :1250 LOY5:858
## Agree :2672 LOY6:858
## Very Agree : 904 LOY7:858
## t <- compareGroups(Res ~ BPE, data = DN_SEM1)
## createTable(t)
DN_HCM_SEM4_LOY %>%
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] LOY1 LOY2 LOY4 LOY6 LOY5 LOY3 LOY7
## Levels: LOY1 LOY2 LOY3 LOY4 LOY5 LOY6 LOY7
# 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: 49 x 5
## BPE Res n percent bar_text
## <fct> <fct> <int> <dbl> <chr>
## 1 LOY1 Very Disagree 4 0.47 0.47%
## 2 LOY1 Disagree 18 2.1 2.1%
## 3 LOY1 Quite Disagree 19 2.21 2.21%
## 4 LOY1 Normal 114 13.3 13.29%
## 5 LOY1 Quite Agree 167 19.5 19.46%
## 6 LOY1 Agree 430 50.1 50.12%
## 7 LOY1 Very Agree 106 12.4 12.35%
## 8 LOY2 Very Disagree 6 0.7 0.7%
## 9 LOY2 Disagree 22 2.56 2.56%
## 10 LOY2 Quite Disagree 16 1.86 1.86%
## # ... with 39 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 loylty (LOY) 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: 7 x 5
## BPE Res n percent bar_text
## <fct> <fct> <int> <dbl> <chr>
## 1 LOY1 Very Disagree 4 0.47 0.47%
## 2 LOY2 Very Disagree 6 0.7 0.7%
## 3 LOY3 Very Disagree 3 0.35 0.35%
## 4 LOY4 Very Disagree 13 1.52 1.52%
## 5 LOY5 Very Disagree 12 1.4 1.4%
## 6 LOY6 Very Disagree 15 1.75 1.75%
## 7 LOY7 Very Disagree 13 1.52 1.52%
# 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 LOY6 Disagree 58 6.76 6.76%
# For displaying percent of "Quite Disagree":
df_odered %>%
filter(Res == "Quite Disagree") %>%
filter(percent >= 0) -> df_for_text3
df_for_text3
## # A tibble: 7 x 5
## BPE Res n percent bar_text
## <fct> <fct> <int> <dbl> <chr>
## 1 LOY1 Quite Disagree 19 2.21 2.21%
## 2 LOY2 Quite Disagree 16 1.86 1.86%
## 3 LOY3 Quite Disagree 18 2.1 2.1%
## 4 LOY4 Quite Disagree 31 3.61 3.61%
## 5 LOY5 Quite Disagree 25 2.91 2.91%
## 6 LOY6 Quite Disagree 52 6.06 6.06%
## 7 LOY7 Quite Disagree 17 1.98 1.98%
# For displaying percent of "Normal":
df_odered %>%
filter(Res == "Normal") %>%
filter(percent >= 0) -> df_for_text4
df_for_text4
## # A tibble: 7 x 5
## BPE Res n percent bar_text
## <fct> <fct> <int> <dbl> <chr>
## 1 LOY1 Normal 114 13.3 13.29%
## 2 LOY2 Normal 99 11.5 11.54%
## 3 LOY3 Normal 92 10.7 10.72%
## 4 LOY4 Normal 130 15.2 15.15%
## 5 LOY5 Normal 111 12.9 12.94%
## 6 LOY6 Normal 141 16.4 16.43%
## 7 LOY7 Normal 80 9.32 9.32%
# For displaying percent of "Quite Agree":
df_odered %>%
filter(Res == "Quite Agree") %>%
filter(percent >= 0) -> df_for_text5
df_for_text5
## # A tibble: 7 x 5
## BPE Res n percent bar_text
## <fct> <fct> <int> <dbl> <chr>
## 1 LOY1 Quite Agree 167 19.5 19.46%
## 2 LOY2 Quite Agree 169 19.7 19.7%
## 3 LOY3 Quite Agree 160 18.6 18.65%
## 4 LOY4 Quite Agree 212 24.7 24.71%
## 5 LOY5 Quite Agree 214 24.9 24.94%
## 6 LOY6 Quite Agree 172 20.0 20.05%
## 7 LOY7 Quite Agree 156 18.2 18.18%
# For displaying percent of "Agree":
df_odered %>%
filter(Res == "Agree") %>%
filter(percent >= 0) -> df_for_text6
df_for_text6
## # A tibble: 7 x 5
## BPE Res n percent bar_text
## <fct> <fct> <int> <dbl> <chr>
## 1 LOY1 Agree 430 50.1 50.12%
## 2 LOY2 Agree 428 49.9 49.88%
## 3 LOY3 Agree 437 50.9 50.93%
## 4 LOY4 Agree 337 39.3 39.28%
## 5 LOY5 Agree 344 40.1 40.09%
## 6 LOY6 Agree 293 34.2 34.15%
## 7 LOY7 Agree 403 47.0 46.97%
# 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: 7 x 5
## BPE Res n percent bar_text
## <fct> <fct> <int> <dbl> <chr>
## 1 LOY1 Very Agree 106 12.4 12.35%
## 2 LOY2 Very Agree 118 13.8 13.75%
## 3 LOY3 Very Agree 132 15.4 15.38%
## 4 LOY4 Very Agree 118 13.8 13.75%
## 5 LOY5 Very Agree 129 15.0 15.03%
## 6 LOY6 Very Agree 127 14.8 14.8%
## 7 LOY7 Very Agree 174 20.3 20.28%
# For displaying percent of "Very Agree":
df_odered %>%
filter(Res == "Very Agree") -> df_for_text
df_for_text
## # A tibble: 7 x 5
## BPE Res n percent bar_text
## <fct> <fct> <int> <dbl> <chr>
## 1 LOY1 Very Agree 106 12.4 12.35%
## 2 LOY2 Very Agree 118 13.8 13.75%
## 3 LOY3 Very Agree 132 15.4 15.38%
## 4 LOY4 Very Agree 118 13.8 13.75%
## 5 LOY5 Very Agree 129 15.0 15.03%
## 6 LOY6 Very Agree 127 14.8 14.8%
## 7 LOY7 Very Agree 174 20.3 20.28%
# 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.4. Construct LOY-Nhãn tiếng việt
DN_HCM_SEM4_LOY_v = within(DN_HCM_SEM4_LOY, {
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("LOY1", "LOY2", "LOY3", "LOY4", "LOY5", "LOY6", "LOY7"))
})
str(DN_HCM_SEM4_LOY_v)
## 'data.frame': 6006 obs. of 2 variables:
## $ Res: Factor w/ 7 levels "R<U+1EA5>t không d<U+1ED3>ng ý",..: 4 4 2 5 4 4 2 6 6 6 ...
## $ BPE: Factor w/ 7 levels "LOY1","LOY2",..: 1 1 1 1 1 1 1 1 1 1 ...
summary(DN_HCM_SEM4_LOY_v)
## Res BPE
## R<U+1EA5>t không d<U+1ED3>ng ý: 66 LOY1:858
## Không d<U+1ED3>ng ý : 169 LOY2:858
## Khá không d<U+1ED3>ng ý : 178 LOY3:858
## Bình thu<U+1EDD>ng : 767 LOY4:858
## Khá d<U+1ED3>ng ý :1250 LOY5:858
## Ð<U+1ED3>ng ý :2672 LOY6:858
## R<U+1EA5>t d<U+1ED3>ng ý : 904 LOY7:858
## t <- compareGroups(Res ~ BPE, data = DN_SEM1)
## createTable(t)
DN_HCM_SEM4_LOY_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] LOY1 LOY2 LOY4 LOY6 LOY5 LOY3 LOY7
## Levels: LOY1 LOY2 LOY3 LOY4 LOY5 LOY6 LOY7
# 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: 49 x 5
## BPE Res n percent bar_text
## <fct> <fct> <int> <dbl> <chr>
## 1 LOY1 R<U+1EA5>t không d<U+1ED3>ng ý 4 0.47 0.47%
## 2 LOY1 Không d<U+1ED3>ng ý 18 2.1 2.1%
## 3 LOY1 Khá không d<U+1ED3>ng ý 19 2.21 2.21%
## 4 LOY1 Bình thu<U+1EDD>ng 114 13.3 13.29%
## 5 LOY1 Khá d<U+1ED3>ng ý 167 19.5 19.46%
## 6 LOY1 Ð<U+1ED3>ng ý 430 50.1 50.12%
## 7 LOY1 R<U+1EA5>t d<U+1ED3>ng ý 106 12.4 12.35%
## 8 LOY2 R<U+1EA5>t không d<U+1ED3>ng ý 6 0.7 0.7%
## 9 LOY2 Không d<U+1ED3>ng ý 22 2.56 2.56%
## 10 LOY2 Khá không d<U+1ED3>ng ý 16 1.86 1.86%
## # ... with 39 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 l\u00F2ng trung th\u00E0nh (LOY) c\u1EE7a h\u00E0nh kh\u00E1ch s\u1EED d\u1EE5ng xe bu\u00FDt \u0111\u00F4 thi \u1EDF 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: 7 x 5
## BPE Res n percent bar_text
## <fct> <fct> <int> <dbl> <chr>
## 1 LOY1 R<U+1EA5>t không d<U+1ED3>ng ý 4 0.47 0.47%
## 2 LOY2 R<U+1EA5>t không d<U+1ED3>ng ý 6 0.7 0.7%
## 3 LOY3 R<U+1EA5>t không d<U+1ED3>ng ý 3 0.35 0.35%
## 4 LOY4 R<U+1EA5>t không d<U+1ED3>ng ý 13 1.52 1.52%
## 5 LOY5 R<U+1EA5>t không d<U+1ED3>ng ý 12 1.4 1.4%
## 6 LOY6 R<U+1EA5>t không d<U+1ED3>ng ý 15 1.75 1.75%
## 7 LOY7 R<U+1EA5>t không d<U+1ED3>ng ý 13 1.52 1.52%
# 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: 7 x 5
## BPE Res n percent bar_text
## <fct> <fct> <int> <dbl> <chr>
## 1 LOY1 Không d<U+1ED3>ng ý 18 2.1 2.1%
## 2 LOY2 Không d<U+1ED3>ng ý 22 2.56 2.56%
## 3 LOY3 Không d<U+1ED3>ng ý 16 1.86 1.86%
## 4 LOY4 Không d<U+1ED3>ng ý 17 1.98 1.98%
## 5 LOY5 Không d<U+1ED3>ng ý 23 2.68 2.68%
## 6 LOY6 Không d<U+1ED3>ng ý 58 6.76 6.76%
## 7 LOY7 Không d<U+1ED3>ng ý 15 1.75 1.75%
# 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: 7 x 5
## BPE Res n percent bar_text
## <fct> <fct> <int> <dbl> <chr>
## 1 LOY1 Khá không d<U+1ED3>ng ý 19 2.21 2.21%
## 2 LOY2 Khá không d<U+1ED3>ng ý 16 1.86 1.86%
## 3 LOY3 Khá không d<U+1ED3>ng ý 18 2.1 2.1%
## 4 LOY4 Khá không d<U+1ED3>ng ý 31 3.61 3.61%
## 5 LOY5 Khá không d<U+1ED3>ng ý 25 2.91 2.91%
## 6 LOY6 Khá không d<U+1ED3>ng ý 52 6.06 6.06%
## 7 LOY7 Khá không d<U+1ED3>ng ý 17 1.98 1.98%
# 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: 7 x 5
## BPE Res n percent bar_text
## <fct> <fct> <int> <dbl> <chr>
## 1 LOY1 Bình thu<U+1EDD>ng 114 13.3 13.29%
## 2 LOY2 Bình thu<U+1EDD>ng 99 11.5 11.54%
## 3 LOY3 Bình thu<U+1EDD>ng 92 10.7 10.72%
## 4 LOY4 Bình thu<U+1EDD>ng 130 15.2 15.15%
## 5 LOY5 Bình thu<U+1EDD>ng 111 12.9 12.94%
## 6 LOY6 Bình thu<U+1EDD>ng 141 16.4 16.43%
## 7 LOY7 Bình thu<U+1EDD>ng 80 9.32 9.32%
# 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: 7 x 5
## BPE Res n percent bar_text
## <fct> <fct> <int> <dbl> <chr>
## 1 LOY1 Khá d<U+1ED3>ng ý 167 19.5 19.46%
## 2 LOY2 Khá d<U+1ED3>ng ý 169 19.7 19.7%
## 3 LOY3 Khá d<U+1ED3>ng ý 160 18.6 18.65%
## 4 LOY4 Khá d<U+1ED3>ng ý 212 24.7 24.71%
## 5 LOY5 Khá d<U+1ED3>ng ý 214 24.9 24.94%
## 6 LOY6 Khá d<U+1ED3>ng ý 172 20.0 20.05%
## 7 LOY7 Khá d<U+1ED3>ng ý 156 18.2 18.18%
# For displaying percent of "Agree":
df_odered %>%
filter(Res == "\u0110\u1ED3ng \u00FD") %>%
filter(percent >= 0) -> df_for_text6
df_for_text6
## # A tibble: 7 x 5
## BPE Res n percent bar_text
## <fct> <fct> <int> <dbl> <chr>
## 1 LOY1 Ð<U+1ED3>ng ý 430 50.1 50.12%
## 2 LOY2 Ð<U+1ED3>ng ý 428 49.9 49.88%
## 3 LOY3 Ð<U+1ED3>ng ý 437 50.9 50.93%
## 4 LOY4 Ð<U+1ED3>ng ý 337 39.3 39.28%
## 5 LOY5 Ð<U+1ED3>ng ý 344 40.1 40.09%
## 6 LOY6 Ð<U+1ED3>ng ý 293 34.2 34.15%
## 7 LOY7 Ð<U+1ED3>ng ý 403 47.0 46.97%
# 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: 7 x 5
## BPE Res n percent bar_text
## <fct> <fct> <int> <dbl> <chr>
## 1 LOY1 R<U+1EA5>t d<U+1ED3>ng ý 106 12.4 12.35%
## 2 LOY2 R<U+1EA5>t d<U+1ED3>ng ý 118 13.8 13.75%
## 3 LOY3 R<U+1EA5>t d<U+1ED3>ng ý 132 15.4 15.38%
## 4 LOY4 R<U+1EA5>t d<U+1ED3>ng ý 118 13.8 13.75%
## 5 LOY5 R<U+1EA5>t d<U+1ED3>ng ý 129 15.0 15.03%
## 6 LOY6 R<U+1EA5>t d<U+1ED3>ng ý 127 14.8 14.8%
## 7 LOY7 R<U+1EA5>t d<U+1ED3>ng ý 174 20.3 20.28%
# For displaying percent of "Very Agree":
df_odered %>%
filter(Res == "R\u1EA5t \u0111\u1ED3ng \u00FD") -> df_for_text
df_for_text
## # A tibble: 7 x 5
## BPE Res n percent bar_text
## <fct> <fct> <int> <dbl> <chr>
## 1 LOY1 R<U+1EA5>t d<U+1ED3>ng ý 106 12.4 12.35%
## 2 LOY2 R<U+1EA5>t d<U+1ED3>ng ý 118 13.8 13.75%
## 3 LOY3 R<U+1EA5>t d<U+1ED3>ng ý 132 15.4 15.38%
## 4 LOY4 R<U+1EA5>t d<U+1ED3>ng ý 118 13.8 13.75%
## 5 LOY5 R<U+1EA5>t d<U+1ED3>ng ý 129 15.0 15.03%
## 6 LOY6 R<U+1EA5>t d<U+1ED3>ng ý 127 14.8 14.8%
## 7 LOY7 R<U+1EA5>t d<U+1ED3>ng ý 174 20.3 20.28%
# 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.5. 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_SEM4_IMA)
## Res BPE
## 1 6 IMA1
## 2 4 IMA1
## 3 4 IMA1
## 4 5 IMA1
## 5 5 IMA1
## 6 4 IMA1
dim(DN_HCM_SEM4_IMA)
## [1] 4290 2
attach(DN_HCM_SEM4_IMA)
## The following objects are masked from DN_HCM_SEM4_LOY:
##
## BPE, Res
## The following objects are masked from DN_HCM_SEM4_PSQ:
##
## BPE, Res
## The following objects are masked from HCM_SEM4:
##
## BPE, Res
## The following objects are masked from DN_SEM4:
##
## BPE, Res
## The following objects are masked from DN_HCM_SEM4:
##
## BPE, Res
DN_HCM_SEM4_IMA = within(DN_HCM_SEM4_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_SEM4_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_SEM4_IMA)
## Res BPE
## Very Disagree : 48 IMA1:858
## Disagree : 85 IMA2:858
## Quite Disagree: 124 IMA3:858
## Normal : 660 IMA4:858
## Quite Agree :1052 IMA5:858
## Agree :1941
## Very Agree : 380
## t <- compareGroups(Res ~ BPE, data = DN_SEM1)
## createTable(t)
DN_HCM_SEM4_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 IMA5 IMA4
## 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 20 2.33 2.33%
## 3 IMA1 Quite Disagree 32 3.73 3.73%
## 4 IMA1 Normal 155 18.1 18.07%
## 5 IMA1 Quite Agree 230 26.8 26.81%
## 6 IMA1 Agree 350 40.8 40.79%
## 7 IMA1 Very Agree 65 7.58 7.58%
## 8 IMA2 Very Disagree 11 1.28 1.28%
## 9 IMA2 Disagree 19 2.21 2.21%
## 10 IMA2 Quite Disagree 25 2.91 2.91%
## # ... 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 14 1.63 1.63%
## 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 32 3.73 3.73%
## 2 IMA2 Quite Disagree 25 2.91 2.91%
## 3 IMA3 Quite Disagree 20 2.33 2.33%
## 4 IMA4 Quite Disagree 26 3.03 3.03%
## 5 IMA5 Quite Disagree 21 2.45 2.45%
# 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 155 18.1 18.07%
## 2 IMA2 Normal 158 18.4 18.41%
## 3 IMA3 Normal 129 15.0 15.03%
## 4 IMA4 Normal 113 13.2 13.17%
## 5 IMA5 Normal 105 12.2 12.24%
# 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 213 24.8 24.83%
## 3 IMA3 Quite Agree 207 24.1 24.13%
## 4 IMA4 Quite Agree 199 23.2 23.19%
## 5 IMA5 Quite Agree 203 23.7 23.66%
# 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 350 40.8 40.79%
## 2 IMA2 Agree 366 42.7 42.66%
## 3 IMA3 Agree 401 46.7 46.74%
## 4 IMA4 Agree 406 47.3 47.32%
## 5 IMA5 Agree 418 48.7 48.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: 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 79 9.21 9.21%
## 4 IMA4 Very Agree 86 10.0 10.02%
## 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 79 9.21 9.21%
## 4 IMA4 Very Agree 86 10.0 10.02%
## 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.6. Construct IMA- Nhãn tiếng việt
DN_HCM_SEM4_IMA_v = within(DN_HCM_SEM4_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_SEM4_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_SEM4_IMA_v)
## Res BPE
## R<U+1EA5>t không d<U+1ED3>ng ý: 48 IMA1:858
## Không d<U+1ED3>ng ý : 85 IMA2:858
## Khá không d<U+1ED3>ng ý : 124 IMA3:858
## Bình thu<U+1EDD>ng : 660 IMA4:858
## Khá d<U+1ED3>ng ý :1052 IMA5:858
## Ð<U+1ED3>ng ý :1941
## R<U+1EA5>t d<U+1ED3>ng ý : 380
## t <- compareGroups(Res ~ BPE, data = DN_SEM1)
## createTable(t)
DN_HCM_SEM4_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 IMA5 IMA4
## 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 ý 20 2.33 2.33%
## 3 IMA1 Khá không d<U+1ED3>ng ý 32 3.73 3.73%
## 4 IMA1 Bình thu<U+1EDD>ng 155 18.1 18.07%
## 5 IMA1 Khá d<U+1ED3>ng ý 230 26.8 26.81%
## 6 IMA1 Ð<U+1ED3>ng ý 350 40.8 40.79%
## 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 ý 19 2.21 2.21%
## 10 IMA2 Khá không d<U+1ED3>ng ý 25 2.91 2.91%
## # ... 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 ý 14 1.63 1.63%
## 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 ý 20 2.33 2.33%
## 2 IMA2 Không d<U+1ED3>ng ý 19 2.21 2.21%
## 3 IMA3 Không d<U+1ED3>ng ý 11 1.28 1.28%
## 4 IMA4 Không d<U+1ED3>ng ý 14 1.63 1.63%
## 5 IMA5 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: 5 x 5
## BPE Res n percent bar_text
## <fct> <fct> <int> <dbl> <chr>
## 1 IMA1 Khá không d<U+1ED3>ng ý 32 3.73 3.73%
## 2 IMA2 Khá không d<U+1ED3>ng ý 25 2.91 2.91%
## 3 IMA3 Khá không d<U+1ED3>ng ý 20 2.33 2.33%
## 4 IMA4 Khá không d<U+1ED3>ng ý 26 3.03 3.03%
## 5 IMA5 Khá không d<U+1ED3>ng ý 21 2.45 2.45%
# 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 155 18.1 18.07%
## 2 IMA2 Bình thu<U+1EDD>ng 158 18.4 18.41%
## 3 IMA3 Bình thu<U+1EDD>ng 129 15.0 15.03%
## 4 IMA4 Bình thu<U+1EDD>ng 113 13.2 13.17%
## 5 IMA5 Bình thu<U+1EDD>ng 105 12.2 12.24%
# 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 ý 213 24.8 24.83%
## 3 IMA3 Khá d<U+1ED3>ng ý 207 24.1 24.13%
## 4 IMA4 Khá d<U+1ED3>ng ý 199 23.2 23.19%
## 5 IMA5 Khá d<U+1ED3>ng ý 203 23.7 23.66%
# 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 ý 350 40.8 40.79%
## 2 IMA2 Ð<U+1ED3>ng ý 366 42.7 42.66%
## 3 IMA3 Ð<U+1ED3>ng ý 401 46.7 46.74%
## 4 IMA4 Ð<U+1ED3>ng ý 406 47.3 47.32%
## 5 IMA5 Ð<U+1ED3>ng ý 418 48.7 48.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: 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 ý 79 9.21 9.21%
## 4 IMA4 R<U+1EA5>t d<U+1ED3>ng ý 86 10.0 10.02%
## 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 ý 79 9.21 9.21%
## 4 IMA4 R<U+1EA5>t d<U+1ED3>ng ý 86 10.0 10.02%
## 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.7. 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_SEM4_PHB)
## Res BPE
## 1 6 PHB1
## 2 3 PHB1
## 3 5 PHB1
## 4 5 PHB1
## 5 5 PHB1
## 6 4 PHB1
dim(DN_HCM_SEM4_PHB)
## [1] 4290 2
attach(DN_HCM_SEM4_PHB)
## The following objects are masked from DN_HCM_SEM4_IMA:
##
## BPE, Res
## The following objects are masked from DN_HCM_SEM4_LOY:
##
## BPE, Res
## The following objects are masked from DN_HCM_SEM4_PSQ:
##
## BPE, Res
## The following objects are masked from HCM_SEM4:
##
## BPE, Res
## The following objects are masked from DN_SEM4:
##
## BPE, Res
## The following objects are masked from DN_HCM_SEM4:
##
## BPE, Res
DN_HCM_SEM4_PHB = within(DN_HCM_SEM4_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_SEM4_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_SEM4_PHB)
## Res BPE
## Very Disagree : 88 PHB1:858
## Disagree : 74 PHB2:858
## Quite Disagree: 113 PHB3:858
## Normal : 376 PHB4:858
## Quite Agree : 802 PHB5:858
## Agree :1917
## Very Agree : 920
## t <- compareGroups(Res ~ BPE, data = DN_SEM1)
## createTable(t)
DN_HCM_SEM4_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 24 2.8 2.8%
## 2 PHB1 Disagree 19 2.21 2.21%
## 3 PHB1 Quite Disagree 36 4.2 4.2%
## 4 PHB1 Normal 99 11.5 11.54%
## 5 PHB1 Quite Agree 215 25.1 25.06%
## 6 PHB1 Agree 351 40.9 40.91%
## 7 PHB1 Very Agree 114 13.3 13.29%
## 8 PHB2 Very Disagree 13 1.52 1.52%
## 9 PHB2 Disagree 22 2.56 2.56%
## 10 PHB2 Quite Disagree 24 2.8 2.8%
## # ... 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 24 2.8 2.8%
## 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 23 2.68 2.68%
# 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 36 4.2 4.2%
## 2 PHB2 Quite Disagree 24 2.8 2.8%
## 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 99 11.5 11.54%
## 2 PHB2 Normal 69 8.04 8.04%
## 3 PHB3 Normal 89 10.4 10.37%
## 4 PHB4 Normal 55 6.41 6.41%
## 5 PHB5 Normal 64 7.46 7.46%
# 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 164 19.1 19.11%
## 3 PHB3 Quite Agree 175 20.4 20.4%
## 4 PHB4 Quite Agree 132 15.4 15.38%
## 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 351 40.9 40.91%
## 2 PHB2 Agree 379 44.2 44.17%
## 3 PHB3 Agree 383 44.6 44.64%
## 4 PHB4 Agree 389 45.3 45.34%
## 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 187 21.8 21.79%
## 3 PHB3 Very Agree 139 16.2 16.2%
## 4 PHB4 Very Agree 252 29.4 29.37%
## 5 PHB5 Very Agree 228 26.6 26.57%
# 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 187 21.8 21.79%
## 3 PHB3 Very Agree 139 16.2 16.2%
## 4 PHB4 Very Agree 252 29.4 29.37%
## 5 PHB5 Very Agree 228 26.6 26.57%
# 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.8. Construct PHB - Nhãn tiếng việt
DN_HCM_SEM4_PHB_v = within(DN_HCM_SEM4_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_SEM4_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_SEM4_PHB_v)
## Res BPE
## R<U+1EA5>t không d<U+1ED3>ng ý: 88 PHB1:858
## Không d<U+1ED3>ng ý : 74 PHB2:858
## Khá không d<U+1ED3>ng ý : 113 PHB3:858
## Bình thu<U+1EDD>ng : 376 PHB4:858
## Khá d<U+1ED3>ng ý : 802 PHB5:858
## Ð<U+1ED3>ng ý :1917
## R<U+1EA5>t d<U+1ED3>ng ý : 920
## t <- compareGroups(Res ~ BPE, data = DN_SEM1)
## createTable(t)
DN_HCM_SEM4_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 ý 24 2.8 2.8%
## 2 PHB1 Không d<U+1ED3>ng ý 19 2.21 2.21%
## 3 PHB1 Khá không d<U+1ED3>ng ý 36 4.2 4.2%
## 4 PHB1 Bình thu<U+1EDD>ng 99 11.5 11.54%
## 5 PHB1 Khá d<U+1ED3>ng ý 215 25.1 25.06%
## 6 PHB1 Ð<U+1ED3>ng ý 351 40.9 40.91%
## 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 ý 22 2.56 2.56%
## 10 PHB2 Khá không d<U+1ED3>ng ý 24 2.8 2.8%
## # ... 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 ý 24 2.8 2.8%
## 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 ý 23 2.68 2.68%
# 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 ý 19 2.21 2.21%
## 2 PHB2 Không d<U+1ED3>ng ý 22 2.56 2.56%
## 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 ý 7 0.82 0.82%
# 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 ý 36 4.2 4.2%
## 2 PHB2 Khá không d<U+1ED3>ng ý 24 2.8 2.8%
## 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 99 11.5 11.54%
## 2 PHB2 Bình thu<U+1EDD>ng 69 8.04 8.04%
## 3 PHB3 Bình thu<U+1EDD>ng 89 10.4 10.37%
## 4 PHB4 Bình thu<U+1EDD>ng 55 6.41 6.41%
## 5 PHB5 Bình thu<U+1EDD>ng 64 7.46 7.46%
# 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 ý 164 19.1 19.11%
## 3 PHB3 Khá d<U+1ED3>ng ý 175 20.4 20.4%
## 4 PHB4 Khá d<U+1ED3>ng ý 132 15.4 15.38%
## 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 ý 351 40.9 40.91%
## 2 PHB2 Ð<U+1ED3>ng ý 379 44.2 44.17%
## 3 PHB3 Ð<U+1ED3>ng ý 383 44.6 44.64%
## 4 PHB4 Ð<U+1ED3>ng ý 389 45.3 45.34%
## 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 ý 187 21.8 21.79%
## 3 PHB3 R<U+1EA5>t d<U+1ED3>ng ý 139 16.2 16.2%
## 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 ý 228 26.6 26.57%
# 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 ý 187 21.8 21.79%
## 3 PHB3 R<U+1EA5>t d<U+1ED3>ng ý 139 16.2 16.2%
## 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 ý 228 26.6 26.57%
# 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.9. 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_SEM4_PEB)
## Res BPE
## 1 4 PEB1
## 2 5 PEB1
## 3 6 PEB1
## 4 5 PEB1
## 5 6 PEB1
## 6 7 PEB1
dim(DN_HCM_SEM4_PEB)
## [1] 3432 2
attach(DN_HCM_SEM4_PEB)
## The following objects are masked from DN_HCM_SEM4_PHB:
##
## BPE, Res
## The following objects are masked from DN_HCM_SEM4_IMA:
##
## BPE, Res
## The following objects are masked from DN_HCM_SEM4_LOY:
##
## BPE, Res
## The following objects are masked from DN_HCM_SEM4_PSQ:
##
## BPE, Res
## The following objects are masked from HCM_SEM4:
##
## BPE, Res
## The following objects are masked from DN_SEM4:
##
## BPE, Res
## The following objects are masked from DN_HCM_SEM4:
##
## BPE, Res
DN_HCM_SEM4_PEB = within(DN_HCM_SEM4_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_SEM4_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_SEM4_PEB)
## Res BPE
## Very Disagree : 99 PEB1:858
## Disagree : 68 PEB2:858
## Quite Disagree: 74 PEB3:858
## Normal : 299 PEB4:858
## Quite Agree : 632
## Agree :1452
## Very Agree : 808
## t <- compareGroups(Res ~ BPE, data = DN_SEM1)
## createTable(t)
DN_HCM_SEM4_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 9 1.05 1.05%
## 3 PEB1 Quite Disagree 13 1.52 1.52%
## 4 PEB1 Normal 59 6.88 6.88%
## 5 PEB1 Quite Agree 128 14.9 14.92%
## 6 PEB1 Agree 390 45.4 45.45%
## 7 PEB1 Very Agree 235 27.4 27.39%
## 8 PEB2 Very Disagree 25 2.91 2.91%
## 9 PEB2 Disagree 18 2.1 2.1%
## 10 PEB2 Quite Disagree 19 2.21 2.21%
## # ... 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 26 3.03 3.03%
## 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 19 2.21 2.21%
## 3 PEB3 Quite Disagree 21 2.45 2.45%
## 4 PEB4 Quite Disagree 21 2.45 2.45%
# 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 59 6.88 6.88%
## 2 PEB2 Normal 68 7.93 7.93%
## 3 PEB3 Normal 77 8.97 8.97%
## 4 PEB4 Normal 95 11.1 11.07%
# 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 128 14.9 14.92%
## 2 PEB2 Quite Agree 171 19.9 19.93%
## 3 PEB3 Quite Agree 167 19.5 19.46%
## 4 PEB4 Quite Agree 166 19.4 19.35%
# 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 390 45.4 45.45%
## 2 PEB2 Agree 352 41.0 41.03%
## 3 PEB3 Agree 353 41.1 41.14%
## 4 PEB4 Agree 357 41.6 41.61%
# 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 193 22.5 22.49%
## 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 193 22.5 22.49%
## 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.10. Construct PEB - Nhãn tiếng việt
DN_HCM_SEM4_PEB_v = within(DN_HCM_SEM4_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_SEM4_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_SEM4_PEB_v)
## Res BPE
## R<U+1EA5>t không d<U+1ED3>ng ý: 99 PEB1:858
## Không d<U+1ED3>ng ý : 68 PEB2:858
## Khá không d<U+1ED3>ng ý : 74 PEB3:858
## Bình thu<U+1EDD>ng : 299 PEB4:858
## Khá d<U+1ED3>ng ý : 632
## Ð<U+1ED3>ng ý :1452
## R<U+1EA5>t d<U+1ED3>ng ý : 808
## t <- compareGroups(Res ~ BPE, data = DN_SEM1)
## createTable(t)
DN_HCM_SEM4_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 ý 9 1.05 1.05%
## 3 PEB1 Khá không d<U+1ED3>ng ý 13 1.52 1.52%
## 4 PEB1 Bình thu<U+1EDD>ng 59 6.88 6.88%
## 5 PEB1 Khá d<U+1ED3>ng ý 128 14.9 14.92%
## 6 PEB1 Ð<U+1ED3>ng ý 390 45.4 45.45%
## 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 ý 18 2.1 2.1%
## 10 PEB2 Khá không d<U+1ED3>ng ý 19 2.21 2.21%
## # ... 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 ý 26 3.03 3.03%
## 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 ý 9 1.05 1.05%
## 2 PEB2 Không d<U+1ED3>ng ý 18 2.1 2.1%
## 3 PEB3 Không d<U+1ED3>ng ý 21 2.45 2.45%
## 4 PEB4 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: 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 ý 19 2.21 2.21%
## 3 PEB3 Khá không d<U+1ED3>ng ý 21 2.45 2.45%
## 4 PEB4 Khá không d<U+1ED3>ng ý 21 2.45 2.45%
# 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 59 6.88 6.88%
## 2 PEB2 Bình thu<U+1EDD>ng 68 7.93 7.93%
## 3 PEB3 Bình thu<U+1EDD>ng 77 8.97 8.97%
## 4 PEB4 Bình thu<U+1EDD>ng 95 11.1 11.07%
# 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 ý 128 14.9 14.92%
## 2 PEB2 Khá d<U+1ED3>ng ý 171 19.9 19.93%
## 3 PEB3 Khá d<U+1ED3>ng ý 167 19.5 19.46%
## 4 PEB4 Khá d<U+1ED3>ng ý 166 19.4 19.35%
# 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 ý 390 45.4 45.45%
## 2 PEB2 Ð<U+1ED3>ng ý 352 41.0 41.03%
## 3 PEB3 Ð<U+1ED3>ng ý 353 41.1 41.14%
## 4 PEB4 Ð<U+1ED3>ng ý 357 41.6 41.61%
# 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 ý 193 22.5 22.49%
## 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 ý 193 22.5 22.49%
## 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.11. Construct SAT - Nhãn tiếng anh
# Plot Likert graph for people in both cities for construct PVA
library(tidyverse)
library(compareGroups)
head(DN_HCM_SEM4_SAT)
## Res BPE
## 1 6 SAT1
## 2 5 SAT1
## 3 2 SAT1
## 4 5 SAT1
## 5 4 SAT1
## 6 4 SAT1
dim(DN_HCM_SEM4_SAT)
## [1] 2574 2
attach(DN_HCM_SEM4_SAT)
## The following objects are masked from DN_HCM_SEM4_PEB:
##
## BPE, Res
## The following objects are masked from DN_HCM_SEM4_PHB:
##
## BPE, Res
## The following objects are masked from DN_HCM_SEM4_IMA:
##
## BPE, Res
## The following objects are masked from DN_HCM_SEM4_LOY:
##
## BPE, Res
## The following objects are masked from DN_HCM_SEM4_PSQ:
##
## BPE, Res
## The following objects are masked from HCM_SEM4:
##
## BPE, Res
## The following objects are masked from DN_SEM4:
##
## BPE, Res
## The following objects are masked from DN_HCM_SEM4:
##
## BPE, Res
DN_HCM_SEM4_SAT = within(DN_HCM_SEM4_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_SEM4_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_SEM4_SAT)
## Res BPE
## Very Disagree : 23 SAT1:858
## Disagree : 53 SAT2:858
## Quite Disagree: 85 SAT3:858
## Normal : 290
## Quite Agree : 625
## Agree :1134
## Very Agree : 364
## t <- compareGroups(Res ~ BPE, data = DN_SEM1)
## createTable(t)
DN_HCM_SEM4_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 35 4.08 4.08%
## 4 SAT1 Normal 110 12.8 12.82%
## 5 SAT1 Quite Agree 216 25.2 25.17%
## 6 SAT1 Agree 359 41.8 41.84%
## 7 SAT1 Very Agree 106 12.4 12.35%
## 8 SAT2 Very Disagree 6 0.7 0.7%
## 9 SAT2 Disagree 14 1.63 1.63%
## 10 SAT2 Quite Disagree 24 2.8 2.8%
## # ... 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 = "Passengers' satisfaction (SAT) 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 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 35 4.08 4.08%
## 2 SAT2 Quite Disagree 24 2.8 2.8%
## 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 101 11.8 11.77%
## 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 216 25.2 25.17%
## 2 SAT2 Quite Agree 196 22.8 22.84%
## 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 384 44.8 44.76%
## 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 106 12.4 12.35%
## 2 SAT2 Very Agree 133 15.5 15.5%
## 3 SAT3 Very Agree 125 14.6 14.57%
# 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 106 12.4 12.35%
## 2 SAT2 Very Agree 133 15.5 15.5%
## 3 SAT3 Very Agree 125 14.6 14.57%
# 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.12. Construct SAT - Nhãn tiếng việt
DN_HCM_SEM4_SAT_v = within(DN_HCM_SEM4_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_SEM4_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_SEM4_SAT_v)
## Res BPE
## R<U+1EA5>t không d<U+1ED3>ng ý: 23 SAT1:858
## Không d<U+1ED3>ng ý : 53 SAT2:858
## Khá không d<U+1ED3>ng ý : 85 SAT3:858
## Bình thu<U+1EDD>ng : 290
## Khá d<U+1ED3>ng ý : 625
## Ð<U+1ED3>ng ý :1134
## R<U+1EA5>t d<U+1ED3>ng ý : 364
## t <- compareGroups(Res ~ BPE, data = DN_SEM1)
## createTable(t)
DN_HCM_SEM4_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 ý 35 4.08 4.08%
## 4 SAT1 Bình thu<U+1EDD>ng 110 12.8 12.82%
## 5 SAT1 Khá d<U+1ED3>ng ý 216 25.2 25.17%
## 6 SAT1 Ð<U+1ED3>ng ý 359 41.8 41.84%
## 7 SAT1 R<U+1EA5>t d<U+1ED3>ng ý 106 12.4 12.35%
## 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 ý 24 2.8 2.8%
## # ... 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 (SAT) c\u1EE7a h\u00E0nh kh\u00E1ch \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 ý 16 1.86 1.86%
# 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 ý 35 4.08 4.08%
## 2 SAT2 Khá không d<U+1ED3>ng ý 24 2.8 2.8%
## 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 101 11.8 11.77%
## 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 ý 216 25.2 25.17%
## 2 SAT2 Khá d<U+1ED3>ng ý 196 22.8 22.84%
## 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 ý 384 44.8 44.76%
## 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 ý 106 12.4 12.35%
## 2 SAT2 R<U+1EA5>t d<U+1ED3>ng ý 133 15.5 15.5%
## 3 SAT3 R<U+1EA5>t d<U+1ED3>ng ý 125 14.6 14.57%
# 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 ý 106 12.4 12.35%
## 2 SAT2 R<U+1EA5>t d<U+1ED3>ng ý 133 15.5 15.5%
## 3 SAT3 R<U+1EA5>t d<U+1ED3>ng ý 125 14.6 14.57%
# 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