1. Read and set up Data Loyalty for SEM1
# 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/859-Loyaltyofbuspassenger_NonBus_Mising-SEM1.csv"
SEM1 = read.csv(t, header = T)
head(SEM1)
## 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 PSSW1 PSSW2 PSSW3 PSSW4 PSSW5 PSSW6 PSSW7 PSSS1 PSSS2 PSSS3 PSSS4
## 1 3.00 4 5 6 4 6 4 5 6 6 6 6
## 2 2.00 2 5 3 2 4 5 3 2 3 4 2
## 3 0.17 4 6 6 4 1 4 2 2 6 6 4
## 4 4.00 5 5 5 2 6 4 2 6 6 4 1
## 5 2.00 3 2 4 4 2 6 5 3 3 5 2
## 6 2.00 2 5 6 5 4 4 6 3 4 6 2
## PSSS5 PSSS6 PSSS7 PSA1 PSA2 PSA3 PSA4 PSSB5 PSSB6 PSSB7 PSSB8 PSQ1 PSQ2 PSQ3
## 1 4 6 4 6 6 4 6 5 6 6 6 6 6 4
## 2 2 2 2 3 3 4 4 6 6 6 6 4 6 5
## 3 2 2 2 2 6 6 4 6 6 4 2 2 2 2
## 4 4 4 6 5 6 6 5 5 6 7 6 6 5 4
## 5 1 2 2 2 2 5 5 5 6 4 3 6 3 6
## 6 1 1 2 2 5 4 4 4 6 4 2 4 4 5
## PSQ4 PSQ5 PSQ6 PSQ7 PSQ8 PSQ9 PSQ10 PSQ11 PSQ12 PSQ13 PSQ14 PSQ15 PSQ16 PSQ17
## 1 4 6 4 4 4 6 6 6 5 6 4 4 6 4
## 2 4 4 5 6 4 6 6 4 4 5 4 3 4 3
## 3 2 2 4 1 2 1 1 1 6 6 2 6 2 5
## 4 5 5 5 5 4 4 5 5 5 5 4 5 5 5
## 5 3 6 6 4 3 6 4 4 4 5 5 3 5 3
## 6 4 5 5 4 3 3 4 4 4 5 3 3 3 3
## PSQ18 SAT1 SAT2 SAT3 LIN1 LIN2 LIN3 LIN7 LIN4 LIN5 LIN6 IMA1 IMA2 IMA3 IMA4
## 1 2 6 6 6 4 6 5 7 6 6 6 6 6 6 4
## 2 6 5 5 4 4 5 4 4 4 4 5 4 5 6 5
## 3 2 2 2 2 2 6 6 4 4 2 2 4 2 5 2
## 4 5 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
## 6 4 4 5 5 4 3 2 5 5 6 6 4 3 2 2
## IMA5 PHB1 PHB2 PHB5 PHB3 PHB4 PGV1 PGV2 PGV3 PGV4 ATM1 ATM2 ATM3 ATM4 ATM5
## 1 6 6 7 6 7 7 4 4 4 4 3 5 6 4 2
## 2 4 3 4 3 4 6 5 6 6 4 3 5 4 4 4
## 3 2 5 2 6 6 6 6 5 6 6 2 6 4 2 2
## 4 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5
## 5 5 5 6 6 6 5 6 6 6 6 3 4 2 2 5
## 6 4 4 6 7 6 4 7 7 5 2 1 4 5 2 1
## ATM6 ATM7 PPI1 PPI2 PPI3 SIM1 SIM2 SIM3 SIM4 PPA1 PPA2 PPA3 PPA4 SBE1 SBE2
## 1 4 6 6 6 6 4 4 4 2 4 6 4 4 4 4
## 2 4 5 4 4 4 4 4 4 4 4 4 4 4 5 4
## 3 4 2 4 2 2 4 4 4 2 4 6 6 2 6 6
## 4 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5
## 5 4 3 2 3 4 6 6 5 5 5 5 5 5 5 5
## 6 4 2 5 2 2 2 2 2 2 2 3 3 2 2 2
## SBE3 SBE4 EXB1 EXB2 EXB3 PVA1 PVA2 PVA3 EC_Stop WC_Stop EC_Bus WC_Bus Gender
## 1 4 4 4 4 3 6 6 6 0 1 0 1 0
## 2 5 5 4 5 3 5 5 3 0 0 1 0 0
## 3 6 6 4 6 2 6 2 4 0 0 0 0 1
## 4 5 5 5 5 5 5 5 5 0 1 0 1 1
## 5 5 5 5 5 4 6 2 3 0 1 0 1 1
## 6 2 2 5 5 4 6 5 5 0 1 0 1 0
## MarriedStatus Occupation Education Income
## 1 1 1 2 1
## 2 1 1 2 1
## 3 1 1 2 1
## 4 1 1 2 1
## 5 1 1 2 1
## 6 1 1 3 1
names(SEM1)
## [1] "ID" "MCCar" "MCMotor" "MCBus"
## [5] "AGE" "CITY" "FRE" "TripPurpose"
## [9] "Departure" "TimeUseonBus" "TravelTime" "PSSW1"
## [13] "PSSW2" "PSSW3" "PSSW4" "PSSW5"
## [17] "PSSW6" "PSSW7" "PSSS1" "PSSS2"
## [21] "PSSS3" "PSSS4" "PSSS5" "PSSS6"
## [25] "PSSS7" "PSA1" "PSA2" "PSA3"
## [29] "PSA4" "PSSB5" "PSSB6" "PSSB7"
## [33] "PSSB8" "PSQ1" "PSQ2" "PSQ3"
## [37] "PSQ4" "PSQ5" "PSQ6" "PSQ7"
## [41] "PSQ8" "PSQ9" "PSQ10" "PSQ11"
## [45] "PSQ12" "PSQ13" "PSQ14" "PSQ15"
## [49] "PSQ16" "PSQ17" "PSQ18" "SAT1"
## [53] "SAT2" "SAT3" "LIN1" "LIN2"
## [57] "LIN3" "LIN7" "LIN4" "LIN5"
## [61] "LIN6" "IMA1" "IMA2" "IMA3"
## [65] "IMA4" "IMA5" "PHB1" "PHB2"
## [69] "PHB5" "PHB3" "PHB4" "PGV1"
## [73] "PGV2" "PGV3" "PGV4" "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(SEM1)
## [1] 859 112
2. Desscriptive statistic
# 2.1. Subset Data SEM1 (6 constructs and 28 items)
SEM1 <- SEM1[, c(2, 3, 5, 6, 7, 8, 9, 10, 11, 26, 27, 28, 29, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112)]
head(SEM1)
## MCCar MCMotor AGE CITY FRE TripPurpose Departure TimeUseonBus TravelTime PSA1
## 1 0 0 1 2 1 2 0 4 3.00 6
## 2 0 0 1 2 2 4 0 4 2.00 3
## 3 0 0 1 2 1 2 1 4 0.17 2
## 4 0 0 1 2 1 2 1 1 4.00 5
## 5 0 0 1 2 1 2 1 4 2.00 2
## 6 0 1 1 2 1 2 1 6 2.00 2
## PSA2 PSA3 PSA4 LIN1 LIN2 LIN3 LIN7 LIN4 LIN5 LIN6 IMA1 IMA2 IMA3 IMA4 IMA5
## 1 6 4 6 4 6 5 7 6 6 6 6 6 6 4 6
## 2 3 4 4 4 5 4 4 4 4 5 4 5 6 5 4
## 3 6 6 4 2 6 6 4 4 2 2 4 2 5 2 2
## 4 6 6 5 5 5 5 5 5 5 5 5 5 5 5 5
## 5 2 5 5 4 5 5 4 4 4 6 5 4 5 4 5
## 6 5 4 4 4 3 2 5 5 6 6 4 3 2 2 4
## PHB1 PHB2 PHB5 PHB3 PHB4 PGV1 PGV2 PGV3 PGV4 PVA1 PVA2 PVA3 EC_Stop WC_Stop
## 1 6 7 6 7 7 4 4 4 4 6 6 6 0 1
## 2 3 4 3 4 6 5 6 6 4 5 5 3 0 0
## 3 5 2 6 6 6 6 5 6 6 6 2 4 0 0
## 4 5 5 5 5 5 5 5 5 5 5 5 5 0 1
## 5 5 6 6 6 5 6 6 6 6 6 2 3 0 1
## 6 4 6 7 6 4 7 7 5 2 6 5 5 0 1
## EC_Bus WC_Bus Gender MarriedStatus Occupation Education Income
## 1 0 1 0 1 1 2 1
## 2 1 0 0 1 1 2 1
## 3 0 0 1 1 1 2 1
## 4 0 1 1 1 1 2 1
## 5 0 1 1 1 1 2 1
## 6 0 1 0 1 1 3 1
names(SEM1)
## [1] "MCCar" "MCMotor" "AGE" "CITY"
## [5] "FRE" "TripPurpose" "Departure" "TimeUseonBus"
## [9] "TravelTime" "PSA1" "PSA2" "PSA3"
## [13] "PSA4" "LIN1" "LIN2" "LIN3"
## [17] "LIN7" "LIN4" "LIN5" "LIN6"
## [21] "IMA1" "IMA2" "IMA3" "IMA4"
## [25] "IMA5" "PHB1" "PHB2" "PHB5"
## [29] "PHB3" "PHB4" "PGV1" "PGV2"
## [33] "PGV3" "PGV4" "PVA1" "PVA2"
## [37] "PVA3" "EC_Stop" "WC_Stop" "EC_Bus"
## [41] "WC_Bus" "Gender" "MarriedStatus" "Occupation"
## [45] "Education" "Income"
dim(SEM1)
## [1] 859 46
# Data coding
str(SEM1)
## 'data.frame': 859 obs. of 46 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 ...
## $ PSA1 : int 6 3 2 5 2 2 1 6 2 4 ...
## $ PSA2 : int 6 3 6 6 2 5 1 6 4 4 ...
## $ PSA3 : int 4 4 6 6 5 4 5 6 4 7 ...
## $ PSA4 : int 6 4 4 5 5 4 1 6 4 4 ...
## $ LIN1 : int 4 4 2 5 4 4 2 6 6 6 ...
## $ LIN2 : int 6 5 6 5 5 3 1 6 5 6 ...
## $ LIN3 : int 5 4 6 5 5 2 1 6 6 6 ...
## $ LIN7 : int 7 4 4 5 4 5 2 7 5 6 ...
## $ LIN4 : int 6 4 4 5 4 5 2 7 5 4 ...
## $ LIN5 : int 6 4 2 5 4 6 1 7 5 6 ...
## $ LIN6 : 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 ...
## $ PHB5 : int 6 3 6 5 6 7 1 4 3 7 ...
## $ PHB3 : int 7 4 6 5 6 6 4 6 7 7 ...
## $ PHB4 : int 7 6 6 5 5 4 4 6 7 7 ...
## $ PGV1 : int 4 5 6 5 6 7 4 6 7 7 ...
## $ PGV2 : int 4 6 5 5 6 7 2 7 7 7 ...
## $ PGV3 : int 4 6 6 5 6 5 2 6 6 7 ...
## $ PGV4 : int 4 4 6 5 6 2 2 6 6 7 ...
## $ PVA1 : int 6 5 6 5 6 6 6 6 6 6 ...
## $ PVA2 : int 6 5 2 5 2 5 4 5 4 6 ...
## $ PVA3 : int 6 3 4 5 3 5 5 6 5 6 ...
## $ EC_Stop : int 0 0 0 0 0 0 0 0 0 0 ...
## $ WC_Stop : int 1 0 0 1 1 1 0 0 1 0 ...
## $ EC_Bus : int 0 1 0 0 0 0 0 0 0 0 ...
## $ WC_Bus : int 1 0 0 1 1 1 0 0 1 0 ...
## $ Gender : int 0 0 1 1 1 0 0 0 0 0 ...
## $ MarriedStatus: int 1 1 1 1 1 1 1 0 1 1 ...
## $ Occupation : int 1 1 1 1 1 1 1 2 1 1 ...
## $ Education : int 2 2 2 2 2 3 5 1 2 3 ...
## $ Income : int 1 1 1 1 1 1 1 1 1 1 ...
attach(SEM1)
SEM1 = within(SEM1, {
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(SEM1)
## 'data.frame': 859 obs. of 46 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 ...
## $ PSA1 : int 6 3 2 5 2 2 1 6 2 4 ...
## $ PSA2 : int 6 3 6 6 2 5 1 6 4 4 ...
## $ PSA3 : int 4 4 6 6 5 4 5 6 4 7 ...
## $ PSA4 : int 6 4 4 5 5 4 1 6 4 4 ...
## $ LIN1 : int 4 4 2 5 4 4 2 6 6 6 ...
## $ LIN2 : int 6 5 6 5 5 3 1 6 5 6 ...
## $ LIN3 : int 5 4 6 5 5 2 1 6 6 6 ...
## $ LIN7 : int 7 4 4 5 4 5 2 7 5 6 ...
## $ LIN4 : int 6 4 4 5 4 5 2 7 5 4 ...
## $ LIN5 : int 6 4 2 5 4 6 1 7 5 6 ...
## $ LIN6 : 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 ...
## $ PHB5 : int 6 3 6 5 6 7 1 4 3 7 ...
## $ PHB3 : int 7 4 6 5 6 6 4 6 7 7 ...
## $ PHB4 : int 7 6 6 5 5 4 4 6 7 7 ...
## $ PGV1 : int 4 5 6 5 6 7 4 6 7 7 ...
## $ PGV2 : int 4 6 5 5 6 7 2 7 7 7 ...
## $ PGV3 : int 4 6 6 5 6 5 2 6 6 7 ...
## $ PGV4 : int 4 4 6 5 6 2 2 6 6 7 ...
## $ PVA1 : int 6 5 6 5 6 6 6 6 6 6 ...
## $ PVA2 : int 6 5 2 5 2 5 4 5 4 6 ...
## $ PVA3 : int 6 3 4 5 3 5 5 6 5 6 ...
## $ EC_Stop : Factor w/ 2 levels "Never","Ever": 1 1 1 1 1 1 1 1 1 1 ...
## $ WC_Stop : Factor w/ 2 levels "Never","Ever": 2 1 1 2 2 2 1 1 2 1 ...
## $ EC_Bus : Factor w/ 2 levels "Never","Ever": 1 2 1 1 1 1 1 1 1 1 ...
## $ WC_Bus : Factor w/ 2 levels "Never","Ever": 2 1 1 2 2 2 1 1 2 1 ...
## $ Gender : Factor w/ 2 levels "Female","Male": 1 1 2 2 2 1 1 1 1 1 ...
## $ MarriedStatus: Factor w/ 2 levels "Married","Single": 2 2 2 2 2 2 2 1 2 2 ...
## $ Occupation : Factor w/ 7 levels "Students/Pupils",..: 1 1 1 1 1 1 1 2 1 1 ...
## $ Education : Factor w/ 5 levels "Secondary.school",..: 2 2 2 2 2 3 5 1 2 3 ...
## $ Income : Factor w/ 4 levels "<5millions","5-10millions",..: 1 1 1 1 1 1 1 1 1 1 ...
dim(SEM1)
## [1] 859 46
# 2.2. Descritive Table
library(tableone)
require(tableone)
library(magrittr)
summary(SEM1)
## MCCar MCMotor AGE CITY FRE
## No :839 No :693 16-25:417 DaNang :404 >=3 days/week :498
## Yes: 20 Yes:166 26-35:170 HoChiMinh:455 2days/month-2days/week:167
## 36-45:103 2days/year-1day/month : 98
## 46-55: 75 <2 days/year : 96
## >55 : 94
##
##
## TripPurpose Departure TimeUseonBus TravelTime
## Working :303 Normal :215 Using.telephone:197 Min. : 0.000
## Studying :297 Peak-Hour:644 Reading : 52 1st Qu.: 0.500
## Shopping : 60 Listening :136 Median : 1.000
## Entertaining: 95 Nothing :420 Mean : 1.295
## Others :104 Talking : 33 3rd Qu.: 2.000
## Others : 21 Max. :20.000
##
## PSA1 PSA2 PSA3 PSA4
## Min. :1.000 Min. :1.000 Min. :1.000 Min. :1.000
## 1st Qu.:3.000 1st Qu.:4.000 1st Qu.:5.000 1st Qu.:4.000
## Median :5.000 Median :6.000 Median :6.000 Median :5.000
## Mean :4.622 Mean :5.073 Mean :5.495 Mean :4.808
## 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
##
## LIN1 LIN2 LIN3 LIN7
## 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.489 Mean :5.517 Mean :5.604 Mean :5.334
## 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
##
## LIN4 LIN5 LIN6 IMA1 IMA2
## Min. :1.000 Min. :1.000 Min. :1.000 Min. :1.00 Min. :1.000
## 1st Qu.:5.000 1st Qu.:4.000 1st Qu.:5.000 1st Qu.:5.00 1st Qu.:5.000
## Median :6.000 Median :5.000 Median :6.000 Median :5.00 Median :6.000
## Mean :5.399 Mean :5.094 Mean :5.633 Mean :5.21 Mean :5.222
## 3rd Qu.:6.000 3rd Qu.:6.000 3rd Qu.:6.000 3rd Qu.:6.00 3rd Qu.:6.000
## Max. :7.000 Max. :7.000 Max. :7.000 Max. :7.00 Max. :7.000
##
## IMA3 IMA4 IMA5 PHB1 PHB2
## Min. :1.000 Min. :1.000 Min. :1.000 Min. :1.000 Min. :1.0
## 1st Qu.:5.000 1st Qu.:5.000 1st Qu.:5.000 1st Qu.:5.000 1st Qu.:5.0
## Median :6.000 Median :6.000 Median :6.000 Median :6.000 Median :6.0
## Mean :5.366 Mean :5.377 Mean :5.416 Mean :5.293 Mean :5.6
## 3rd Qu.:6.000 3rd Qu.:6.000 3rd Qu.:6.000 3rd Qu.:6.000 3rd Qu.:6.0
## Max. :7.000 Max. :7.000 Max. :7.000 Max. :7.000 Max. :7.0
##
## PHB5 PHB3 PHB4 PGV1 PGV2
## Min. :1.000 Min. :1.000 Min. :1.000 Min. :1.00 Min. :1.000
## 1st Qu.:5.000 1st Qu.:5.000 1st Qu.:6.000 1st Qu.:5.00 1st Qu.:5.000
## Median :6.000 Median :6.000 Median :6.000 Median :6.00 Median :6.000
## Mean :5.451 Mean :5.863 Mean :5.799 Mean :5.75 Mean :5.589
## 3rd Qu.:6.000 3rd Qu.:7.000 3rd Qu.:7.000 3rd Qu.:7.00 3rd Qu.:6.000
## Max. :7.000 Max. :7.000 Max. :7.000 Max. :7.00 Max. :7.000
##
## PGV3 PGV4 PVA1 PVA2
## 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.547 Mean :5.497 Mean :5.845 Mean :5.438
## 3rd Qu.:6.000 3rd Qu.:6.000 3rd Qu.:7.000 3rd Qu.:6.000
## Max. :7.000 Max. :7.000 Max. :7.000 Max. :7.000
##
## PVA3 EC_Stop WC_Stop EC_Bus WC_Bus Gender
## Min. :1.000 Never:821 Never:735 Never:816 Never:741 Female:505
## 1st Qu.:5.000 Ever : 38 Ever :124 Ever : 43 Ever :118 Male :354
## Median :6.000
## Mean :5.726
## 3rd Qu.:6.000
## Max. :7.000
##
## MarriedStatus Occupation Education Income
## Married:332 Students/Pupils:362 Secondary.school: 59 <5millions :455
## Single :527 Full.time.job :305 Undergraduate :276 5-10millions :250
## Part.time.job : 66 High.school :361 10-15millions:118
## Retirement : 46 Postgraduate :107 >15millions : 36
## No.job : 3 Others : 56
## Housewife : 52
## Others : 25
library(table1)
##
## Attaching package: 'table1'
## The following objects are masked from 'package:base':
##
## units, units<-
Tab1_SEM1 <- table1(~ PSA1 + PSA2 + PSA3 + PSA4 + LIN1 + LIN2 + LIN3 + LIN7 + LIN4 + LIN5 + LIN6 + IMA1 + IMA2 + IMA3 + IMA4 + IMA5 + PHB1 + PHB2 + PHB5 + PHB3 + PHB4 + PGV1 + PGV2 + PGV3 + PGV4 + PVA1 + PVA2 + PVA3 + EC_Stop + WC_Stop + EC_Bus + WC_Bus + Gender + MarriedStatus + Occupation + Education + Income + MCCar + MCMotor + AGE + CITY + FRE + TripPurpose + Departure + TimeUseonBus + TravelTime| CITY , data = SEM1)
Tab1_SEM1
| DaNang (N=404) |
HoChiMinh (N=455) |
Overall (N=859) |
|
|---|---|---|---|
| PSA1 | |||
| Mean (SD) | 5.56 (1.25) | 3.79 (1.91) | 4.62 (1.86) |
| Median [Min, Max] | 6.00 [1.00, 7.00] | 4.00 [1.00, 7.00] | 5.00 [1.00, 7.00] |
| PSA2 | |||
| Mean (SD) | 5.60 (1.22) | 4.60 (1.77) | 5.07 (1.61) |
| Median [Min, Max] | 6.00 [1.00, 7.00] | 5.00 [1.00, 7.00] | 6.00 [1.00, 7.00] |
| PSA3 | |||
| Mean (SD) | 5.75 (1.03) | 5.27 (1.38) | 5.49 (1.25) |
| Median [Min, Max] | 6.00 [1.00, 7.00] | 6.00 [1.00, 7.00] | 6.00 [1.00, 7.00] |
| PSA4 | |||
| Mean (SD) | 5.38 (1.24) | 4.30 (1.71) | 4.81 (1.60) |
| Median [Min, Max] | 6.00 [1.00, 7.00] | 4.00 [1.00, 7.00] | 5.00 [1.00, 7.00] |
| LIN1 | |||
| Mean (SD) | 5.76 (0.883) | 5.25 (1.25) | 5.49 (1.12) |
| Median [Min, Max] | 6.00 [2.00, 7.00] | 6.00 [1.00, 7.00] | 6.00 [1.00, 7.00] |
| LIN2 | |||
| Mean (SD) | 5.80 (0.864) | 5.27 (1.32) | 5.52 (1.16) |
| Median [Min, Max] | 6.00 [2.00, 7.00] | 6.00 [1.00, 7.00] | 6.00 [1.00, 7.00] |
| LIN3 | |||
| Mean (SD) | 5.83 (0.880) | 5.40 (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] |
| LIN7 | |||
| Mean (SD) | 5.57 (1.01) | 5.13 (1.38) | 5.33 (1.24) |
| Median [Min, Max] | 6.00 [3.00, 7.00] | 6.00 [1.00, 7.00] | 6.00 [1.00, 7.00] |
| LIN4 | |||
| Mean (SD) | 5.67 (0.980) | 5.16 (1.40) | 5.40 (1.24) |
| Median [Min, Max] | 6.00 [2.00, 7.00] | 6.00 [1.00, 7.00] | 6.00 [1.00, 7.00] |
| LIN5 | |||
| Mean (SD) | 5.37 (1.31) | 4.85 (1.60) | 5.09 (1.49) |
| Median [Min, Max] | 6.00 [1.00, 7.00] | 5.00 [1.00, 7.00] | 5.00 [1.00, 7.00] |
| LIN6 | |||
| Mean (SD) | 5.93 (0.871) | 5.37 (1.40) | 5.63 (1.21) |
| Median [Min, Max] | 6.00 [3.00, 7.00] | 6.00 [1.00, 7.00] | 6.00 [1.00, 7.00] |
| IMA1 | |||
| Mean (SD) | 5.36 (0.982) | 5.08 (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.53 (0.867) | 4.95 (1.35) | 5.22 (1.18) |
| Median [Min, Max] | 6.00 [3.00, 7.00] | 5.00 [1.00, 7.00] | 6.00 [1.00, 7.00] |
| IMA3 | |||
| Mean (SD) | 5.63 (0.840) | 5.13 (1.30) | 5.37 (1.13) |
| Median [Min, Max] | 6.00 [3.00, 7.00] | 5.00 [1.00, 7.00] | 6.00 [1.00, 7.00] |
| IMA4 | |||
| Mean (SD) | 5.71 (0.839) | 5.08 (1.33) | 5.38 (1.17) |
| Median [Min, Max] | 6.00 [3.00, 7.00] | 5.00 [1.00, 7.00] | 6.00 [1.00, 7.00] |
| IMA5 | |||
| Mean (SD) | 5.74 (0.810) | 5.13 (1.28) | 5.42 (1.13) |
| Median [Min, Max] | 6.00 [3.00, 7.00] | 5.00 [1.00, 7.00] | 6.00 [1.00, 7.00] |
| PHB1 | |||
| Mean (SD) | 5.43 (1.07) | 5.17 (1.55) | 5.29 (1.35) |
| 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.83 (0.984) | 5.39 (1.47) | 5.60 (1.28) |
| Median [Min, Max] | 6.00 [2.00, 7.00] | 6.00 [1.00, 7.00] | 6.00 [1.00, 7.00] |
| PHB5 | |||
| Mean (SD) | 5.49 (1.16) | 5.42 (1.39) | 5.45 (1.29) |
| Median [Min, Max] | 6.00 [2.00, 7.00] | 6.00 [1.00, 7.00] | 6.00 [1.00, 7.00] |
| PHB3 | |||
| Mean (SD) | 6.07 (0.844) | 5.68 (1.36) | 5.86 (1.16) |
| Median [Min, Max] | 6.00 [3.00, 7.00] | 6.00 [1.00, 7.00] | 6.00 [1.00, 7.00] |
| PHB4 | |||
| Mean (SD) | 6.05 (0.813) | 5.58 (1.48) | 5.80 (1.23) |
| Median [Min, Max] | 6.00 [4.00, 7.00] | 6.00 [1.00, 7.00] | 6.00 [1.00, 7.00] |
| PGV1 | |||
| Mean (SD) | 5.97 (0.861) | 5.56 (1.58) | 5.75 (1.31) |
| Median [Min, Max] | 6.00 [1.00, 7.00] | 6.00 [1.00, 7.00] | 6.00 [1.00, 7.00] |
| PGV2 | |||
| Mean (SD) | 5.82 (0.947) | 5.38 (1.61) | 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] |
| PGV3 | |||
| Mean (SD) | 5.76 (1.01) | 5.35 (1.61) | 5.55 (1.37) |
| Median [Min, Max] | 6.00 [2.00, 7.00] | 6.00 [1.00, 7.00] | 6.00 [1.00, 7.00] |
| PGV4 | |||
| Mean (SD) | 5.74 (1.00) | 5.29 (1.58) | 5.50 (1.36) |
| Median [Min, Max] | 6.00 [2.00, 7.00] | 6.00 [1.00, 7.00] | 6.00 [1.00, 7.00] |
| PVA1 | |||
| Mean (SD) | 5.95 (0.912) | 5.75 (1.20) | 5.85 (1.08) |
| Median [Min, Max] | 6.00 [2.00, 7.00] | 6.00 [1.00, 7.00] | 6.00 [1.00, 7.00] |
| PVA2 | |||
| Mean (SD) | 5.54 (1.17) | 5.34 (1.31) | 5.44 (1.25) |
| Median [Min, Max] | 6.00 [2.00, 7.00] | 6.00 [1.00, 7.00] | 6.00 [1.00, 7.00] |
| PVA3 | |||
| Mean (SD) | 5.92 (0.809) | 5.55 (1.25) | 5.73 (1.08) |
| Median [Min, Max] | 6.00 [2.00, 7.00] | 6.00 [1.00, 7.00] | 6.00 [1.00, 7.00] |
| EC_Stop | |||
| Never | 400 (99.0%) | 421 (92.5%) | 821 (95.6%) |
| Ever | 4 (1.0%) | 34 (7.5%) | 38 (4.4%) |
| WC_Stop | |||
| Never | 382 (94.6%) | 353 (77.6%) | 735 (85.6%) |
| Ever | 22 (5.4%) | 102 (22.4%) | 124 (14.4%) |
| EC_Bus | |||
| Never | 401 (99.3%) | 415 (91.2%) | 816 (95.0%) |
| Ever | 3 (0.7%) | 40 (8.8%) | 43 (5.0%) |
| WC_Bus | |||
| Never | 387 (95.8%) | 354 (77.8%) | 741 (86.3%) |
| Ever | 17 (4.2%) | 101 (22.2%) | 118 (13.7%) |
| Gender | |||
| Female | 229 (56.7%) | 276 (60.7%) | 505 (58.8%) |
| Male | 175 (43.3%) | 179 (39.3%) | 354 (41.2%) |
| MarriedStatus | |||
| Married | 147 (36.4%) | 185 (40.7%) | 332 (38.6%) |
| Single | 257 (63.6%) | 270 (59.3%) | 527 (61.4%) |
| Occupation | |||
| Students/Pupils | 199 (49.3%) | 163 (35.8%) | 362 (42.1%) |
| Full.time.job | 113 (28.0%) | 192 (42.2%) | 305 (35.5%) |
| Part.time.job | 25 (6.2%) | 41 (9.0%) | 66 (7.7%) |
| Retirement | 33 (8.2%) | 13 (2.9%) | 46 (5.4%) |
| No.job | 2 (0.5%) | 1 (0.2%) | 3 (0.3%) |
| Housewife | 27 (6.7%) | 25 (5.5%) | 52 (6.1%) |
| Others | 5 (1.2%) | 20 (4.4%) | 25 (2.9%) |
| Education | |||
| Secondary.school | 30 (7.4%) | 29 (6.4%) | 59 (6.9%) |
| Undergraduate | 125 (30.9%) | 151 (33.2%) | 276 (32.1%) |
| High.school | 167 (41.3%) | 194 (42.6%) | 361 (42.0%) |
| Postgraduate | 63 (15.6%) | 44 (9.7%) | 107 (12.5%) |
| Others | 19 (4.7%) | 37 (8.1%) | 56 (6.5%) |
| Income | |||
| <5millions | 266 (65.8%) | 189 (41.5%) | 455 (53.0%) |
| 5-10millions | 82 (20.3%) | 168 (36.9%) | 250 (29.1%) |
| 10-15millions | 48 (11.9%) | 70 (15.4%) | 118 (13.7%) |
| >15millions | 8 (2.0%) | 28 (6.2%) | 36 (4.2%) |
| MCCar | |||
| No | 404 (100%) | 435 (95.6%) | 839 (97.7%) |
| Yes | 0 (0%) | 20 (4.4%) | 20 (2.3%) |
| MCMotor | |||
| No | 403 (99.8%) | 290 (63.7%) | 693 (80.7%) |
| Yes | 1 (0.2%) | 165 (36.3%) | 166 (19.3%) |
| AGE | |||
| 16-25 | 213 (52.7%) | 204 (44.8%) | 417 (48.5%) |
| 26-35 | 74 (18.3%) | 96 (21.1%) | 170 (19.8%) |
| 36-45 | 36 (8.9%) | 67 (14.7%) | 103 (12.0%) |
| 46-55 | 34 (8.4%) | 41 (9.0%) | 75 (8.7%) |
| >55 | 47 (11.6%) | 47 (10.3%) | 94 (10.9%) |
| CITY | |||
| DaNang | 404 (100%) | 0 (0%) | 404 (47.0%) |
| HoChiMinh | 0 (0%) | 455 (100%) | 455 (53.0%) |
| FRE | |||
| >=3 days/week | 259 (64.1%) | 239 (52.5%) | 498 (58.0%) |
| 2days/month-2days/week | 83 (20.5%) | 84 (18.5%) | 167 (19.4%) |
| 2days/year-1day/month | 27 (6.7%) | 71 (15.6%) | 98 (11.4%) |
| <2 days/year | 35 (8.7%) | 61 (13.4%) | 96 (11.2%) |
| TripPurpose | |||
| Working | 112 (27.7%) | 191 (42.0%) | 303 (35.3%) |
| Studying | 161 (39.9%) | 136 (29.9%) | 297 (34.6%) |
| Shopping | 46 (11.4%) | 14 (3.1%) | 60 (7.0%) |
| Entertaining | 47 (11.6%) | 48 (10.5%) | 95 (11.1%) |
| Others | 38 (9.4%) | 66 (14.5%) | 104 (12.1%) |
| Departure | |||
| Normal | 141 (34.9%) | 74 (16.3%) | 215 (25.0%) |
| Peak-Hour | 263 (65.1%) | 381 (83.7%) | 644 (75.0%) |
| TimeUseonBus | |||
| Using.telephone | 103 (25.5%) | 94 (20.7%) | 197 (22.9%) |
| Reading | 21 (5.2%) | 31 (6.8%) | 52 (6.1%) |
| Listening | 50 (12.4%) | 86 (18.9%) | 136 (15.8%) |
| Nothing | 201 (49.8%) | 219 (48.1%) | 420 (48.9%) |
| Talking | 24 (5.9%) | 9 (2.0%) | 33 (3.8%) |
| Others | 5 (1.2%) | 16 (3.5%) | 21 (2.4%) |
| TravelTime | |||
| Mean (SD) | 1.12 (0.838) | 1.45 (1.85) | 1.29 (1.47) |
| Median [Min, Max] | 1.00 [0, 6.00] | 1.00 [0, 20.0] | 1.00 [0, 20.0] |
# Create data for Likert graph by BS (remove ID and TM =7-Bus)
head(SEM1)
## 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 PSA1 PSA2 PSA3 PSA4 LIN1 LIN2 LIN3 LIN7 LIN4 LIN5
## 1 Nothing 3.00 6 6 4 6 4 6 5 7 6 6
## 2 Nothing 2.00 3 3 4 4 4 5 4 4 4 4
## 3 Nothing 0.17 2 6 6 4 2 6 6 4 4 2
## 4 Using.telephone 4.00 5 6 6 5 5 5 5 5 5 5
## 5 Nothing 2.00 2 2 5 5 4 5 5 4 4 4
## 6 Others 2.00 2 5 4 4 4 3 2 5 5 6
## LIN6 IMA1 IMA2 IMA3 IMA4 IMA5 PHB1 PHB2 PHB5 PHB3 PHB4 PGV1 PGV2 PGV3 PGV4
## 1 6 6 6 6 4 6 6 7 6 7 7 4 4 4 4
## 2 5 4 5 6 5 4 3 4 3 4 6 5 6 6 4
## 3 2 4 2 5 2 2 5 2 6 6 6 6 5 6 6
## 4 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5
## 5 6 5 4 5 4 5 5 6 6 6 5 6 6 6 6
## 6 6 4 3 2 2 4 4 6 7 6 4 7 7 5 2
## PVA1 PVA2 PVA3 EC_Stop WC_Stop EC_Bus WC_Bus Gender MarriedStatus
## 1 6 6 6 Never Ever Never Ever Female Single
## 2 5 5 3 Never Never Ever Never Female Single
## 3 6 2 4 Never Never Never Never Male Single
## 4 5 5 5 Never Ever Never Ever Male Single
## 5 6 2 3 Never Ever Never Ever Male Single
## 6 6 5 5 Never Ever Never Ever Female Single
## Occupation Education Income
## 1 Students/Pupils Undergraduate <5millions
## 2 Students/Pupils Undergraduate <5millions
## 3 Students/Pupils Undergraduate <5millions
## 4 Students/Pupils Undergraduate <5millions
## 5 Students/Pupils Undergraduate <5millions
## 6 Students/Pupils High.school <5millions
str(SEM1)
## 'data.frame': 859 obs. of 46 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 ...
## $ PSA1 : int 6 3 2 5 2 2 1 6 2 4 ...
## $ PSA2 : int 6 3 6 6 2 5 1 6 4 4 ...
## $ PSA3 : int 4 4 6 6 5 4 5 6 4 7 ...
## $ PSA4 : int 6 4 4 5 5 4 1 6 4 4 ...
## $ LIN1 : int 4 4 2 5 4 4 2 6 6 6 ...
## $ LIN2 : int 6 5 6 5 5 3 1 6 5 6 ...
## $ LIN3 : int 5 4 6 5 5 2 1 6 6 6 ...
## $ LIN7 : int 7 4 4 5 4 5 2 7 5 6 ...
## $ LIN4 : int 6 4 4 5 4 5 2 7 5 4 ...
## $ LIN5 : int 6 4 2 5 4 6 1 7 5 6 ...
## $ LIN6 : 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 ...
## $ PHB5 : int 6 3 6 5 6 7 1 4 3 7 ...
## $ PHB3 : int 7 4 6 5 6 6 4 6 7 7 ...
## $ PHB4 : int 7 6 6 5 5 4 4 6 7 7 ...
## $ PGV1 : int 4 5 6 5 6 7 4 6 7 7 ...
## $ PGV2 : int 4 6 5 5 6 7 2 7 7 7 ...
## $ PGV3 : int 4 6 6 5 6 5 2 6 6 7 ...
## $ PGV4 : int 4 4 6 5 6 2 2 6 6 7 ...
## $ PVA1 : int 6 5 6 5 6 6 6 6 6 6 ...
## $ PVA2 : int 6 5 2 5 2 5 4 5 4 6 ...
## $ PVA3 : int 6 3 4 5 3 5 5 6 5 6 ...
## $ EC_Stop : Factor w/ 2 levels "Never","Ever": 1 1 1 1 1 1 1 1 1 1 ...
## $ WC_Stop : Factor w/ 2 levels "Never","Ever": 2 1 1 2 2 2 1 1 2 1 ...
## $ EC_Bus : Factor w/ 2 levels "Never","Ever": 1 2 1 1 1 1 1 1 1 1 ...
## $ WC_Bus : Factor w/ 2 levels "Never","Ever": 2 1 1 2 2 2 1 1 2 1 ...
## $ Gender : Factor w/ 2 levels "Female","Male": 1 1 2 2 2 1 1 1 1 1 ...
## $ MarriedStatus: Factor w/ 2 levels "Married","Single": 2 2 2 2 2 2 2 1 2 2 ...
## $ Occupation : Factor w/ 7 levels "Students/Pupils",..: 1 1 1 1 1 1 1 2 1 1 ...
## $ Education : Factor w/ 5 levels "Secondary.school",..: 2 2 2 2 2 3 5 1 2 3 ...
## $ Income : Factor w/ 4 levels "<5millions","5-10millions",..: 1 1 1 1 1 1 1 1 1 1 ...
dim(SEM1)
## [1] 859 46
SEM1_likert = SEM1[,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)] # BPE gom cac bien tu 10-37
head(SEM1_likert)
## AGE CITY PSA1 PSA2 PSA3 PSA4 LIN1 LIN2 LIN3 LIN7 LIN4 LIN5 LIN6 IMA1
## 1 16-25 HoChiMinh 6 6 4 6 4 6 5 7 6 6 6 6
## 2 16-25 HoChiMinh 3 3 4 4 4 5 4 4 4 4 5 4
## 3 16-25 HoChiMinh 2 6 6 4 2 6 6 4 4 2 2 4
## 4 16-25 HoChiMinh 5 6 6 5 5 5 5 5 5 5 5 5
## 5 16-25 HoChiMinh 2 2 5 5 4 5 5 4 4 4 6 5
## 6 16-25 HoChiMinh 2 5 4 4 4 3 2 5 5 6 6 4
## IMA2 IMA3 IMA4 IMA5 PHB1 PHB2 PHB5 PHB3 PHB4 PGV1 PGV2 PGV3 PGV4 PVA1 PVA2
## 1 6 6 4 6 6 7 6 7 7 4 4 4 4 6 6
## 2 5 6 5 4 3 4 3 4 6 5 6 6 4 5 5
## 3 2 5 2 2 5 2 6 6 6 6 5 6 6 6 2
## 4 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5
## 5 4 5 4 5 5 6 6 6 5 6 6 6 6 6 2
## 6 3 2 2 4 4 6 7 6 4 7 7 5 2 6 5
## PVA3 EC_Stop WC_Stop EC_Bus WC_Bus Gender
## 1 6 Never Ever Never Ever Female
## 2 3 Never Never Ever Never Female
## 3 4 Never Never Never Never Male
## 4 5 Never Ever Never Ever Male
## 5 3 Never Ever Never Ever Male
## 6 5 Never Ever Never Ever Female
str(SEM1_likert)
## 'data.frame': 859 obs. of 35 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 ...
## $ PSA1 : int 6 3 2 5 2 2 1 6 2 4 ...
## $ PSA2 : int 6 3 6 6 2 5 1 6 4 4 ...
## $ PSA3 : int 4 4 6 6 5 4 5 6 4 7 ...
## $ PSA4 : int 6 4 4 5 5 4 1 6 4 4 ...
## $ LIN1 : int 4 4 2 5 4 4 2 6 6 6 ...
## $ LIN2 : int 6 5 6 5 5 3 1 6 5 6 ...
## $ LIN3 : int 5 4 6 5 5 2 1 6 6 6 ...
## $ LIN7 : int 7 4 4 5 4 5 2 7 5 6 ...
## $ LIN4 : int 6 4 4 5 4 5 2 7 5 4 ...
## $ LIN5 : int 6 4 2 5 4 6 1 7 5 6 ...
## $ LIN6 : 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 ...
## $ PHB5 : int 6 3 6 5 6 7 1 4 3 7 ...
## $ PHB3 : int 7 4 6 5 6 6 4 6 7 7 ...
## $ PHB4 : int 7 6 6 5 5 4 4 6 7 7 ...
## $ PGV1 : int 4 5 6 5 6 7 4 6 7 7 ...
## $ PGV2 : int 4 6 5 5 6 7 2 7 7 7 ...
## $ PGV3 : int 4 6 6 5 6 5 2 6 6 7 ...
## $ PGV4 : int 4 4 6 5 6 2 2 6 6 7 ...
## $ PVA1 : int 6 5 6 5 6 6 6 6 6 6 ...
## $ PVA2 : int 6 5 2 5 2 5 4 5 4 6 ...
## $ PVA3 : int 6 3 4 5 3 5 5 6 5 6 ...
## $ EC_Stop: Factor w/ 2 levels "Never","Ever": 1 1 1 1 1 1 1 1 1 1 ...
## $ WC_Stop: Factor w/ 2 levels "Never","Ever": 2 1 1 2 2 2 1 1 2 1 ...
## $ EC_Bus : Factor w/ 2 levels "Never","Ever": 1 2 1 1 1 1 1 1 1 1 ...
## $ WC_Bus : Factor w/ 2 levels "Never","Ever": 2 1 1 2 2 2 1 1 2 1 ...
## $ Gender : Factor w/ 2 levels "Female","Male": 1 1 2 2 2 1 1 1 1 1 ...
dim(SEM1_likert)
## [1] 859 35
## Creat dat_PSA1 - cot 3 cua SEM1_likert
dat_PSA1 <- SEM1_likert [, c(1,2,3,31, 32, 33, 34, 35)]
head(dat_PSA1)
## AGE CITY PSA1 EC_Stop WC_Stop EC_Bus WC_Bus Gender
## 1 16-25 HoChiMinh 6 Never Ever Never Ever Female
## 2 16-25 HoChiMinh 3 Never Never Ever Never Female
## 3 16-25 HoChiMinh 2 Never Never Never Never Male
## 4 16-25 HoChiMinh 5 Never Ever Never Ever Male
## 5 16-25 HoChiMinh 2 Never Ever Never Ever Male
## 6 16-25 HoChiMinh 2 Never Ever Never Ever Female
dim(dat_PSA1)
## [1] 859 8
size <- 859
dat_PSA1$BPE <- rep("PSA1", size = size) # Tạo biến mới BPE
names(dat_PSA1)[names(dat_PSA1) == "PSA1"] <- "Res" # Đổi tên biến BST thành Res
head(dat_PSA1)
## AGE CITY Res EC_Stop WC_Stop EC_Bus WC_Bus Gender BPE
## 1 16-25 HoChiMinh 6 Never Ever Never Ever Female PSA1
## 2 16-25 HoChiMinh 3 Never Never Ever Never Female PSA1
## 3 16-25 HoChiMinh 2 Never Never Never Never Male PSA1
## 4 16-25 HoChiMinh 5 Never Ever Never Ever Male PSA1
## 5 16-25 HoChiMinh 2 Never Ever Never Ever Male PSA1
## 6 16-25 HoChiMinh 2 Never Ever Never Ever Female PSA1
## Creat dat_PSA2 - cot 4 cua SEM1_likert
dat_PSA2 <- SEM1_likert [, c(1,2,4,31, 32, 33, 34, 35)]
head(dat_PSA2)
## AGE CITY PSA2 EC_Stop WC_Stop EC_Bus WC_Bus Gender
## 1 16-25 HoChiMinh 6 Never Ever Never Ever Female
## 2 16-25 HoChiMinh 3 Never Never Ever Never Female
## 3 16-25 HoChiMinh 6 Never Never Never Never Male
## 4 16-25 HoChiMinh 6 Never Ever Never Ever Male
## 5 16-25 HoChiMinh 2 Never Ever Never Ever Male
## 6 16-25 HoChiMinh 5 Never Ever Never Ever Female
dim(dat_PSA2)
## [1] 859 8
size <- 859
dat_PSA2$BPE <- rep("PSA2", size = size) # Tạo biến mới BPE
names(dat_PSA2)[names(dat_PSA2) == "PSA2"] <- "Res" # Đổi tên biến BST thành Res
head(dat_PSA2)
## AGE CITY Res EC_Stop WC_Stop EC_Bus WC_Bus Gender BPE
## 1 16-25 HoChiMinh 6 Never Ever Never Ever Female PSA2
## 2 16-25 HoChiMinh 3 Never Never Ever Never Female PSA2
## 3 16-25 HoChiMinh 6 Never Never Never Never Male PSA2
## 4 16-25 HoChiMinh 6 Never Ever Never Ever Male PSA2
## 5 16-25 HoChiMinh 2 Never Ever Never Ever Male PSA2
## 6 16-25 HoChiMinh 5 Never Ever Never Ever Female PSA2
## Creat dat_PSA3 - cot 5 cua SEN1_likert
dat_PSA3 <- SEM1_likert [, c(1,2,5,31, 32, 33, 34, 35)]
head(dat_PSA3)
## AGE CITY PSA3 EC_Stop WC_Stop EC_Bus WC_Bus Gender
## 1 16-25 HoChiMinh 4 Never Ever Never Ever Female
## 2 16-25 HoChiMinh 4 Never Never Ever Never Female
## 3 16-25 HoChiMinh 6 Never Never Never Never Male
## 4 16-25 HoChiMinh 6 Never Ever Never Ever Male
## 5 16-25 HoChiMinh 5 Never Ever Never Ever Male
## 6 16-25 HoChiMinh 4 Never Ever Never Ever Female
dim(dat_PSA3)
## [1] 859 8
size <- 859
dat_PSA3$BPE <- rep("PSA3", size = size) # Tạo biến mới BPE
names(dat_PSA3)[names(dat_PSA3) == "PSA3"] <- "Res" # Đổi tên biến BST thành Res
head(dat_PSA3)
## AGE CITY Res EC_Stop WC_Stop EC_Bus WC_Bus Gender BPE
## 1 16-25 HoChiMinh 4 Never Ever Never Ever Female PSA3
## 2 16-25 HoChiMinh 4 Never Never Ever Never Female PSA3
## 3 16-25 HoChiMinh 6 Never Never Never Never Male PSA3
## 4 16-25 HoChiMinh 6 Never Ever Never Ever Male PSA3
## 5 16-25 HoChiMinh 5 Never Ever Never Ever Male PSA3
## 6 16-25 HoChiMinh 4 Never Ever Never Ever Female PSA3
## Creat dat_PSA4 - cot 6 cua SEM1_likert
dat_PSA4 <- SEM1_likert [, c(1,2,6,31, 32, 33, 34, 35)]
head(dat_PSA4)
## AGE CITY PSA4 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_PSA4)
## [1] 859 8
size <- 859
dat_PSA4$BPE <- rep("PSA4", size = size) # Tạo biến mới BPE
names(dat_PSA4)[names(dat_PSA4) == "PSA4"] <- "Res" # Đổi tên biến BST thành Res
head(dat_PSA4)
## AGE CITY Res EC_Stop WC_Stop EC_Bus WC_Bus Gender BPE
## 1 16-25 HoChiMinh 6 Never Ever Never Ever Female PSA4
## 2 16-25 HoChiMinh 4 Never Never Ever Never Female PSA4
## 3 16-25 HoChiMinh 4 Never Never Never Never Male PSA4
## 4 16-25 HoChiMinh 5 Never Ever Never Ever Male PSA4
## 5 16-25 HoChiMinh 5 Never Ever Never Ever Male PSA4
## 6 16-25 HoChiMinh 4 Never Ever Never Ever Female PSA4
## Creat dat_LIN1 - cot 7 cua SEM1_likert
dat_LIN1 <- SEM1_likert [, c(1,2,7,31, 32, 33, 34, 35)]
head(dat_LIN1)
## AGE CITY LIN1 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_LIN1)
## [1] 859 8
size <- 859
dat_LIN1$BPE <- rep("LIN1", size = size) # Tạo biến mới BPE
names(dat_LIN1)[names(dat_LIN1) == "LIN1"] <- "Res" # Đổi tên biến BST thành Res
head(dat_LIN1)
## AGE CITY Res EC_Stop WC_Stop EC_Bus WC_Bus Gender BPE
## 1 16-25 HoChiMinh 4 Never Ever Never Ever Female LIN1
## 2 16-25 HoChiMinh 4 Never Never Ever Never Female LIN1
## 3 16-25 HoChiMinh 2 Never Never Never Never Male LIN1
## 4 16-25 HoChiMinh 5 Never Ever Never Ever Male LIN1
## 5 16-25 HoChiMinh 4 Never Ever Never Ever Male LIN1
## 6 16-25 HoChiMinh 4 Never Ever Never Ever Female LIN1
## Creat dat_LIN2 - cot 8 cua SEM1_likert
dat_LIN2 <- SEM1_likert [, c(1,2,8,31, 32, 33, 34, 35)]
head(dat_LIN2)
## AGE CITY LIN2 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_LIN2)
## [1] 859 8
size <- 859
dat_LIN2$BPE <- rep("LIN2", size = size) # Tạo biến mới BPE
names(dat_LIN2)[names(dat_LIN2) == "LIN2"] <- "Res" # Đổi tên biến BST thành Res
head(dat_LIN2)
## AGE CITY Res EC_Stop WC_Stop EC_Bus WC_Bus Gender BPE
## 1 16-25 HoChiMinh 6 Never Ever Never Ever Female LIN2
## 2 16-25 HoChiMinh 5 Never Never Ever Never Female LIN2
## 3 16-25 HoChiMinh 6 Never Never Never Never Male LIN2
## 4 16-25 HoChiMinh 5 Never Ever Never Ever Male LIN2
## 5 16-25 HoChiMinh 5 Never Ever Never Ever Male LIN2
## 6 16-25 HoChiMinh 3 Never Ever Never Ever Female LIN2
## Creat dat_LIN3 - cot 9 cua SEM1_likert
dat_LIN3 <- SEM1_likert [, c(1,2,9,31, 32, 33, 34, 35)]
head(dat_LIN3)
## AGE CITY LIN3 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_LIN3)
## [1] 859 8
size <- 859
dat_LIN3$BPE <- rep("LIN3", size = size) # Tạo biến mới BPE
names(dat_LIN3)[names(dat_LIN3) == "LIN3"] <- "Res" # Đổi tên biến BST thành Res
head(dat_LIN3)
## AGE CITY Res EC_Stop WC_Stop EC_Bus WC_Bus Gender BPE
## 1 16-25 HoChiMinh 5 Never Ever Never Ever Female LIN3
## 2 16-25 HoChiMinh 4 Never Never Ever Never Female LIN3
## 3 16-25 HoChiMinh 6 Never Never Never Never Male LIN3
## 4 16-25 HoChiMinh 5 Never Ever Never Ever Male LIN3
## 5 16-25 HoChiMinh 5 Never Ever Never Ever Male LIN3
## 6 16-25 HoChiMinh 2 Never Ever Never Ever Female LIN3
## Creat dat_LIN7 - cot 10 cua SEM1_likert
dat_LIN7 <- SEM1_likert [, c(1,2,10,31, 32, 33, 34, 35)]
head(dat_LIN7)
## AGE CITY LIN7 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_LIN7)
## [1] 859 8
size <- 859
dat_LIN7$BPE <- rep("LIN7", size = size) # Tạo biến mới BPE
names(dat_LIN7)[names(dat_LIN7) == "LIN7"] <- "Res" # Đổi tên biến BST thành Res
head(dat_LIN7)
## AGE CITY Res EC_Stop WC_Stop EC_Bus WC_Bus Gender BPE
## 1 16-25 HoChiMinh 7 Never Ever Never Ever Female LIN7
## 2 16-25 HoChiMinh 4 Never Never Ever Never Female LIN7
## 3 16-25 HoChiMinh 4 Never Never Never Never Male LIN7
## 4 16-25 HoChiMinh 5 Never Ever Never Ever Male LIN7
## 5 16-25 HoChiMinh 4 Never Ever Never Ever Male LIN7
## 6 16-25 HoChiMinh 5 Never Ever Never Ever Female LIN7
## Creat dat_LIN4 - cot 11 cua SEM1_likert
dat_LIN4 <- SEM1_likert [, c(1,2,11,31, 32, 33, 34, 35)]
head(dat_LIN4)
## AGE CITY LIN4 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_LIN4)
## [1] 859 8
size <- 859
dat_LIN4$BPE <- rep("LIN4", size = size) # Tạo biến mới BPE
names(dat_LIN4)[names(dat_LIN4) == "LIN4"] <- "Res" # Đổi tên biến BST thành Res
head(dat_LIN4)
## AGE CITY Res EC_Stop WC_Stop EC_Bus WC_Bus Gender BPE
## 1 16-25 HoChiMinh 6 Never Ever Never Ever Female LIN4
## 2 16-25 HoChiMinh 4 Never Never Ever Never Female LIN4
## 3 16-25 HoChiMinh 4 Never Never Never Never Male LIN4
## 4 16-25 HoChiMinh 5 Never Ever Never Ever Male LIN4
## 5 16-25 HoChiMinh 4 Never Ever Never Ever Male LIN4
## 6 16-25 HoChiMinh 5 Never Ever Never Ever Female LIN4
## Creat dat_LIN5 - cot 12 cua SEM1_likert
dat_LIN5 <- SEM1_likert [, c(1,2,12,31, 32, 33, 34, 35)]
head(dat_LIN5)
## AGE CITY LIN5 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_LIN5)
## [1] 859 8
size <- 859
dat_LIN5$BPE <- rep("LIN5", size = size) # Tạo biến mới BPE
names(dat_LIN5)[names(dat_LIN5) == "LIN5"] <- "Res" # Đổi tên biến BST thành Res
head(dat_LIN5)
## AGE CITY Res EC_Stop WC_Stop EC_Bus WC_Bus Gender BPE
## 1 16-25 HoChiMinh 6 Never Ever Never Ever Female LIN5
## 2 16-25 HoChiMinh 4 Never Never Ever Never Female LIN5
## 3 16-25 HoChiMinh 2 Never Never Never Never Male LIN5
## 4 16-25 HoChiMinh 5 Never Ever Never Ever Male LIN5
## 5 16-25 HoChiMinh 4 Never Ever Never Ever Male LIN5
## 6 16-25 HoChiMinh 6 Never Ever Never Ever Female LIN5
## Creat dat_LIN6 - cot 13 cua SEM1_likert
dat_LIN6 <- SEM1_likert [, c(1,2,13,31, 32, 33, 34, 35)]
head(dat_LIN6)
## AGE CITY LIN6 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_LIN6)
## [1] 859 8
size <- 859
dat_LIN6$BPE <- rep("LIN6", size = size) # Tạo biến mới BPE
names(dat_LIN6)[names(dat_LIN6) == "LIN6"] <- "Res" # Đổi tên biến BST thành Res
head(dat_LIN6)
## AGE CITY Res EC_Stop WC_Stop EC_Bus WC_Bus Gender BPE
## 1 16-25 HoChiMinh 6 Never Ever Never Ever Female LIN6
## 2 16-25 HoChiMinh 5 Never Never Ever Never Female LIN6
## 3 16-25 HoChiMinh 2 Never Never Never Never Male LIN6
## 4 16-25 HoChiMinh 5 Never Ever Never Ever Male LIN6
## 5 16-25 HoChiMinh 6 Never Ever Never Ever Male LIN6
## 6 16-25 HoChiMinh 6 Never Ever Never Ever Female LIN6
## Creat dat_IMA1 - cot 14 cua SEM1_likert
dat_IMA1 <- SEM1_likert [, c(1,2,14,31, 32, 33, 34, 35)]
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] 859 8
size <- 859
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 15 cua SEM1_likert
dat_IMA2 <- SEM1_likert [, c(1,2,15,31, 32, 33, 34, 35)]
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] 859 8
size <- 859
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 16 cua SEM1_likert
dat_IMA3 <- SEM1_likert [, c(1,2,16,31, 32, 33, 34, 35)]
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] 859 8
size <- 859
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 17 cua SEM1_likert
dat_IMA4 <- SEM1_likert [, c(1,2,17,31, 32, 33, 34, 35)]
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] 859 8
size <- 859
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 18 cua SEM1_likert
dat_IMA5 <- SEM1_likert [, c(1,2,18,31, 32, 33, 34, 35)]
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] 859 8
size <- 859
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 19 cua SEM1_likert
dat_PHB1 <- SEM1_likert [, c(1,2,19,31, 32, 33, 34, 35)]
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] 859 8
size <- 859
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 20 cua SEM1_likert
dat_PHB2 <- SEM1_likert [, c(1,2,20,31, 32, 33, 34, 35)]
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] 859 8
size <- 859
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_PHB5 - cot 21 cua SEN1_likert
dat_PHB5 <- SEM1_likert [, c(1,2,21,31, 32, 33, 34, 35)]
head(dat_PHB5)
## AGE CITY PHB5 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_PHB5)
## [1] 859 8
size <- 859
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 6 Never Ever Never Ever Female PHB5
## 2 16-25 HoChiMinh 3 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 6 Never Ever Never Ever Male PHB5
## 6 16-25 HoChiMinh 7 Never Ever Never Ever Female PHB5
## Creat dat_PHB3 - cot 22 cua SEM1_likert
dat_PHB3 <- SEM1_likert [, c(1,2,22,31, 32, 33, 34, 35)]
head(dat_PHB3)
## AGE CITY PHB3 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_PHB3)
## [1] 859 8
size <- 859
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 7 Never Ever Never Ever Female PHB3
## 2 16-25 HoChiMinh 4 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 6 Never Ever Never Ever Female PHB3
## Creat dat_PHB4 - cot 23 cua SEM1_likert
dat_PHB4 <- SEM1_likert [, c(1,2,23,31, 32, 33, 34, 35)]
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 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_PHB4)
## [1] 859 8
size <- 859
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 6 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 5 Never Ever Never Ever Male PHB4
## 6 16-25 HoChiMinh 4 Never Ever Never Ever Female PHB4
## Creat dat_PGV1 - cot 24 cua SEM1_likert
dat_PGV1 <- SEM1_likert [, c(1,2,24,31, 32, 33, 34, 35)]
head(dat_PGV1)
## AGE CITY PGV1 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_PGV1)
## [1] 859 8
size <- 859
dat_PGV1$BPE <- rep("PGV1", size = size) # Tạo biến mới BPE
names(dat_PGV1)[names(dat_PGV1) == "PGV1"] <- "Res" # Đổi tên biến BST thành Res
head(dat_PGV1)
## AGE CITY Res EC_Stop WC_Stop EC_Bus WC_Bus Gender BPE
## 1 16-25 HoChiMinh 4 Never Ever Never Ever Female PGV1
## 2 16-25 HoChiMinh 5 Never Never Ever Never Female PGV1
## 3 16-25 HoChiMinh 6 Never Never Never Never Male PGV1
## 4 16-25 HoChiMinh 5 Never Ever Never Ever Male PGV1
## 5 16-25 HoChiMinh 6 Never Ever Never Ever Male PGV1
## 6 16-25 HoChiMinh 7 Never Ever Never Ever Female PGV1
## Creat dat_PGV2 - cot 25 cua SEM1_likert
dat_PGV2 <- SEM1_likert [, c(1,2,25,31, 32, 33, 34, 35)]
head(dat_PGV2)
## AGE CITY PGV2 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_PGV2)
## [1] 859 8
size <- 859
dat_PGV2$BPE <- rep("PGV2", size = size) # Tạo biến mới BPE
names(dat_PGV2)[names(dat_PGV2) == "PGV2"] <- "Res" # Đổi tên biến BST thành Res
head(dat_PGV2)
## AGE CITY Res EC_Stop WC_Stop EC_Bus WC_Bus Gender BPE
## 1 16-25 HoChiMinh 4 Never Ever Never Ever Female PGV2
## 2 16-25 HoChiMinh 6 Never Never Ever Never Female PGV2
## 3 16-25 HoChiMinh 5 Never Never Never Never Male PGV2
## 4 16-25 HoChiMinh 5 Never Ever Never Ever Male PGV2
## 5 16-25 HoChiMinh 6 Never Ever Never Ever Male PGV2
## 6 16-25 HoChiMinh 7 Never Ever Never Ever Female PGV2
## Creat dat_PGV3 - cot 26 cua SEM1_likert
dat_PGV3 <- SEM1_likert [, c(1,2,26,31, 32, 33, 34, 35)]
head(dat_PGV3)
## AGE CITY PGV3 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_PGV3)
## [1] 859 8
size <- 859
dat_PGV3$BPE <- rep("PGV3", size = size) # Tạo biến mới BPE
names(dat_PGV3)[names(dat_PGV3) == "PGV3"] <- "Res" # Đổi tên biến BST thành Res
head(dat_PGV3)
## AGE CITY Res EC_Stop WC_Stop EC_Bus WC_Bus Gender BPE
## 1 16-25 HoChiMinh 4 Never Ever Never Ever Female PGV3
## 2 16-25 HoChiMinh 6 Never Never Ever Never Female PGV3
## 3 16-25 HoChiMinh 6 Never Never Never Never Male PGV3
## 4 16-25 HoChiMinh 5 Never Ever Never Ever Male PGV3
## 5 16-25 HoChiMinh 6 Never Ever Never Ever Male PGV3
## 6 16-25 HoChiMinh 5 Never Ever Never Ever Female PGV3
## Creat dat_PGV4 - cot 27 cua SEM1_likert
dat_PGV4 <- SEM1_likert [, c(1,2,27,31, 32, 33, 34, 35)]
head(dat_PGV4)
## AGE CITY PGV4 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_PGV4)
## [1] 859 8
size <- 859
dat_PGV4$BPE <- rep("PGV4", size = size) # Tạo biến mới BPE
names(dat_PGV4)[names(dat_PGV4) == "PGV4"] <- "Res" # Đổi tên biến BST thành Res
head(dat_PGV4)
## AGE CITY Res EC_Stop WC_Stop EC_Bus WC_Bus Gender BPE
## 1 16-25 HoChiMinh 4 Never Ever Never Ever Female PGV4
## 2 16-25 HoChiMinh 4 Never Never Ever Never Female PGV4
## 3 16-25 HoChiMinh 6 Never Never Never Never Male PGV4
## 4 16-25 HoChiMinh 5 Never Ever Never Ever Male PGV4
## 5 16-25 HoChiMinh 6 Never Ever Never Ever Male PGV4
## 6 16-25 HoChiMinh 2 Never Ever Never Ever Female PGV4
## Creat dat_PVA1 - cot 28 cua SEM1_likert
dat_PVA1 <- SEM1_likert [, c(1,2,28,31, 32, 33, 34, 35)]
head(dat_PVA1)
## AGE CITY PVA1 EC_Stop WC_Stop EC_Bus WC_Bus Gender
## 1 16-25 HoChiMinh 6 Never Ever Never Ever Female
## 2 16-25 HoChiMinh 5 Never Never Ever Never Female
## 3 16-25 HoChiMinh 6 Never Never Never Never Male
## 4 16-25 HoChiMinh 5 Never Ever Never Ever Male
## 5 16-25 HoChiMinh 6 Never Ever Never Ever Male
## 6 16-25 HoChiMinh 6 Never Ever Never Ever Female
dim(dat_PVA1)
## [1] 859 8
size <- 859
dat_PVA1$BPE <- rep("PVA1", size = size) # Tạo biến mới BPE
names(dat_PVA1)[names(dat_PVA1) == "PVA1"] <- "Res" # Đổi tên biến BST thành Res
head(dat_PVA1)
## AGE CITY Res EC_Stop WC_Stop EC_Bus WC_Bus Gender BPE
## 1 16-25 HoChiMinh 6 Never Ever Never Ever Female PVA1
## 2 16-25 HoChiMinh 5 Never Never Ever Never Female PVA1
## 3 16-25 HoChiMinh 6 Never Never Never Never Male PVA1
## 4 16-25 HoChiMinh 5 Never Ever Never Ever Male PVA1
## 5 16-25 HoChiMinh 6 Never Ever Never Ever Male PVA1
## 6 16-25 HoChiMinh 6 Never Ever Never Ever Female PVA1
## Creat dat_PVA2 - cot 29 cua SEM1_likert
dat_PVA2 <- SEM1_likert [, c(1,2,29,31, 32, 33, 34, 35)]
head(dat_PVA2)
## AGE CITY PVA2 EC_Stop WC_Stop EC_Bus WC_Bus Gender
## 1 16-25 HoChiMinh 6 Never Ever Never Ever Female
## 2 16-25 HoChiMinh 5 Never Never Ever Never Female
## 3 16-25 HoChiMinh 2 Never Never Never Never Male
## 4 16-25 HoChiMinh 5 Never Ever Never Ever Male
## 5 16-25 HoChiMinh 2 Never Ever Never Ever Male
## 6 16-25 HoChiMinh 5 Never Ever Never Ever Female
dim(dat_PVA2)
## [1] 859 8
size <- 859
dat_PVA2$BPE <- rep("PVA2", size = size) # Tạo biến mới BPE
names(dat_PVA2)[names(dat_PVA2) == "PVA2"] <- "Res" # Đổi tên biến BST thành Res
head(dat_PVA2)
## AGE CITY Res EC_Stop WC_Stop EC_Bus WC_Bus Gender BPE
## 1 16-25 HoChiMinh 6 Never Ever Never Ever Female PVA2
## 2 16-25 HoChiMinh 5 Never Never Ever Never Female PVA2
## 3 16-25 HoChiMinh 2 Never Never Never Never Male PVA2
## 4 16-25 HoChiMinh 5 Never Ever Never Ever Male PVA2
## 5 16-25 HoChiMinh 2 Never Ever Never Ever Male PVA2
## 6 16-25 HoChiMinh 5 Never Ever Never Ever Female PVA2
## Creat dat_PVA3 - cot 30 cua SEM1_likert
dat_PVA3 <- SEM1_likert [, c(1,2,30,31, 32, 33, 34, 35)]
head(dat_PVA3)
## AGE CITY PVA3 EC_Stop WC_Stop EC_Bus WC_Bus Gender
## 1 16-25 HoChiMinh 6 Never Ever Never Ever Female
## 2 16-25 HoChiMinh 3 Never Never Ever Never Female
## 3 16-25 HoChiMinh 4 Never Never Never Never Male
## 4 16-25 HoChiMinh 5 Never Ever Never Ever Male
## 5 16-25 HoChiMinh 3 Never Ever Never Ever Male
## 6 16-25 HoChiMinh 5 Never Ever Never Ever Female
dim(dat_PVA3)
## [1] 859 8
size <- 859
dat_PVA3$BPE <- rep("PVA3", size = size) # Tạo biến mới BPE
names(dat_PVA3)[names(dat_PVA3) == "PVA3"] <- "Res" # Đổi tên biến BST thành Res
head(dat_PVA3)
## AGE CITY Res EC_Stop WC_Stop EC_Bus WC_Bus Gender BPE
## 1 16-25 HoChiMinh 6 Never Ever Never Ever Female PVA3
## 2 16-25 HoChiMinh 3 Never Never Ever Never Female PVA3
## 3 16-25 HoChiMinh 4 Never Never Never Never Male PVA3
## 4 16-25 HoChiMinh 5 Never Ever Never Ever Male PVA3
## 5 16-25 HoChiMinh 3 Never Ever Never Ever Male PVA3
## 6 16-25 HoChiMinh 5 Never Ever Never Ever Female PVA3
## Tạo dữ liệu likert từ 28 dữ liệu: dat_PSA1-4, dat_LIN1-7, dat_IMA1-5, dat_PHB1-5, dat_PGV1-4, dat_PVA1-3
B.Per <- rbind(dat_PSA1, dat_PSA2, dat_PSA3, dat_PSA4, dat_LIN1, dat_LIN2, dat_LIN3, dat_LIN7, dat_LIN4, dat_LIN5, dat_LIN6, dat_IMA1, dat_IMA2, dat_IMA3, dat_IMA4, dat_IMA5, dat_PHB1, dat_PHB2, dat_PHB5, dat_PHB3, dat_PHB4, dat_PGV1, dat_PGV2, dat_PGV3, dat_PGV4, dat_PVA1, dat_PVA2, dat_PVA3)
head(B.Per)
## AGE CITY Res EC_Stop WC_Stop EC_Bus WC_Bus Gender BPE
## 1 16-25 HoChiMinh 6 Never Ever Never Ever Female PSA1
## 2 16-25 HoChiMinh 3 Never Never Ever Never Female PSA1
## 3 16-25 HoChiMinh 2 Never Never Never Never Male PSA1
## 4 16-25 HoChiMinh 5 Never Ever Never Ever Male PSA1
## 5 16-25 HoChiMinh 2 Never Ever Never Ever Male PSA1
## 6 16-25 HoChiMinh 2 Never Ever Never Ever Female PSA1
str(B.Per)
## 'data.frame': 24052 obs. of 9 variables:
## $ AGE : Factor w/ 5 levels "16-25","26-35",..: 1 1 1 1 1 1 1 3 1 1 ...
## $ CITY : Factor w/ 2 levels "DaNang","HoChiMinh": 2 2 2 2 2 2 2 2 2 2 ...
## $ Res : int 6 3 2 5 2 2 1 6 2 4 ...
## $ EC_Stop: Factor w/ 2 levels "Never","Ever": 1 1 1 1 1 1 1 1 1 1 ...
## $ WC_Stop: Factor w/ 2 levels "Never","Ever": 2 1 1 2 2 2 1 1 2 1 ...
## $ EC_Bus : Factor w/ 2 levels "Never","Ever": 1 2 1 1 1 1 1 1 1 1 ...
## $ WC_Bus : Factor w/ 2 levels "Never","Ever": 2 1 1 2 2 2 1 1 2 1 ...
## $ Gender : Factor w/ 2 levels "Female","Male": 1 1 2 2 2 1 1 1 1 1 ...
## $ BPE : chr "PSA1" "PSA1" "PSA1" "PSA1" ...
dim(B.Per)
## [1] 24052 9
## Tạo dữ liệu likert theo constructs
B.Per_PSA <- rbind(dat_PSA1, dat_PSA2, dat_PSA3, dat_PSA4)
head(B.Per_PSA)
## AGE CITY Res EC_Stop WC_Stop EC_Bus WC_Bus Gender BPE
## 1 16-25 HoChiMinh 6 Never Ever Never Ever Female PSA1
## 2 16-25 HoChiMinh 3 Never Never Ever Never Female PSA1
## 3 16-25 HoChiMinh 2 Never Never Never Never Male PSA1
## 4 16-25 HoChiMinh 5 Never Ever Never Ever Male PSA1
## 5 16-25 HoChiMinh 2 Never Ever Never Ever Male PSA1
## 6 16-25 HoChiMinh 2 Never Ever Never Ever Female PSA1
str(B.Per_PSA)
## 'data.frame': 3436 obs. of 9 variables:
## $ AGE : Factor w/ 5 levels "16-25","26-35",..: 1 1 1 1 1 1 1 3 1 1 ...
## $ CITY : Factor w/ 2 levels "DaNang","HoChiMinh": 2 2 2 2 2 2 2 2 2 2 ...
## $ Res : int 6 3 2 5 2 2 1 6 2 4 ...
## $ EC_Stop: Factor w/ 2 levels "Never","Ever": 1 1 1 1 1 1 1 1 1 1 ...
## $ WC_Stop: Factor w/ 2 levels "Never","Ever": 2 1 1 2 2 2 1 1 2 1 ...
## $ EC_Bus : Factor w/ 2 levels "Never","Ever": 1 2 1 1 1 1 1 1 1 1 ...
## $ WC_Bus : Factor w/ 2 levels "Never","Ever": 2 1 1 2 2 2 1 1 2 1 ...
## $ Gender : Factor w/ 2 levels "Female","Male": 1 1 2 2 2 1 1 1 1 1 ...
## $ BPE : chr "PSA1" "PSA1" "PSA1" "PSA1" ...
dim(B.Per_PSA)
## [1] 3436 9
B.Per_LIN <- rbind(dat_LIN1, dat_LIN2, dat_LIN3, dat_LIN7, dat_LIN4, dat_LIN5, dat_LIN6)
head(B.Per_LIN)
## AGE CITY Res EC_Stop WC_Stop EC_Bus WC_Bus Gender BPE
## 1 16-25 HoChiMinh 4 Never Ever Never Ever Female LIN1
## 2 16-25 HoChiMinh 4 Never Never Ever Never Female LIN1
## 3 16-25 HoChiMinh 2 Never Never Never Never Male LIN1
## 4 16-25 HoChiMinh 5 Never Ever Never Ever Male LIN1
## 5 16-25 HoChiMinh 4 Never Ever Never Ever Male LIN1
## 6 16-25 HoChiMinh 4 Never Ever Never Ever Female LIN1
str(B.Per_LIN)
## 'data.frame': 6013 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 "LIN1" "LIN1" "LIN1" "LIN1" ...
dim(B.Per_LIN)
## [1] 6013 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': 4295 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] 4295 9
B.Per_PHB <- rbind(dat_PHB1, dat_PHB2, dat_PHB5, dat_PHB3, dat_PHB4)
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': 4295 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] 4295 9
B.Per_PGV <- rbind(dat_PGV1, dat_PGV2, dat_PGV3, dat_PGV4)
head(B.Per_PGV)
## AGE CITY Res EC_Stop WC_Stop EC_Bus WC_Bus Gender BPE
## 1 16-25 HoChiMinh 4 Never Ever Never Ever Female PGV1
## 2 16-25 HoChiMinh 5 Never Never Ever Never Female PGV1
## 3 16-25 HoChiMinh 6 Never Never Never Never Male PGV1
## 4 16-25 HoChiMinh 5 Never Ever Never Ever Male PGV1
## 5 16-25 HoChiMinh 6 Never Ever Never Ever Male PGV1
## 6 16-25 HoChiMinh 7 Never Ever Never Ever Female PGV1
str(B.Per_PGV)
## 'data.frame': 3436 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 "PGV1" "PGV1" "PGV1" "PGV1" ...
dim(B.Per_PGV)
## [1] 3436 9
B.Per_PVA <- rbind(dat_PVA1, dat_PVA2, dat_PVA3)
head(B.Per_PVA)
## AGE CITY Res EC_Stop WC_Stop EC_Bus WC_Bus Gender BPE
## 1 16-25 HoChiMinh 6 Never Ever Never Ever Female PVA1
## 2 16-25 HoChiMinh 5 Never Never Ever Never Female PVA1
## 3 16-25 HoChiMinh 6 Never Never Never Never Male PVA1
## 4 16-25 HoChiMinh 5 Never Ever Never Ever Male PVA1
## 5 16-25 HoChiMinh 6 Never Ever Never Ever Male PVA1
## 6 16-25 HoChiMinh 6 Never Ever Never Ever Female PVA1
str(B.Per_PVA)
## 'data.frame': 2577 obs. of 9 variables:
## $ AGE : Factor w/ 5 levels "16-25","26-35",..: 1 1 1 1 1 1 1 3 1 1 ...
## $ CITY : Factor w/ 2 levels "DaNang","HoChiMinh": 2 2 2 2 2 2 2 2 2 2 ...
## $ Res : int 6 5 6 5 6 6 6 6 6 6 ...
## $ EC_Stop: Factor w/ 2 levels "Never","Ever": 1 1 1 1 1 1 1 1 1 1 ...
## $ WC_Stop: Factor w/ 2 levels "Never","Ever": 2 1 1 2 2 2 1 1 2 1 ...
## $ EC_Bus : Factor w/ 2 levels "Never","Ever": 1 2 1 1 1 1 1 1 1 1 ...
## $ WC_Bus : Factor w/ 2 levels "Never","Ever": 2 1 1 2 2 2 1 1 2 1 ...
## $ Gender : Factor w/ 2 levels "Female","Male": 1 1 2 2 2 1 1 1 1 1 ...
## $ BPE : chr "PVA1" "PVA1" "PVA1" "PVA1" ...
dim(B.Per_PVA)
## [1] 2577 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_SEM1 = subset(B.Per, CITY == "DaNang")
head(DN_SEM1)
## AGE CITY Res EC_Stop WC_Stop EC_Bus WC_Bus Gender BPE
## 456 26-35 DaNang 6 Never Never Never Never Male PSA1
## 457 46-55 DaNang 6 Never Never Never Never Female PSA1
## 458 46-55 DaNang 6 Never Never Never Never Female PSA1
## 459 26-35 DaNang 5 Never Never Never Never Female PSA1
## 460 46-55 DaNang 6 Never Never Never Never Female PSA1
## 461 16-25 DaNang 6 Never Never Never Never Female PSA1
str(DN_SEM1)
## 'data.frame': 11312 obs. of 9 variables:
## $ AGE : Factor w/ 5 levels "16-25","26-35",..: 2 4 4 2 4 1 1 2 1 2 ...
## $ CITY : Factor w/ 2 levels "DaNang","HoChiMinh": 1 1 1 1 1 1 1 1 1 1 ...
## $ Res : int 6 6 6 5 6 6 6 7 4 6 ...
## $ EC_Stop: Factor w/ 2 levels "Never","Ever": 1 1 1 1 1 1 1 1 1 1 ...
## $ WC_Stop: Factor w/ 2 levels "Never","Ever": 1 1 1 1 1 1 1 1 1 1 ...
## $ EC_Bus : Factor w/ 2 levels "Never","Ever": 1 1 1 1 1 1 1 1 1 1 ...
## $ WC_Bus : Factor w/ 2 levels "Never","Ever": 1 1 1 1 1 1 1 1 1 1 ...
## $ Gender : Factor w/ 2 levels "Female","Male": 2 1 1 1 1 1 1 2 2 1 ...
## $ BPE : chr "PSA1" "PSA1" "PSA1" "PSA1" ...
dim(DN_SEM1)
## [1] 11312 9
DN_SEM1 = DN_SEM1[ , c(3, 9)]
dim(DN_SEM1)
## [1] 11312 2
head(DN_SEM1)
## Res BPE
## 456 6 PSA1
## 457 6 PSA1
## 458 6 PSA1
## 459 5 PSA1
## 460 6 PSA1
## 461 6 PSA1
# Data Bus perception of people in Ho Chi Minh
HCM_SEM1 = subset(B.Per, CITY == "HoChiMinh")
head(HCM_SEM1)
## AGE CITY Res EC_Stop WC_Stop EC_Bus WC_Bus Gender BPE
## 1 16-25 HoChiMinh 6 Never Ever Never Ever Female PSA1
## 2 16-25 HoChiMinh 3 Never Never Ever Never Female PSA1
## 3 16-25 HoChiMinh 2 Never Never Never Never Male PSA1
## 4 16-25 HoChiMinh 5 Never Ever Never Ever Male PSA1
## 5 16-25 HoChiMinh 2 Never Ever Never Ever Male PSA1
## 6 16-25 HoChiMinh 2 Never Ever Never Ever Female PSA1
str(HCM_SEM1)
## 'data.frame': 12740 obs. of 9 variables:
## $ AGE : Factor w/ 5 levels "16-25","26-35",..: 1 1 1 1 1 1 1 3 1 1 ...
## $ CITY : Factor w/ 2 levels "DaNang","HoChiMinh": 2 2 2 2 2 2 2 2 2 2 ...
## $ Res : int 6 3 2 5 2 2 1 6 2 4 ...
## $ EC_Stop: Factor w/ 2 levels "Never","Ever": 1 1 1 1 1 1 1 1 1 1 ...
## $ WC_Stop: Factor w/ 2 levels "Never","Ever": 2 1 1 2 2 2 1 1 2 1 ...
## $ EC_Bus : Factor w/ 2 levels "Never","Ever": 1 2 1 1 1 1 1 1 1 1 ...
## $ WC_Bus : Factor w/ 2 levels "Never","Ever": 2 1 1 2 2 2 1 1 2 1 ...
## $ Gender : Factor w/ 2 levels "Female","Male": 1 1 2 2 2 1 1 1 1 1 ...
## $ BPE : chr "PSA1" "PSA1" "PSA1" "PSA1" ...
dim(HCM_SEM1)
## [1] 12740 9
HCM_SEM1 = HCM_SEM1[ , c(3, 9)]
dim(HCM_SEM1)
## [1] 12740 2
head(HCM_SEM1)
## Res BPE
## 1 6 PSA1
## 2 3 PSA1
## 3 2 PSA1
## 4 5 PSA1
## 5 2 PSA1
## 6 2 PSA1
# Data Bus perception of people in both Da Nang and Ho Chi Minh cities
DN_HCM_SEM1 = B.Per[, c(3, 9)]
str(DN_HCM_SEM1)
## 'data.frame': 24052 obs. of 2 variables:
## $ Res: int 6 3 2 5 2 2 1 6 2 4 ...
## $ BPE: chr "PSA1" "PSA1" "PSA1" "PSA1" ...
dim(DN_HCM_SEM1)
## [1] 24052 2
head(DN_HCM_SEM1)
## Res BPE
## 1 6 PSA1
## 2 3 PSA1
## 3 2 PSA1
## 4 5 PSA1
## 5 2 PSA1
## 6 2 PSA1
# Data bus perception of people in both Da Nang and Ho Chi Minh cities - according constructs
## Construct PSA
DN_HCM_SEM1_PSA = B.Per_PSA[ , c(3, 9)]
dim(DN_HCM_SEM1_PSA)
## [1] 3436 2
head(DN_HCM_SEM1_PSA)
## Res BPE
## 1 6 PSA1
## 2 3 PSA1
## 3 2 PSA1
## 4 5 PSA1
## 5 2 PSA1
## 6 2 PSA1
## Construct LIN
DN_HCM_SEM1_LIN = B.Per_LIN[ , c(3, 9)]
dim(DN_HCM_SEM1_LIN)
## [1] 6013 2
head(DN_HCM_SEM1_LIN)
## Res BPE
## 1 4 LIN1
## 2 4 LIN1
## 3 2 LIN1
## 4 5 LIN1
## 5 4 LIN1
## 6 4 LIN1
## Construct IMA
DN_HCM_SEM1_IMA = B.Per_IMA[ , c(3, 9)]
dim(DN_HCM_SEM1_IMA)
## [1] 4295 2
head(DN_HCM_SEM1_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_SEM1_PHB = B.Per_PHB[ , c(3, 9)]
dim(DN_HCM_SEM1_PHB)
## [1] 4295 2
head(DN_HCM_SEM1_PHB)
## Res BPE
## 1 6 PHB1
## 2 3 PHB1
## 3 5 PHB1
## 4 5 PHB1
## 5 5 PHB1
## 6 4 PHB1
## Construct PGV
DN_HCM_SEM1_PGV = B.Per_PGV[ , c(3, 9)]
dim(DN_HCM_SEM1_PGV)
## [1] 3436 2
head(DN_HCM_SEM1_PGV)
## Res BPE
## 1 4 PGV1
## 2 5 PGV1
## 3 6 PGV1
## 4 5 PGV1
## 5 6 PGV1
## 6 7 PGV1
## Construct PVA
DN_HCM_SEM1_PVA = B.Per_PVA[ , c(3, 9)]
dim(DN_HCM_SEM1_PVA)
## [1] 2577 2
head(DN_HCM_SEM1_PVA)
## Res BPE
## 1 6 PVA1
## 2 5 PVA1
## 3 6 PVA1
## 4 5 PVA1
## 5 6 PVA1
## 6 6 PVA1
3.2. Vẽ biểu đồ likert với dữ liệu chung Đà Nẵng và Hồ Chí Minh
# 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_SEM1)
## Res BPE
## 1 6 PSA1
## 2 3 PSA1
## 3 2 PSA1
## 4 5 PSA1
## 5 2 PSA1
## 6 2 PSA1
dim(DN_HCM_SEM1)
## [1] 24052 2
attach(DN_HCM_SEM1)
DN_HCM_SEM1 = within(DN_HCM_SEM1, {
Res = factor(Res, labels = c("Very Disagree", "Disagree", "Quite Disagree", "Normal", "Quite Agree", "Agree", "Very Agree"))
BPE = factor(BPE, labels = c("PSA1", "PSA2", "PSA3", "PSA4", "LIN1", "LIN2", "LIN3", "LIN7", "LIN4", "LIN5", "LIN6", "IMA1", "IMA2", "IMA3", "IMA4", "IMA5", "PHB1", "PHB2", "PHB5", "PHB3", "PHB4", "PGV1", "PGV2", "PGV3", "PGV4", "PVA1", "PVA2", "PVA3"))
})
str(DN_HCM_SEM1)
## 'data.frame': 24052 obs. of 2 variables:
## $ Res: Factor w/ 7 levels "Very Disagree",..: 6 3 2 5 2 2 1 6 2 4 ...
## $ BPE: Factor w/ 28 levels "PSA1","PSA2",..: 22 22 22 22 22 22 22 22 22 22 ...
summary(DN_HCM_SEM1)
## Res BPE
## Very Disagree : 469 PSA1 : 859
## Disagree : 730 PSA2 : 859
## Quite Disagree: 748 PSA3 : 859
## Normal : 2703 PSA4 : 859
## Quite Agree : 4740 LIN1 : 859
## Agree :10703 LIN2 : 859
## Very Agree : 3959 (Other):18898
## t <- compareGroups(Res ~ BPE, data = DN_HCM_SEM1)
## createTable(t)
DN_HCM_SEM1 %>%
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] PSA1 PSA2 PSA3 PSA4 LIN1 LIN2 LIN3 LIN7 LIN4 LIN5 LIN6 IMA1 IMA2 IMA3 IMA4
## [16] IMA5 PHB1 PHB2 PHB5 PHB3 PHB4 PGV1 PGV2 PGV3 PGV4 PVA1 PVA2 PVA3
## 28 Levels: PSA1 PSA2 PSA3 PSA4 LIN1 LIN2 LIN3 LIN7 LIN4 LIN5 LIN6 IMA1 ... PVA3
# Make a draft plot:
my_colors <- c("#3e6487", "#829cb2", "pink", "pink3", "palevioletred", "rosybrown2", "rosybrown3")
my_font <- "Roboto Condensed"
df_for_ploting %>%
mutate(BPE = factor(BPE, levels = order_x), Res = factor(Res, levels = Res[7:1])) -> df_odered
df_odered
## # A tibble: 196 x 5
## BPE Res n percent bar_text
## <fct> <fct> <int> <dbl> <chr>
## 1 PSA1 Very Disagree 6 0.7 0.7%
## 2 PSA1 Disagree 20 2.33 2.33%
## 3 PSA1 Quite Disagree 32 3.73 3.73%
## 4 PSA1 Normal 155 18.0 18.04%
## 5 PSA1 Quite Agree 228 26.5 26.54%
## 6 PSA1 Agree 353 41.1 41.09%
## 7 PSA1 Very Agree 65 7.57 7.57%
## 8 PSA2 Very Disagree 12 1.4 1.4%
## 9 PSA2 Disagree 18 2.1 2.1%
## 10 PSA2 Quite Disagree 25 2.91 2.91%
## # ... with 186 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: 28 x 5
## BPE Res n percent bar_text
## <fct> <fct> <int> <dbl> <chr>
## 1 PSA1 Very Disagree 6 0.7 0.7%
## 2 PSA2 Very Disagree 12 1.4 1.4%
## 3 PSA3 Very Disagree 13 1.51 1.51%
## 4 PSA4 Very Disagree 13 1.51 1.51%
## 5 LIN1 Very Disagree 6 0.7 0.7%
## 6 LIN2 Very Disagree 4 0.47 0.47%
## 7 LIN3 Very Disagree 7 0.81 0.81%
## 8 LIN7 Very Disagree 3 0.35 0.35%
## 9 LIN4 Very Disagree 11 1.28 1.28%
## 10 LIN5 Very Disagree 15 1.75 1.75%
## # ... with 18 more rows
# For displaying percent of "Disagree":
df_odered %>%
filter(Res == "Disagree") %>%
filter(percent >= 0) -> df_for_text2
df_for_text2
## # A tibble: 28 x 5
## BPE Res n percent bar_text
## <fct> <fct> <int> <dbl> <chr>
## 1 PSA1 Disagree 20 2.33 2.33%
## 2 PSA2 Disagree 18 2.1 2.1%
## 3 PSA3 Disagree 9 1.05 1.05%
## 4 PSA4 Disagree 13 1.51 1.51%
## 5 LIN1 Disagree 21 2.44 2.44%
## 6 LIN2 Disagree 19 2.21 2.21%
## 7 LIN3 Disagree 22 2.56 2.56%
## 8 LIN7 Disagree 16 1.86 1.86%
## 9 LIN4 Disagree 23 2.68 2.68%
## 10 LIN5 Disagree 57 6.64 6.64%
## # ... with 18 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: 28 x 5
## BPE Res n percent bar_text
## <fct> <fct> <int> <dbl> <chr>
## 1 PSA1 Quite Disagree 32 3.73 3.73%
## 2 PSA2 Quite Disagree 25 2.91 2.91%
## 3 PSA3 Quite Disagree 20 2.33 2.33%
## 4 PSA4 Quite Disagree 27 3.14 3.14%
## 5 LIN1 Quite Disagree 21 2.44 2.44%
## 6 LIN2 Quite Disagree 19 2.21 2.21%
## 7 LIN3 Quite Disagree 16 1.86 1.86%
## 8 LIN7 Quite Disagree 18 2.1 2.1%
## 9 LIN4 Quite Disagree 23 2.68 2.68%
## 10 LIN5 Quite Disagree 51 5.94 5.94%
## # ... with 18 more rows
# For displaying percent of "Normal":
df_odered %>%
filter(Res == "Normal") %>%
filter(percent >= 0) -> df_for_text4
df_for_text4
## # A tibble: 28 x 5
## BPE Res n percent bar_text
## <fct> <fct> <int> <dbl> <chr>
## 1 PSA1 Normal 155 18.0 18.04%
## 2 PSA2 Normal 157 18.3 18.28%
## 3 PSA3 Normal 129 15.0 15.02%
## 4 PSA4 Normal 112 13.0 13.04%
## 5 LIN1 Normal 105 12.2 12.22%
## 6 LIN2 Normal 115 13.4 13.39%
## 7 LIN3 Normal 99 11.5 11.53%
## 8 LIN7 Normal 92 10.7 10.71%
## 9 LIN4 Normal 111 12.9 12.92%
## 10 LIN5 Normal 142 16.5 16.53%
## # ... with 18 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: 28 x 5
## BPE Res n percent bar_text
## <fct> <fct> <int> <dbl> <chr>
## 1 PSA1 Quite Agree 228 26.5 26.54%
## 2 PSA2 Quite Agree 213 24.8 24.8%
## 3 PSA3 Quite Agree 205 23.9 23.86%
## 4 PSA4 Quite Agree 199 23.2 23.17%
## 5 LIN1 Quite Agree 201 23.4 23.4%
## 6 LIN2 Quite Agree 163 19.0 18.98%
## 7 LIN3 Quite Agree 167 19.4 19.44%
## 8 LIN7 Quite Agree 157 18.3 18.28%
## 9 LIN4 Quite Agree 211 24.6 24.56%
## 10 LIN5 Quite Agree 168 19.6 19.56%
## # ... with 18 more rows
# For displaying percent of "Agree":
df_odered %>%
filter(Res == "Agree") %>%
filter(percent >= 0) -> df_for_text6
df_for_text6
## # A tibble: 28 x 5
## BPE Res n percent bar_text
## <fct> <fct> <int> <dbl> <chr>
## 1 PSA1 Agree 353 41.1 41.09%
## 2 PSA2 Agree 368 42.8 42.84%
## 3 PSA3 Agree 404 47.0 47.03%
## 4 PSA4 Agree 409 47.6 47.61%
## 5 LIN1 Agree 419 48.8 48.78%
## 6 LIN2 Agree 432 50.3 50.29%
## 7 LIN3 Agree 427 49.7 49.71%
## 8 LIN7 Agree 439 51.1 51.11%
## 9 LIN4 Agree 347 40.4 40.4%
## 10 LIN5 Agree 296 34.5 34.46%
## # ... with 18 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: 28 x 5
## BPE Res n percent bar_text
## <fct> <fct> <int> <dbl> <chr>
## 1 PSA1 Very Agree 65 7.57 7.57%
## 2 PSA2 Very Agree 66 7.68 7.68%
## 3 PSA3 Very Agree 79 9.2 9.2%
## 4 PSA4 Very Agree 86 10.0 10.01%
## 5 LIN1 Very Agree 86 10.0 10.01%
## 6 LIN2 Very Agree 107 12.5 12.46%
## 7 LIN3 Very Agree 121 14.1 14.09%
## 8 LIN7 Very Agree 134 15.6 15.6%
## 9 LIN4 Very Agree 133 15.5 15.48%
## 10 LIN5 Very Agree 130 15.1 15.13%
## # ... with 18 more rows
# For displaying percent of "Very Agree":
df_odered %>%
filter(Res == "Very Agree") -> df_for_text
df_for_text
## # A tibble: 28 x 5
## BPE Res n percent bar_text
## <fct> <fct> <int> <dbl> <chr>
## 1 PSA1 Very Agree 65 7.57 7.57%
## 2 PSA2 Very Agree 66 7.68 7.68%
## 3 PSA3 Very Agree 79 9.2 9.2%
## 4 PSA4 Very Agree 86 10.0 10.01%
## 5 LIN1 Very Agree 86 10.0 10.01%
## 6 LIN2 Very Agree 107 12.5 12.46%
## 7 LIN3 Very Agree 121 14.1 14.09%
## 8 LIN7 Very Agree 134 15.6 15.6%
## 9 LIN4 Very Agree 133 15.5 15.48%
## 10 LIN5 Very Agree 130 15.1 15.13%
## # ... with 18 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 cho dữ liệu Đà Nẵng
# Plot Likert graph for people in Da Nang
library(tidyverse)
library(compareGroups)
head(DN_SEM1)
## Res BPE
## 456 6 PSA1
## 457 6 PSA1
## 458 6 PSA1
## 459 5 PSA1
## 460 6 PSA1
## 461 6 PSA1
dim(DN_SEM1)
## [1] 11312 2
attach(DN_SEM1)
## The following objects are masked from DN_HCM_SEM1:
##
## BPE, Res
DN_SEM1 = within(DN_SEM1, {
Res = factor(Res, labels = c("Very Disagree", "Disagree", "Quite Disagree", "Normal", "Quite Agree", "Agree", "Very Agree"))
BPE = factor(BPE, labels = c("PSA1", "PSA2", "PSA3", "PSA4", "LIN1", "LIN2", "LIN3", "LIN7", "LIN4", "LIN5", "LIN6", "IMA1", "IMA2", "IMA3", "IMA4", "IMA5", "PHB1", "PHB2", "PHB5", "PHB3", "PHB4", "PGV1", "PGV2", "PGV3", "PGV4", "PVA1", "PVA2", "PVA3"))
})
str(DN_SEM1)
## 'data.frame': 11312 obs. of 2 variables:
## $ Res: Factor w/ 7 levels "Very Disagree",..: 6 6 6 5 6 6 6 7 4 6 ...
## $ BPE: Factor w/ 28 levels "PSA1","PSA2",..: 22 22 22 22 22 22 22 22 22 22 ...
summary(DN_SEM1)
## Res BPE
## Very Disagree : 25 PSA1 : 404
## Disagree : 100 PSA2 : 404
## Quite Disagree: 287 PSA3 : 404
## Normal : 758 PSA4 : 404
## Quite Agree :2560 LIN1 : 404
## Agree :5451 LIN2 : 404
## Very Agree :2131 (Other):8888
## t <- compareGroups(Res ~ BPE, data = DN_SEM1)
## createTable(t)
DN_SEM1 %>%
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] PSA1 PSA2 PSA3 PSA4 LIN1 LIN2 LIN3 LIN7 LIN4 LIN5 LIN6 IMA1 IMA2 IMA3 IMA4
## [16] IMA5 PHB1 PHB2 PHB5 PHB3 PHB4 PGV1 PGV2 PGV3 PGV4 PVA1 PVA2 PVA3
## 28 Levels: PSA1 PSA2 PSA3 PSA4 LIN1 LIN2 LIN3 LIN7 LIN4 LIN5 LIN6 IMA1 ... PVA3
# Make a draft plot:
my_colors <- c("#3e6487", "#829cb2", "pink", "pink3", "palevioletred", "rosybrown2", "rosybrown3")
my_font <- "Roboto Condensed"
df_for_ploting %>%
mutate(BPE = factor(BPE, levels = order_x), Res = factor(Res, levels = Res[7:1])) -> df_odered
df_odered
## # A tibble: 168 x 5
## BPE Res n percent bar_text
## <fct> <fct> <int> <dbl> <chr>
## 1 PSA1 Very Disagree 1 0.25 0.25%
## 2 PSA1 Disagree 3 0.74 0.74%
## 3 PSA1 Quite Disagree 11 2.72 2.72%
## 4 PSA1 Normal 54 13.4 13.37%
## 5 PSA1 Quite Agree 134 33.2 33.17%
## 6 PSA1 Agree 168 41.6 41.58%
## 7 PSA1 Very Agree 33 8.17 8.17%
## 8 PSA2 Quite Disagree 7 1.73 1.73%
## 9 PSA2 Normal 46 11.4 11.39%
## 10 PSA2 Quite Agree 112 27.7 27.72%
## # ... with 158 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: 9 x 5
## BPE Res n percent bar_text
## <fct> <fct> <int> <dbl> <chr>
## 1 PSA1 Very Disagree 1 0.25 0.25%
## 2 LIN5 Very Disagree 1 0.25 0.25%
## 3 IMA2 Very Disagree 1 0.25 0.25%
## 4 IMA3 Very Disagree 1 0.25 0.25%
## 5 PHB1 Very Disagree 1 0.25 0.25%
## 6 PGV1 Very Disagree 8 1.98 1.98%
## 7 PGV2 Very Disagree 5 1.24 1.24%
## 8 PGV3 Very Disagree 3 0.74 0.74%
## 9 PGV4 Very Disagree 4 0.99 0.99%
# For displaying percent of "Disagree":
df_odered %>%
filter(Res == "Disagree") %>%
filter(percent >= 0) -> df_for_text2
df_for_text2
## # A tibble: 20 x 5
## BPE Res n percent bar_text
## <fct> <fct> <int> <dbl> <chr>
## 1 PSA1 Disagree 3 0.74 0.74%
## 2 LIN2 Disagree 2 0.5 0.5%
## 3 LIN3 Disagree 1 0.25 0.25%
## 4 LIN7 Disagree 1 0.25 0.25%
## 5 LIN4 Disagree 1 0.25 0.25%
## 6 LIN5 Disagree 12 2.97 2.97%
## 7 IMA2 Disagree 1 0.25 0.25%
## 8 IMA3 Disagree 2 0.5 0.5%
## 9 IMA4 Disagree 4 0.99 0.99%
## 10 IMA5 Disagree 3 0.74 0.74%
## 11 PHB1 Disagree 6 1.49 1.49%
## 12 PHB2 Disagree 5 1.24 1.24%
## 13 PHB4 Disagree 10 2.48 2.48%
## 14 PGV1 Disagree 8 1.98 1.98%
## 15 PGV2 Disagree 10 2.48 2.48%
## 16 PGV3 Disagree 6 1.49 1.49%
## 17 PGV4 Disagree 11 2.72 2.72%
## 18 PVA1 Disagree 2 0.5 0.5%
## 19 PVA2 Disagree 11 2.72 2.72%
## 20 PVA3 Disagree 1 0.25 0.25%
# For displaying percent of "Quite Disagree":
df_odered %>%
filter(Res == "Quite Disagree") %>%
filter(percent >= 0) -> df_for_text3
df_for_text3
## # A tibble: 27 x 5
## BPE Res n percent bar_text
## <fct> <fct> <int> <dbl> <chr>
## 1 PSA1 Quite Disagree 11 2.72 2.72%
## 2 PSA2 Quite Disagree 7 1.73 1.73%
## 3 PSA3 Quite Disagree 4 0.99 0.99%
## 4 PSA4 Quite Disagree 8 1.98 1.98%
## 5 LIN1 Quite Disagree 6 1.49 1.49%
## 6 LIN2 Quite Disagree 5 1.24 1.24%
## 7 LIN3 Quite Disagree 6 1.49 1.49%
## 8 LIN7 Quite Disagree 4 0.99 0.99%
## 9 LIN4 Quite Disagree 10 2.48 2.48%
## 10 LIN5 Quite Disagree 32 7.92 7.92%
## # ... with 17 more rows
# For displaying percent of "Normal":
df_odered %>%
filter(Res == "Normal") %>%
filter(percent >= 0) -> df_for_text4
df_for_text4
## # A tibble: 28 x 5
## BPE Res n percent bar_text
## <fct> <fct> <int> <dbl> <chr>
## 1 PSA1 Normal 54 13.4 13.37%
## 2 PSA2 Normal 46 11.4 11.39%
## 3 PSA3 Normal 39 9.65 9.65%
## 4 PSA4 Normal 23 5.69 5.69%
## 5 LIN1 Normal 23 5.69 5.69%
## 6 LIN2 Normal 27 6.68 6.68%
## 7 LIN3 Normal 23 5.69 5.69%
## 8 LIN7 Normal 30 7.43 7.43%
## 9 LIN4 Normal 33 8.17 8.17%
## 10 LIN5 Normal 42 10.4 10.4%
## # ... with 18 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: 28 x 5
## BPE Res n percent bar_text
## <fct> <fct> <int> <dbl> <chr>
## 1 PSA1 Quite Agree 134 33.2 33.17%
## 2 PSA2 Quite Agree 112 27.7 27.72%
## 3 PSA3 Quite Agree 104 25.7 25.74%
## 4 PSA4 Quite Agree 101 25 25%
## 5 LIN1 Quite Agree 94 23.3 23.27%
## 6 LIN2 Quite Agree 87 21.5 21.53%
## 7 LIN3 Quite Agree 84 20.8 20.79%
## 8 LIN7 Quite Agree 71 17.6 17.57%
## 9 LIN4 Quite Agree 113 28.0 27.97%
## 10 LIN5 Quite Agree 99 24.5 24.5%
## # ... with 18 more rows
# For displaying percent of "Agree":
df_odered %>%
filter(Res == "Agree") %>%
filter(percent >= 0) -> df_for_text6
df_for_text6
## # A tibble: 28 x 5
## BPE Res n percent bar_text
## <fct> <fct> <int> <dbl> <chr>
## 1 PSA1 Agree 168 41.6 41.58%
## 2 PSA2 Agree 205 50.7 50.74%
## 3 PSA3 Agree 213 52.7 52.72%
## 4 PSA4 Agree 219 54.2 54.21%
## 5 LIN1 Agree 229 56.7 56.68%
## 6 LIN2 Agree 217 53.7 53.71%
## 7 LIN3 Agree 219 54.2 54.21%
## 8 LIN7 Agree 218 54.0 53.96%
## 9 LIN4 Agree 167 41.3 41.34%
## 10 LIN5 Agree 140 34.6 34.65%
## # ... with 18 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: 28 x 5
## BPE Res n percent bar_text
## <fct> <fct> <int> <dbl> <chr>
## 1 PSA1 Very Agree 33 8.17 8.17%
## 2 PSA2 Very Agree 34 8.42 8.42%
## 3 PSA3 Very Agree 44 10.9 10.89%
## 4 PSA4 Very Agree 53 13.1 13.12%
## 5 LIN1 Very Agree 52 12.9 12.87%
## 6 LIN2 Very Agree 66 16.3 16.34%
## 7 LIN3 Very Agree 71 17.6 17.57%
## 8 LIN7 Very Agree 80 19.8 19.8%
## 9 LIN4 Very Agree 80 19.8 19.8%
## 10 LIN5 Very Agree 78 19.3 19.31%
## # ... with 18 more rows
# For displaying percent of "Very Agree":
df_odered %>%
filter(Res == "Very Agree") -> df_for_text
df_for_text
## # A tibble: 28 x 5
## BPE Res n percent bar_text
## <fct> <fct> <int> <dbl> <chr>
## 1 PSA1 Very Agree 33 8.17 8.17%
## 2 PSA2 Very Agree 34 8.42 8.42%
## 3 PSA3 Very Agree 44 10.9 10.89%
## 4 PSA4 Very Agree 53 13.1 13.12%
## 5 LIN1 Very Agree 52 12.9 12.87%
## 6 LIN2 Very Agree 66 16.3 16.34%
## 7 LIN3 Very Agree 71 17.6 17.57%
## 8 LIN7 Very Agree 80 19.8 19.8%
## 9 LIN4 Very Agree 80 19.8 19.8%
## 10 LIN5 Very Agree 78 19.3 19.31%
## # ... with 18 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.4. Vẽ biểu đồ likert cho dữ liệu Hồ Chí Minh
# Plot Likert graph for people in Ho Chi Minh
library(tidyverse)
library(compareGroups)
head(HCM_SEM1)
## Res BPE
## 1 6 PSA1
## 2 3 PSA1
## 3 2 PSA1
## 4 5 PSA1
## 5 2 PSA1
## 6 2 PSA1
dim(HCM_SEM1)
## [1] 12740 2
attach(HCM_SEM1)
## The following objects are masked from DN_SEM1:
##
## BPE, Res
## The following objects are masked from DN_HCM_SEM1:
##
## BPE, Res
HCM_SEM1 = within(HCM_SEM1, {
Res = factor(Res, labels = c("Very Disagree", "Disagree", "Quite Disagree", "Normal", "Quite Agree", "Agree", "Very Agree"))
BPE = factor(BPE, labels = c("PSA1", "PSA2", "PSA3", "PSA4", "LIN1", "LIN2", "LIN3", "LIN7", "LIN4", "LIN5", "LIN6", "IMA1", "IMA2", "IMA3", "IMA4", "IMA5", "PHB1", "PHB2", "PHB5", "PHB3", "PHB4", "PGV1", "PGV2", "PGV3", "PGV4", "PVA1", "PVA2", "PVA3"))
})
str(HCM_SEM1)
## 'data.frame': 12740 obs. of 2 variables:
## $ Res: Factor w/ 7 levels "Very Disagree",..: 6 3 2 5 2 2 1 6 2 4 ...
## $ BPE: Factor w/ 28 levels "PSA1","PSA2",..: 22 22 22 22 22 22 22 22 22 22 ...
summary(HCM_SEM1)
## Res BPE
## Very Disagree : 444 PSA1 : 455
## Disagree : 630 PSA2 : 455
## Quite Disagree: 461 PSA3 : 455
## Normal :1945 PSA4 : 455
## Quite Agree :2180 LIN1 : 455
## Agree :5252 LIN2 : 455
## Very Agree :1828 (Other):10010
## t <- compareGroups(Res ~ BPE, data = DN_SEM1)
## createTable(t)
HCM_SEM1 %>%
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] PSA1 PSA2 PSA3 PSA4 LIN1 LIN2 LIN3 LIN7 LIN4 LIN5 LIN6 IMA1 IMA2 IMA3 IMA4
## [16] IMA5 PHB1 PHB2 PHB5 PHB3 PHB4 PGV1 PGV2 PGV3 PGV4 PVA1 PVA2 PVA3
## 28 Levels: PSA1 PSA2 PSA3 PSA4 LIN1 LIN2 LIN3 LIN7 LIN4 LIN5 LIN6 IMA1 ... PVA3
# Make a draft plot:
my_colors <- c("#3e6487", "#829cb2", "pink", "pink3", "palevioletred", "rosybrown2", "rosybrown3")
my_font <- "Roboto Condensed"
df_for_ploting %>%
mutate(BPE = factor(BPE, levels = order_x), Res = factor(Res, levels = Res[7:1])) -> df_odered
df_odered
## # A tibble: 196 x 5
## BPE Res n percent bar_text
## <fct> <fct> <int> <dbl> <chr>
## 1 PSA1 Very Disagree 5 1.1 1.1%
## 2 PSA1 Disagree 17 3.74 3.74%
## 3 PSA1 Quite Disagree 21 4.62 4.62%
## 4 PSA1 Normal 101 22.2 22.2%
## 5 PSA1 Quite Agree 94 20.7 20.66%
## 6 PSA1 Agree 185 40.7 40.66%
## 7 PSA1 Very Agree 32 7.03 7.03%
## 8 PSA2 Very Disagree 12 2.64 2.64%
## 9 PSA2 Disagree 18 3.96 3.96%
## 10 PSA2 Quite Disagree 18 3.96 3.96%
## # ... with 186 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: 28 x 5
## BPE Res n percent bar_text
## <fct> <fct> <int> <dbl> <chr>
## 1 PSA1 Very Disagree 5 1.1 1.1%
## 2 PSA2 Very Disagree 12 2.64 2.64%
## 3 PSA3 Very Disagree 13 2.86 2.86%
## 4 PSA4 Very Disagree 13 2.86 2.86%
## 5 LIN1 Very Disagree 6 1.32 1.32%
## 6 LIN2 Very Disagree 4 0.88 0.88%
## 7 LIN3 Very Disagree 7 1.54 1.54%
## 8 LIN7 Very Disagree 3 0.66 0.66%
## 9 LIN4 Very Disagree 11 2.42 2.42%
## 10 LIN5 Very Disagree 14 3.08 3.08%
## # ... with 18 more rows
# For displaying percent of "Disagree":
df_odered %>%
filter(Res == "Disagree") %>%
filter(percent >= 0) -> df_for_text2
df_for_text2
## # A tibble: 28 x 5
## BPE Res n percent bar_text
## <fct> <fct> <int> <dbl> <chr>
## 1 PSA1 Disagree 17 3.74 3.74%
## 2 PSA2 Disagree 18 3.96 3.96%
## 3 PSA3 Disagree 9 1.98 1.98%
## 4 PSA4 Disagree 13 2.86 2.86%
## 5 LIN1 Disagree 21 4.62 4.62%
## 6 LIN2 Disagree 17 3.74 3.74%
## 7 LIN3 Disagree 21 4.62 4.62%
## 8 LIN7 Disagree 15 3.3 3.3%
## 9 LIN4 Disagree 22 4.84 4.84%
## 10 LIN5 Disagree 45 9.89 9.89%
## # ... with 18 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: 28 x 5
## BPE Res n percent bar_text
## <fct> <fct> <int> <dbl> <chr>
## 1 PSA1 Quite Disagree 21 4.62 4.62%
## 2 PSA2 Quite Disagree 18 3.96 3.96%
## 3 PSA3 Quite Disagree 16 3.52 3.52%
## 4 PSA4 Quite Disagree 19 4.18 4.18%
## 5 LIN1 Quite Disagree 15 3.3 3.3%
## 6 LIN2 Quite Disagree 14 3.08 3.08%
## 7 LIN3 Quite Disagree 10 2.2 2.2%
## 8 LIN7 Quite Disagree 14 3.08 3.08%
## 9 LIN4 Quite Disagree 13 2.86 2.86%
## 10 LIN5 Quite Disagree 19 4.18 4.18%
## # ... with 18 more rows
# For displaying percent of "Normal":
df_odered %>%
filter(Res == "Normal") %>%
filter(percent >= 0) -> df_for_text4
df_for_text4
## # A tibble: 28 x 5
## BPE Res n percent bar_text
## <fct> <fct> <int> <dbl> <chr>
## 1 PSA1 Normal 101 22.2 22.2%
## 2 PSA2 Normal 111 24.4 24.4%
## 3 PSA3 Normal 90 19.8 19.78%
## 4 PSA4 Normal 89 19.6 19.56%
## 5 LIN1 Normal 82 18.0 18.02%
## 6 LIN2 Normal 88 19.3 19.34%
## 7 LIN3 Normal 76 16.7 16.7%
## 8 LIN7 Normal 62 13.6 13.63%
## 9 LIN4 Normal 78 17.1 17.14%
## 10 LIN5 Normal 100 22.0 21.98%
## # ... with 18 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: 28 x 5
## BPE Res n percent bar_text
## <fct> <fct> <int> <dbl> <chr>
## 1 PSA1 Quite Agree 94 20.7 20.66%
## 2 PSA2 Quite Agree 101 22.2 22.2%
## 3 PSA3 Quite Agree 101 22.2 22.2%
## 4 PSA4 Quite Agree 98 21.5 21.54%
## 5 LIN1 Quite Agree 107 23.5 23.52%
## 6 LIN2 Quite Agree 76 16.7 16.7%
## 7 LIN3 Quite Agree 83 18.2 18.24%
## 8 LIN7 Quite Agree 86 18.9 18.9%
## 9 LIN4 Quite Agree 98 21.5 21.54%
## 10 LIN5 Quite Agree 69 15.2 15.16%
## # ... with 18 more rows
# For displaying percent of "Agree":
df_odered %>%
filter(Res == "Agree") %>%
filter(percent >= 0) -> df_for_text6
df_for_text6
## # A tibble: 28 x 5
## BPE Res n percent bar_text
## <fct> <fct> <int> <dbl> <chr>
## 1 PSA1 Agree 185 40.7 40.66%
## 2 PSA2 Agree 163 35.8 35.82%
## 3 PSA3 Agree 191 42.0 41.98%
## 4 PSA4 Agree 190 41.8 41.76%
## 5 LIN1 Agree 190 41.8 41.76%
## 6 LIN2 Agree 215 47.2 47.25%
## 7 LIN3 Agree 208 45.7 45.71%
## 8 LIN7 Agree 221 48.6 48.57%
## 9 LIN4 Agree 180 39.6 39.56%
## 10 LIN5 Agree 156 34.3 34.29%
## # ... with 18 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: 28 x 5
## BPE Res n percent bar_text
## <fct> <fct> <int> <dbl> <chr>
## 1 PSA1 Very Agree 32 7.03 7.03%
## 2 PSA2 Very Agree 32 7.03 7.03%
## 3 PSA3 Very Agree 35 7.69 7.69%
## 4 PSA4 Very Agree 33 7.25 7.25%
## 5 LIN1 Very Agree 34 7.47 7.47%
## 6 LIN2 Very Agree 41 9.01 9.01%
## 7 LIN3 Very Agree 50 11.0 10.99%
## 8 LIN7 Very Agree 54 11.9 11.87%
## 9 LIN4 Very Agree 53 11.6 11.65%
## 10 LIN5 Very Agree 52 11.4 11.43%
## # ... with 18 more rows
# For displaying percent of "Very Agree":
df_odered %>%
filter(Res == "Very Agree") -> df_for_text
df_for_text
## # A tibble: 28 x 5
## BPE Res n percent bar_text
## <fct> <fct> <int> <dbl> <chr>
## 1 PSA1 Very Agree 32 7.03 7.03%
## 2 PSA2 Very Agree 32 7.03 7.03%
## 3 PSA3 Very Agree 35 7.69 7.69%
## 4 PSA4 Very Agree 33 7.25 7.25%
## 5 LIN1 Very Agree 34 7.47 7.47%
## 6 LIN2 Very Agree 41 9.01 9.01%
## 7 LIN3 Very Agree 50 11.0 10.99%
## 8 LIN7 Very Agree 54 11.9 11.87%
## 9 LIN4 Very Agree 53 11.6 11.65%
## 10 LIN5 Very Agree 52 11.4 11.43%
## # ... with 18 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.5. Vẽ biểu đồ likert cho dữ liệu của 2 thành phố theo từng constructs 3.5.1. Construct PSA
# Plot Likert graph for people in both cities for construct PSA
library(tidyverse)
library(compareGroups)
head(DN_HCM_SEM1_PSA)
## Res BPE
## 1 6 PSA1
## 2 3 PSA1
## 3 2 PSA1
## 4 5 PSA1
## 5 2 PSA1
## 6 2 PSA1
dim(DN_HCM_SEM1_PSA)
## [1] 3436 2
attach(DN_HCM_SEM1_PSA)
## The following objects are masked from HCM_SEM1:
##
## BPE, Res
## The following objects are masked from DN_SEM1:
##
## BPE, Res
## The following objects are masked from DN_HCM_SEM1:
##
## BPE, Res
DN_HCM_SEM1_PSA = within(DN_HCM_SEM1_PSA, {
Res = factor(Res, labels = c("Very Disagree", "Disagree", "Quite Disagree", "Normal", "Quite Agree", "Agree", "Very Agree"))
BPE = factor(BPE, labels = c("PSA1", "PSA2", "PSA3", "PSA4"))
})
str(DN_HCM_SEM1_PSA)
## 'data.frame': 3436 obs. of 2 variables:
## $ Res: Factor w/ 7 levels "Very Disagree",..: 6 3 2 5 2 2 1 6 2 4 ...
## $ BPE: Factor w/ 4 levels "PSA1","PSA2",..: 1 1 1 1 1 1 1 1 1 1 ...
summary(DN_HCM_SEM1_PSA)
## Res BPE
## Very Disagree : 145 PSA1:859
## Disagree : 297 PSA2:859
## Quite Disagree: 192 PSA3:859
## Normal : 375 PSA4:859
## Quite Agree : 561
## Agree :1504
## Very Agree : 362
## t <- compareGroups(Res ~ BPE, data = DN_SEM1)
## createTable(t)
DN_HCM_SEM1_PSA %>%
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] PSA4 PSA1 PSA2 PSA3
## Levels: PSA1 PSA2 PSA3 PSA4
# 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 PSA1 Very Disagree 60 6.98 6.98%
## 2 PSA1 Disagree 130 15.1 15.13%
## 3 PSA1 Quite Disagree 54 6.29 6.29%
## 4 PSA1 Normal 78 9.08 9.08%
## 5 PSA1 Quite Agree 127 14.8 14.78%
## 6 PSA1 Agree 329 38.3 38.3%
## 7 PSA1 Very Agree 81 9.43 9.43%
## 8 PSA2 Very Disagree 36 4.19 4.19%
## 9 PSA2 Disagree 65 7.57 7.57%
## 10 PSA2 Quite Disagree 51 5.94 5.94%
## # ... with 18 more rows
library(extrafont)
theme_set(theme_minimal())
gg <- df_odered %>%
ggplot(aes(x = BPE, y = percent, fill = Res)) +
geom_col(width = 0.8) +
coord_flip() +
scale_fill_manual(values = my_colors[7:1], name = "") +
theme(legend.position = "top") +
theme(text = element_text(family = my_font)) +
guides(fill = guide_legend(reverse = TRUE)) +
scale_y_continuous(labels = paste0(seq(0, 100, 25), "%"), expand = c(0, 0)) +
theme(plot.title = element_text(size = 18), plot.subtitle = element_text(size = 11, color = "grey20")) +
theme(axis.text = element_text(color = "grey20", size = 10.2)) +
theme(plot.margin = unit(rep(0.7, 4), "cm")) +
theme(panel.grid.major.y = element_blank(), panel.grid.minor.x = element_blank()) +
theme(legend.key.height = unit(0.15, "mm")) +
labs(x = NULL, y = NULL,
title = "Perceived safety on bus of passengers in urban areas of Viet Nam",
subtitle = "Likert scale is a type of rating scale commonly used in surveys. When responding to a Likert type question,\nrespondents simply state their level of agreement or disagreement on a symmetric agree-disagree scale.")
gg
## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database
## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database
## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database
## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database
## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database
## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database
## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database
## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database
## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database
## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database
## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database
## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database
## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database
# For displaying percent of "Very Disagree": Điều chỉnh percent để thể hiện giá trị của %
df_odered %>%
filter(Res == "Very Disagree") %>%
filter(percent >= 0) -> df_for_text1
df_for_text1
## # A tibble: 4 x 5
## BPE Res n percent bar_text
## <fct> <fct> <int> <dbl> <chr>
## 1 PSA1 Very Disagree 60 6.98 6.98%
## 2 PSA2 Very Disagree 36 4.19 4.19%
## 3 PSA3 Very Disagree 17 1.98 1.98%
## 4 PSA4 Very Disagree 32 3.73 3.73%
# For displaying percent of "Disagree":
df_odered %>%
filter(Res == "Disagree") %>%
filter(percent >= 3) -> df_for_text2
df_for_text2
## # A tibble: 3 x 5
## BPE Res n percent bar_text
## <fct> <fct> <int> <dbl> <chr>
## 1 PSA1 Disagree 130 15.1 15.13%
## 2 PSA2 Disagree 65 7.57 7.57%
## 3 PSA4 Disagree 79 9.2 9.2%
# 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 PSA1 Quite Disagree 54 6.29 6.29%
## 2 PSA2 Quite Disagree 51 5.94 5.94%
## 3 PSA3 Quite Disagree 28 3.26 3.26%
## 4 PSA4 Quite Disagree 59 6.87 6.87%
# 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 PSA1 Normal 78 9.08 9.08%
## 2 PSA2 Normal 86 10.0 10.01%
## 3 PSA3 Normal 66 7.68 7.68%
## 4 PSA4 Normal 145 16.9 16.88%
# 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 PSA1 Quite Agree 127 14.8 14.78%
## 2 PSA2 Quite Agree 126 14.7 14.67%
## 3 PSA3 Quite Agree 148 17.2 17.23%
## 4 PSA4 Quite Agree 160 18.6 18.63%
# 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 PSA1 Agree 329 38.3 38.3%
## 2 PSA2 Agree 400 46.6 46.57%
## 3 PSA3 Agree 470 54.7 54.71%
## 4 PSA4 Agree 305 35.5 35.51%
# 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 PSA1 Very Agree 81 9.43 9.43%
## 2 PSA2 Very Agree 95 11.1 11.06%
## 3 PSA3 Very Agree 107 12.5 12.46%
## 4 PSA4 Very Agree 79 9.2 9.2%
# 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 PSA1 Very Agree 81 9.43 9.43%
## 2 PSA2 Very Agree 95 11.1 11.06%
## 3 PSA3 Very Agree 107 12.5 12.46%
## 4 PSA4 Very Agree 79 9.2 9.2%
# 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.5.2. Construct LIN
# Plot Likert graph for people in both cities for construct LIN
library(tidyverse)
library(compareGroups)
head(DN_HCM_SEM1_LIN)
## Res BPE
## 1 4 LIN1
## 2 4 LIN1
## 3 2 LIN1
## 4 5 LIN1
## 5 4 LIN1
## 6 4 LIN1
dim(DN_HCM_SEM1_LIN)
## [1] 6013 2
attach(DN_HCM_SEM1_LIN)
## The following objects are masked from DN_HCM_SEM1_PSA:
##
## BPE, Res
## The following objects are masked from HCM_SEM1:
##
## BPE, Res
## The following objects are masked from DN_SEM1:
##
## BPE, Res
## The following objects are masked from DN_HCM_SEM1:
##
## BPE, Res
DN_HCM_SEM1_LIN = within(DN_HCM_SEM1_LIN, {
Res = factor(Res, labels = c("Very Disagree", "Disagree", "Quite Disagree", "Normal", "Quite Agree", "Agree", "Very Agree"))
BPE = factor(BPE, labels = c("LIN1", "LIN2", "LIN3", "LIN7", "LIN4", "LIN5", "LIN6"))
})
str(DN_HCM_SEM1_LIN)
## 'data.frame': 6013 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 "LIN1","LIN2",..: 1 1 1 1 1 1 1 1 1 1 ...
summary(DN_HCM_SEM1_LIN)
## Res BPE
## Very Disagree : 65 LIN1:859
## Disagree : 170 LIN2:859
## Quite Disagree: 173 LIN3:859
## Normal : 770 LIN7:859
## Quite Agree :1232 LIN4:859
## Agree :2682 LIN5:859
## Very Agree : 921 LIN6:859
## t <- compareGroups(Res ~ BPE, data = DN_SEM1)
## createTable(t)
DN_HCM_SEM1_LIN %>%
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] LIN1 LIN6 LIN2 LIN4 LIN7 LIN3 LIN5
## Levels: LIN1 LIN2 LIN3 LIN7 LIN4 LIN5 LIN6
# 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 LIN1 Very Disagree 4 0.47 0.47%
## 2 LIN1 Disagree 19 2.21 2.21%
## 3 LIN1 Quite Disagree 19 2.21 2.21%
## 4 LIN1 Normal 115 13.4 13.39%
## 5 LIN1 Quite Agree 163 19.0 18.98%
## 6 LIN1 Agree 432 50.3 50.29%
## 7 LIN1 Very Agree 107 12.5 12.46%
## 8 LIN2 Very Disagree 7 0.81 0.81%
## 9 LIN2 Disagree 22 2.56 2.56%
## 10 LIN2 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 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 LIN1 Very Disagree 4 0.47 0.47%
## 2 LIN2 Very Disagree 7 0.81 0.81%
## 3 LIN3 Very Disagree 3 0.35 0.35%
## 4 LIN7 Very Disagree 11 1.28 1.28%
## 5 LIN4 Very Disagree 15 1.75 1.75%
## 6 LIN5 Very Disagree 13 1.51 1.51%
## 7 LIN6 Very Disagree 12 1.4 1.4%
# 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 LIN4 Disagree 57 6.64 6.64%
# 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 LIN1 Quite Disagree 19 2.21 2.21%
## 2 LIN2 Quite Disagree 16 1.86 1.86%
## 3 LIN3 Quite Disagree 18 2.1 2.1%
## 4 LIN7 Quite Disagree 23 2.68 2.68%
## 5 LIN4 Quite Disagree 51 5.94 5.94%
## 6 LIN5 Quite Disagree 17 1.98 1.98%
## 7 LIN6 Quite Disagree 29 3.38 3.38%
# 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 LIN1 Normal 115 13.4 13.39%
## 2 LIN2 Normal 99 11.5 11.53%
## 3 LIN3 Normal 92 10.7 10.71%
## 4 LIN7 Normal 111 12.9 12.92%
## 5 LIN4 Normal 142 16.5 16.53%
## 6 LIN5 Normal 80 9.31 9.31%
## 7 LIN6 Normal 131 15.2 15.25%
# 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 LIN1 Quite Agree 163 19.0 18.98%
## 2 LIN2 Quite Agree 167 19.4 19.44%
## 3 LIN3 Quite Agree 157 18.3 18.28%
## 4 LIN7 Quite Agree 211 24.6 24.56%
## 5 LIN4 Quite Agree 168 19.6 19.56%
## 6 LIN5 Quite Agree 156 18.2 18.16%
## 7 LIN6 Quite Agree 210 24.4 24.45%
# 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 LIN1 Agree 432 50.3 50.29%
## 2 LIN2 Agree 427 49.7 49.71%
## 3 LIN3 Agree 439 51.1 51.11%
## 4 LIN7 Agree 347 40.4 40.4%
## 5 LIN4 Agree 296 34.5 34.46%
## 6 LIN5 Agree 401 46.7 46.68%
## 7 LIN6 Agree 340 39.6 39.58%
# 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 LIN1 Very Agree 107 12.5 12.46%
## 2 LIN2 Very Agree 121 14.1 14.09%
## 3 LIN3 Very Agree 134 15.6 15.6%
## 4 LIN7 Very Agree 133 15.5 15.48%
## 5 LIN4 Very Agree 130 15.1 15.13%
## 6 LIN5 Very Agree 177 20.6 20.61%
## 7 LIN6 Very Agree 119 13.8 13.85%
# 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 LIN1 Very Agree 107 12.5 12.46%
## 2 LIN2 Very Agree 121 14.1 14.09%
## 3 LIN3 Very Agree 134 15.6 15.6%
## 4 LIN7 Very Agree 133 15.5 15.48%
## 5 LIN4 Very Agree 130 15.1 15.13%
## 6 LIN5 Very Agree 177 20.6 20.61%
## 7 LIN6 Very Agree 119 13.8 13.85%
# 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.5.3. Construct IMA
# Plot Likert graph for people in both cities for construct IMA
library(tidyverse)
library(compareGroups)
head(DN_HCM_SEM1_IMA)
## Res BPE
## 1 6 IMA1
## 2 4 IMA1
## 3 4 IMA1
## 4 5 IMA1
## 5 5 IMA1
## 6 4 IMA1
dim(DN_HCM_SEM1_IMA)
## [1] 4295 2
attach(DN_HCM_SEM1_IMA)
## The following objects are masked from DN_HCM_SEM1_LIN:
##
## BPE, Res
## The following objects are masked from DN_HCM_SEM1_PSA:
##
## BPE, Res
## The following objects are masked from HCM_SEM1:
##
## BPE, Res
## The following objects are masked from DN_SEM1:
##
## BPE, Res
## The following objects are masked from DN_HCM_SEM1:
##
## BPE, Res
DN_HCM_SEM1_IMA = within(DN_HCM_SEM1_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_SEM1_IMA)
## 'data.frame': 4295 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_SEM1_IMA)
## Res BPE
## Very Disagree : 50 IMA1:859
## Disagree : 81 IMA2:859
## Quite Disagree: 125 IMA3:859
## Normal : 658 IMA4:859
## Quite Agree :1046 IMA5:859
## Agree :1953
## Very Agree : 382
## t <- compareGroups(Res ~ BPE, data = DN_SEM1)
## createTable(t)
DN_HCM_SEM1_IMA %>%
group_by(BPE, Res) %>%
count() %>%
ungroup() %>%
group_by(BPE) %>%
mutate(percent = 100*n / sum(n)) %>%
mutate(percent = round(percent, 2)) %>%
mutate(bar_text = paste0(percent, "%")) %>%
ungroup() -> df_for_ploting
df_for_ploting %>%
filter(Res == Res[7]) %>%
arrange(percent) %>% # sắp xếp theo %
pull(BPE) -> order_x
order_x
## [1] IMA1 IMA2 IMA3 IMA4 IMA5
## Levels: IMA1 IMA2 IMA3 IMA4 IMA5
# Make a draft plot:
my_colors <- c("#3e6487", "#829cb2", "pink", "pink3", "palevioletred", "rosybrown2", "rosybrown3")
my_font <- "Roboto Condensed"
df_for_ploting %>%
mutate(BPE = factor(BPE, levels = order_x), Res = factor(Res, levels = Res[7:1])) -> df_odered
df_odered
## # A tibble: 35 x 5
## BPE Res n percent bar_text
## <fct> <fct> <int> <dbl> <chr>
## 1 IMA1 Very Disagree 6 0.7 0.7%
## 2 IMA1 Disagree 20 2.33 2.33%
## 3 IMA1 Quite Disagree 32 3.73 3.73%
## 4 IMA1 Normal 155 18.0 18.04%
## 5 IMA1 Quite Agree 228 26.5 26.54%
## 6 IMA1 Agree 353 41.1 41.09%
## 7 IMA1 Very Agree 65 7.57 7.57%
## 8 IMA2 Very Disagree 12 1.4 1.4%
## 9 IMA2 Disagree 18 2.1 2.1%
## 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 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 12 1.4 1.4%
## 3 IMA3 Very Disagree 13 1.51 1.51%
## 4 IMA4 Very Disagree 13 1.51 1.51%
## 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 27 3.14 3.14%
## 5 IMA5 Quite Disagree 21 2.44 2.44%
# 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.0 18.04%
## 2 IMA2 Normal 157 18.3 18.28%
## 3 IMA3 Normal 129 15.0 15.02%
## 4 IMA4 Normal 112 13.0 13.04%
## 5 IMA5 Normal 105 12.2 12.22%
# 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 228 26.5 26.54%
## 2 IMA2 Quite Agree 213 24.8 24.8%
## 3 IMA3 Quite Agree 205 23.9 23.86%
## 4 IMA4 Quite Agree 199 23.2 23.17%
## 5 IMA5 Quite Agree 201 23.4 23.4%
# 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 353 41.1 41.09%
## 2 IMA2 Agree 368 42.8 42.84%
## 3 IMA3 Agree 404 47.0 47.03%
## 4 IMA4 Agree 409 47.6 47.61%
## 5 IMA5 Agree 419 48.8 48.78%
# 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.57 7.57%
## 2 IMA2 Very Agree 66 7.68 7.68%
## 3 IMA3 Very Agree 79 9.2 9.2%
## 4 IMA4 Very Agree 86 10.0 10.01%
## 5 IMA5 Very Agree 86 10.0 10.01%
# 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.57 7.57%
## 2 IMA2 Very Agree 66 7.68 7.68%
## 3 IMA3 Very Agree 79 9.2 9.2%
## 4 IMA4 Very Agree 86 10.0 10.01%
## 5 IMA5 Very Agree 86 10.0 10.01%
# 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.5.4. Construct PHB
# Plot Likert graph for people in both cities for construct PHB
library(tidyverse)
library(compareGroups)
head(DN_HCM_SEM1_PHB)
## Res BPE
## 1 6 PHB1
## 2 3 PHB1
## 3 5 PHB1
## 4 5 PHB1
## 5 5 PHB1
## 6 4 PHB1
dim(DN_HCM_SEM1_PHB)
## [1] 4295 2
attach(DN_HCM_SEM1_PHB)
## The following objects are masked from DN_HCM_SEM1_IMA:
##
## BPE, Res
## The following objects are masked from DN_HCM_SEM1_LIN:
##
## BPE, Res
## The following objects are masked from DN_HCM_SEM1_PSA:
##
## BPE, Res
## The following objects are masked from HCM_SEM1:
##
## BPE, Res
## The following objects are masked from DN_SEM1:
##
## BPE, Res
## The following objects are masked from DN_HCM_SEM1:
##
## BPE, Res
DN_HCM_SEM1_PHB = within(DN_HCM_SEM1_PHB, {
Res = factor(Res, labels = c("Very Disagree", "Disagree", "Quite Disagree", "Normal", "Quite Agree", "Agree", "Very Agree"))
BPE = factor(BPE, labels = c("PHB1", "PHB2", "PHB5", "PHB3", "PHB4"))
})
str(DN_HCM_SEM1_PHB)
## 'data.frame': 4295 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_SEM1_PHB)
## Res BPE
## Very Disagree : 94 PHB1:859
## Disagree : 73 PHB2:859
## Quite Disagree: 111 PHB5:859
## Normal : 372 PHB3:859
## Quite Agree : 798 PHB4:859
## Agree :1924
## Very Agree : 923
## t <- compareGroups(Res ~ BPE, data = DN_SEM1)
## createTable(t)
DN_HCM_SEM1_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 PHB4 PHB2 PHB3 PHB5
## Levels: PHB1 PHB2 PHB5 PHB3 PHB4
# 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 26 3.03 3.03%
## 2 PHB1 Disagree 18 2.1 2.1%
## 3 PHB1 Quite Disagree 37 4.31 4.31%
## 4 PHB1 Normal 97 11.3 11.29%
## 5 PHB1 Quite Agree 215 25.0 25.03%
## 6 PHB1 Agree 351 40.9 40.86%
## 7 PHB1 Very Agree 115 13.4 13.39%
## 8 PHB2 Very Disagree 14 1.63 1.63%
## 9 PHB2 Disagree 22 2.56 2.56%
## 10 PHB2 Quite Disagree 24 2.79 2.79%
## # ... 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 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 26 3.03 3.03%
## 2 PHB2 Very Disagree 14 1.63 1.63%
## 3 PHB5 Very Disagree 15 1.75 1.75%
## 4 PHB3 Very Disagree 23 2.68 2.68%
## 5 PHB4 Very Disagree 16 1.86 1.86%
# For displaying percent of "Disagree":
df_odered %>%
filter(Res == "Disagree") %>%
filter(percent >= 3) -> df_for_text2
df_for_text2
## # A tibble: 0 x 5
## # ... with 5 variables: BPE <fct>, Res <fct>, n <int>, percent <dbl>,
## # bar_text <chr>
# For displaying percent of "Quite Disagree":
df_odered %>%
filter(Res == "Quite Disagree") %>%
filter(percent >= 0) -> df_for_text3
df_for_text3
## # A tibble: 5 x 5
## BPE Res n percent bar_text
## <fct> <fct> <int> <dbl> <chr>
## 1 PHB1 Quite Disagree 37 4.31 4.31%
## 2 PHB2 Quite Disagree 24 2.79 2.79%
## 3 PHB5 Quite Disagree 10 1.16 1.16%
## 4 PHB3 Quite Disagree 4 0.47 0.47%
## 5 PHB4 Quite Disagree 36 4.19 4.19%
# For displaying percent of "Normal":
df_odered %>%
filter(Res == "Normal") %>%
filter(percent >= 0) -> df_for_text4
df_for_text4
## # A tibble: 5 x 5
## BPE Res n percent bar_text
## <fct> <fct> <int> <dbl> <chr>
## 1 PHB1 Normal 97 11.3 11.29%
## 2 PHB2 Normal 69 8.03 8.03%
## 3 PHB5 Normal 53 6.17 6.17%
## 4 PHB3 Normal 64 7.45 7.45%
## 5 PHB4 Normal 89 10.4 10.36%
# 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.0 25.03%
## 2 PHB2 Quite Agree 164 19.1 19.09%
## 3 PHB5 Quite Agree 131 15.2 15.25%
## 4 PHB3 Quite Agree 114 13.3 13.27%
## 5 PHB4 Quite Agree 174 20.3 20.26%
# 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.86%
## 2 PHB2 Agree 378 44 44%
## 3 PHB5 Agree 391 45.5 45.52%
## 4 PHB3 Agree 418 48.7 48.66%
## 5 PHB4 Agree 386 44.9 44.94%
# 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 115 13.4 13.39%
## 2 PHB2 Very Agree 188 21.9 21.89%
## 3 PHB5 Very Agree 252 29.3 29.34%
## 4 PHB3 Very Agree 228 26.5 26.54%
## 5 PHB4 Very Agree 140 16.3 16.3%
# 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 115 13.4 13.39%
## 2 PHB2 Very Agree 188 21.9 21.89%
## 3 PHB5 Very Agree 252 29.3 29.34%
## 4 PHB3 Very Agree 228 26.5 26.54%
## 5 PHB4 Very Agree 140 16.3 16.3%
# 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.5.5. Construct PGV
# Plot Likert graph for people in both cities for construct PGV
library(tidyverse)
library(compareGroups)
head(DN_HCM_SEM1_PGV)
## Res BPE
## 1 4 PGV1
## 2 5 PGV1
## 3 6 PGV1
## 4 5 PGV1
## 5 6 PGV1
## 6 7 PGV1
dim(DN_HCM_SEM1_PGV)
## [1] 3436 2
attach(DN_HCM_SEM1_PGV)
## The following objects are masked from DN_HCM_SEM1_PHB:
##
## BPE, Res
## The following objects are masked from DN_HCM_SEM1_IMA:
##
## BPE, Res
## The following objects are masked from DN_HCM_SEM1_LIN:
##
## BPE, Res
## The following objects are masked from DN_HCM_SEM1_PSA:
##
## BPE, Res
## The following objects are masked from HCM_SEM1:
##
## BPE, Res
## The following objects are masked from DN_SEM1:
##
## BPE, Res
## The following objects are masked from DN_HCM_SEM1:
##
## BPE, Res
DN_HCM_SEM1_PGV = within(DN_HCM_SEM1_PGV, {
Res = factor(Res, labels = c("Very Disagree", "Disagree", "Quite Disagree", "Normal", "Quite Agree", "Agree", "Very Agree"))
BPE = factor(BPE, labels = c("PGV1", "PGV2", "PGV3", "PGV4"))
})
str(DN_HCM_SEM1_PGV)
## 'data.frame': 3436 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 "PGV1","PGV2",..: 1 1 1 1 1 1 1 1 1 1 ...
summary(DN_HCM_SEM1_PGV)
## Res BPE
## Very Disagree : 104 PGV1:859
## Disagree : 61 PGV2:859
## Quite Disagree: 70 PGV3:859
## Normal : 298 PGV4:859
## Quite Agree : 629
## Agree :1464
## Very Agree : 810
## t <- compareGroups(Res ~ BPE, data = DN_SEM1)
## createTable(t)
DN_HCM_SEM1_PGV %>%
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] PGV4 PGV3 PGV2 PGV1
## Levels: PGV1 PGV2 PGV3 PGV4
# 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 PGV1 Very Disagree 26 3.03 3.03%
## 2 PGV1 Disagree 10 1.16 1.16%
## 3 PGV1 Quite Disagree 13 1.51 1.51%
## 4 PGV1 Normal 59 6.87 6.87%
## 5 PGV1 Quite Agree 124 14.4 14.44%
## 6 PGV1 Agree 391 45.5 45.52%
## 7 PGV1 Very Agree 236 27.5 27.47%
## 8 PGV2 Very Disagree 27 3.14 3.14%
## 9 PGV2 Disagree 15 1.75 1.75%
## 10 PGV2 Quite Disagree 18 2.1 2.1%
## # ... 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 values 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 PGV1 Very Disagree 26 3.03 3.03%
## 2 PGV2 Very Disagree 27 3.14 3.14%
## 3 PGV3 Very Disagree 26 3.03 3.03%
## 4 PGV4 Very Disagree 25 2.91 2.91%
# 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 PGV1 Quite Disagree 13 1.51 1.51%
## 2 PGV2 Quite Disagree 18 2.1 2.1%
## 3 PGV3 Quite Disagree 19 2.21 2.21%
## 4 PGV4 Quite Disagree 20 2.33 2.33%
# For displaying percent of "Normal":
df_odered %>%
filter(Res == "Normal") %>%
filter(percent >= 0) -> df_for_text4
df_for_text4
## # A tibble: 4 x 5
## BPE Res n percent bar_text
## <fct> <fct> <int> <dbl> <chr>
## 1 PGV1 Normal 59 6.87 6.87%
## 2 PGV2 Normal 68 7.92 7.92%
## 3 PGV3 Normal 77 8.96 8.96%
## 4 PGV4 Normal 94 10.9 10.94%
# 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 PGV1 Quite Agree 124 14.4 14.44%
## 2 PGV2 Quite Agree 171 19.9 19.91%
## 3 PGV3 Quite Agree 167 19.4 19.44%
## 4 PGV4 Quite Agree 167 19.4 19.44%
# 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 PGV1 Agree 391 45.5 45.52%
## 2 PGV2 Agree 357 41.6 41.56%
## 3 PGV3 Agree 356 41.4 41.44%
## 4 PGV4 Agree 360 41.9 41.91%
# 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 PGV1 Very Agree 236 27.5 27.47%
## 2 PGV2 Very Agree 203 23.6 23.63%
## 3 PGV3 Very Agree 195 22.7 22.7%
## 4 PGV4 Very Agree 176 20.5 20.49%
# 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 PGV1 Very Agree 236 27.5 27.47%
## 2 PGV2 Very Agree 203 23.6 23.63%
## 3 PGV3 Very Agree 195 22.7 22.7%
## 4 PGV4 Very Agree 176 20.5 20.49%
# 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.5.6. Construct PVA
# Plot Likert graph for people in both cities for construct PVA
library(tidyverse)
library(compareGroups)
head(DN_HCM_SEM1_PVA)
## Res BPE
## 1 6 PVA1
## 2 5 PVA1
## 3 6 PVA1
## 4 5 PVA1
## 5 6 PVA1
## 6 6 PVA1
dim(DN_HCM_SEM1_PVA)
## [1] 2577 2
attach(DN_HCM_SEM1_PVA)
## The following objects are masked from DN_HCM_SEM1_PGV:
##
## BPE, Res
## The following objects are masked from DN_HCM_SEM1_PHB:
##
## BPE, Res
## The following objects are masked from DN_HCM_SEM1_IMA:
##
## BPE, Res
## The following objects are masked from DN_HCM_SEM1_LIN:
##
## BPE, Res
## The following objects are masked from DN_HCM_SEM1_PSA:
##
## BPE, Res
## The following objects are masked from HCM_SEM1:
##
## BPE, Res
## The following objects are masked from DN_SEM1:
##
## BPE, Res
## The following objects are masked from DN_HCM_SEM1:
##
## BPE, Res
DN_HCM_SEM1_PVA = within(DN_HCM_SEM1_PVA, {
Res = factor(Res, labels = c("Very Disagree", "Disagree", "Quite Disagree", "Normal", "Quite Agree", "Agree", "Very Agree"))
BPE = factor(BPE, labels = c("PVA1", "PVA2", "PVA3"))
})
str(DN_HCM_SEM1_PVA)
## 'data.frame': 2577 obs. of 2 variables:
## $ Res: Factor w/ 7 levels "Very Disagree",..: 6 5 6 5 6 6 6 6 6 6 ...
## $ BPE: Factor w/ 3 levels "PVA1","PVA2",..: 1 1 1 1 1 1 1 1 1 1 ...
summary(DN_HCM_SEM1_PVA)
## Res BPE
## Very Disagree : 11 PVA1:859
## Disagree : 48 PVA2:859
## Quite Disagree: 77 PVA3:859
## Normal : 230
## Quite Agree : 474
## Agree :1176
## Very Agree : 561
## t <- compareGroups(Res ~ BPE, data = DN_SEM1)
## createTable(t)
DN_HCM_SEM1_PVA %>%
group_by(BPE, Res) %>%
count() %>%
ungroup() %>%
group_by(BPE) %>%
mutate(percent = 100*n / sum(n)) %>%
mutate(percent = round(percent, 2)) %>%
mutate(bar_text = paste0(percent, "%")) %>%
ungroup() -> df_for_ploting
df_for_ploting %>%
filter(Res == Res[7]) %>%
arrange(percent) %>% # sắp xếp theo %
pull(BPE) -> order_x
order_x
## [1] PVA2 PVA3 PVA1
## Levels: PVA1 PVA2 PVA3
# Make a draft plot:
my_colors <- c("#3e6487", "#829cb2", "pink", "pink3", "palevioletred", "rosybrown2", "rosybrown3")
my_font <- "Roboto Condensed"
df_for_ploting %>%
mutate(BPE = factor(BPE, levels = order_x), Res = factor(Res, levels = Res[7:1])) -> df_odered
df_odered
## # A tibble: 21 x 5
## BPE Res n percent bar_text
## <fct> <fct> <int> <dbl> <chr>
## 1 PVA1 Very Disagree 5 0.580 0.58%
## 2 PVA1 Disagree 9 1.05 1.05%
## 3 PVA1 Quite Disagree 18 2.1 2.1%
## 4 PVA1 Normal 59 6.87 6.87%
## 5 PVA1 Quite Agree 126 14.7 14.67%
## 6 PVA1 Agree 416 48.4 48.43%
## 7 PVA1 Very Agree 226 26.3 26.31%
## 8 PVA2 Very Disagree 4 0.47 0.47%
## 9 PVA2 Disagree 26 3.03 3.03%
## 10 PVA2 Quite Disagree 38 4.42 4.42%
## # ... with 11 more rows
library(extrafont)
theme_set(theme_minimal())
gg <- df_odered %>%
ggplot(aes(x = BPE, y = percent, fill = Res)) +
geom_col(width = 0.8) +
coord_flip() +
scale_fill_manual(values = my_colors[7:1], name = "") +
theme(legend.position = "top") +
theme(text = element_text(family = my_font)) +
guides(fill = guide_legend(reverse = TRUE)) +
scale_y_continuous(labels = paste0(seq(0, 100, 25), "%"), expand = c(0, 0)) +
theme(plot.title = element_text(size = 18), plot.subtitle = element_text(size = 11, color = "grey20")) +
theme(axis.text = element_text(color = "grey20", size = 10.2)) +
theme(plot.margin = unit(rep(0.7, 4), "cm")) +
theme(panel.grid.major.y = element_blank(), panel.grid.minor.x = element_blank()) +
theme(legend.key.height = unit(0.15, "mm")) +
labs(x = NULL, y = NULL,
title = "Perceived values towards urban bus systems of Viet Nam",
subtitle = "Likert scale is a type of rating scale commonly used in surveys. When responding to a Likert type question,\nrespondents simply state their level of agreement or disagreement on a symmetric agree-disagree scale.")
gg
## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database
## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database
## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database
## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database
## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database
## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database
## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database
## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database
## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database
## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database
## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database
## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database
## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database
# For displaying percent of "Very Disagree": Điều chỉnh percent để thể hiện giá trị của %
df_odered %>%
filter(Res == "Very Disagree") %>%
filter(percent >= 0) -> df_for_text1
df_for_text1
## # A tibble: 3 x 5
## BPE Res n percent bar_text
## <fct> <fct> <int> <dbl> <chr>
## 1 PVA1 Very Disagree 5 0.580 0.58%
## 2 PVA2 Very Disagree 4 0.47 0.47%
## 3 PVA3 Very Disagree 2 0.23 0.23%
# For displaying percent of "Disagree":
df_odered %>%
filter(Res == "Disagree") %>%
filter(percent >= 3) -> df_for_text2
df_for_text2
## # A tibble: 1 x 5
## BPE Res n percent bar_text
## <fct> <fct> <int> <dbl> <chr>
## 1 PVA2 Disagree 26 3.03 3.03%
# For displaying percent of "Quite Disagree":
df_odered %>%
filter(Res == "Quite Disagree") %>%
filter(percent >= 0) -> df_for_text3
df_for_text3
## # A tibble: 3 x 5
## BPE Res n percent bar_text
## <fct> <fct> <int> <dbl> <chr>
## 1 PVA1 Quite Disagree 18 2.1 2.1%
## 2 PVA2 Quite Disagree 38 4.42 4.42%
## 3 PVA3 Quite Disagree 21 2.44 2.44%
# For displaying percent of "Normal":
df_odered %>%
filter(Res == "Normal") %>%
filter(percent >= 0) -> df_for_text4
df_for_text4
## # A tibble: 3 x 5
## BPE Res n percent bar_text
## <fct> <fct> <int> <dbl> <chr>
## 1 PVA1 Normal 59 6.87 6.87%
## 2 PVA2 Normal 102 11.9 11.87%
## 3 PVA3 Normal 69 8.03 8.03%
# For displaying percent of "Quite Agree":
df_odered %>%
filter(Res == "Quite Agree") %>%
filter(percent >= 0) -> df_for_text5
df_for_text5
## # A tibble: 3 x 5
## BPE Res n percent bar_text
## <fct> <fct> <int> <dbl> <chr>
## 1 PVA1 Quite Agree 126 14.7 14.67%
## 2 PVA2 Quite Agree 193 22.5 22.47%
## 3 PVA3 Quite Agree 155 18.0 18.04%
# For displaying percent of "Agree":
df_odered %>%
filter(Res == "Agree") %>%
filter(percent >= 0) -> df_for_text6
df_for_text6
## # A tibble: 3 x 5
## BPE Res n percent bar_text
## <fct> <fct> <int> <dbl> <chr>
## 1 PVA1 Agree 416 48.4 48.43%
## 2 PVA2 Agree 344 40.0 40.05%
## 3 PVA3 Agree 416 48.4 48.43%
# For displaying percent of "Very Agree":
df_odered %>%
filter(Res == "Very Agree") %>%
filter(percent >= 0) -> df_for_text7 # Chỉ thể hiện giá trị có % lựa chọn >0
df_for_text7
## # A tibble: 3 x 5
## BPE Res n percent bar_text
## <fct> <fct> <int> <dbl> <chr>
## 1 PVA1 Very Agree 226 26.3 26.31%
## 2 PVA2 Very Agree 152 17.7 17.69%
## 3 PVA3 Very Agree 183 21.3 21.3%
# For displaying percent of "Very Agree":
df_odered %>%
filter(Res == "Very Agree") -> df_for_text
df_for_text
## # A tibble: 3 x 5
## BPE Res n percent bar_text
## <fct> <fct> <int> <dbl> <chr>
## 1 PVA1 Very Agree 226 26.3 26.31%
## 2 PVA2 Very Agree 152 17.7 17.69%
## 3 PVA3 Very Agree 183 21.3 21.3%
# 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