d <- read.csv("D:/sfuvault/Interact Tasks/Victoria Survey Descriptives/Data/Victoria_health_q_data_COPY.csv")
  • There are a total of 286 Participants in this survey.
  • Some participants have NA values in their question responses. These are denoted as “NA” in summaries.

Section 1: Transportation

Q1:How many bicycles are kept in your household?

Adult bikes

ggplot(d, aes(x = d$Q1_transp_bikes_adults)) + geom_bar(na.rm = TRUE) + xlab("Number of bicycles for adults")

summary(d$Q1_transp_bikes_adults)
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##   1.000   2.000   3.000   3.294   4.000  20.000

Children bikes

ggplot(d, aes(x = d$Q1_transp_bikes_children)) + geom_bar(na.rm = TRUE) + xlab("Number of bicycles for children") + scale_x_continuous()

summary(d$Q1_transp_bikes_children)
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##  0.0000  0.0000  0.0000  0.6538  1.0000 10.0000

Q2:On a scale of 1 to 5, with 1 being ‘very safe’ and 5 being ‘very dangerous’, overall, how safe do you think cycling is in your city?

t1 <- prop.table(table(factor(d$Q2_bike_safety, levels = 1:5)))*100
t1 <- as.data.frame(t1)
t1$group <- substring(row.names(t1), 1)
t1$group <- revalue(as.character(t1$group), c("1" = "Very safe", "2" = "Somewhat safe", "3" = "Neither safe nor unsafe", "4" = "Somewhat dangerous", "5" = "Very dangerous"))
t1$plot <- factor(t1$group, t1$group)


p <- ggplot(t1, aes(x=group, y=Freq, fill=group)) + theme(axis.text.x  = element_text(angle=90, vjust=.6)) #order responses as in t1


p + geom_bar(aes(x = plot), data = t1, stat = "identity", colour="black") +
  scale_fill_brewer(palette = "YlGn", direction=1) +
  guides(fill=FALSE)+
      ylab("Percent of total") +
      xlab("Perception of bicycle risk") +
      ggtitle("Overall, how safe do you think cycling is in your city?")

t1.tb <- as.factor(d$Q2_bike_safety)
t1.tb <- summary(t1.tb)
t1.tb <- as.data.frame(t1.tb)
t1.tb$Var1 <- substring(row.names(t1.tb), 1)
t1.tb$group <- revalue(as.character(t1.tb$Var1), c("1" = "Very safe", "2" = "Somewhat safe", "3" = "Neither safe nor unsafe", "4" = "Somewhat dangerous", "5" = "Very dangerous"))
plot.t1 <- merge(t1, t1.tb, by = "group")
plot.t1 <- plot.t1[-c(2, 4, 6)]
plot.t1 <- setcolorder(plot.t1, c("group", "t1.tb", "Freq"))
plot.t1$order <- c(3, 4, 2, 5, 1)
plot.t1 <- plot.t1 %>% arrange(order)
plot.t1 <- plot.t1[-c(4)]
colnames(plot.t1) <- c("Response", "N", "Proportion")

kable(plot.t1)
Response N Proportion
Very safe 23 8.041958
Somewhat safe 168 58.741259
Neither safe nor unsafe 34 11.888112
Somewhat dangerous 56 19.580420
Very dangerous 5 1.748252

Q3: How often do you typically travel by bicycle during each season?

fall

t2 <- prop.table(table(factor(d$Q3_freq_fall, levels = 0:7)))*100
t2 <- as.data.frame(t2)
t2$days <- substring(row.names(t2), 1)
t2$days <- revalue(as.character(t2$days), c("1" = "0",  "2" = "1", "3" = "2", "4" = "3", "5" = "4", "6" = "5", "7" = "6", "8" = "7"))
t2$plot <- factor(t2$days, t2$days)

p2 <- ggplot(t2, aes(x = days, y = Freq, fill = days)) + theme(axis.text.x  = element_text(angle=90, vjust=.6)) #order responses as in t2

p2 + geom_bar(aes(x = plot), data = t2, stat = "identity", colour="black") +
  guides(fill = FALSE) +
  scale_fill_brewer(palette = "BuGn") +
      ylab("Percent of total") +
      xlab("Bicycling number of days per week") +
      ggtitle("How often do you typically travel by bicycle during the fall?")

summary(d$Q3_freq_fall)
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##   0.000   3.250   5.000   4.629   6.000   7.000

winter

t3 <- prop.table(table(factor(d$Q3_freq_winter, levels = 0:7)))*100
t3 <- as.data.frame(t3)
t3$days <- substring(row.names(t3), 1)
t3$days <- revalue(as.character(t3$days), c("1" = "0",  "2" = "1", "3" = "2", "4" = "3", "5" = "4", "6" = "5", "7" = "6", "8" = "7"))
t3$plot <- factor(t3$days, t3$days)

p3 <- ggplot(t3, aes(x = days, y = Freq, fill = days)) + theme(axis.text.x  = element_text(angle=90, vjust=.6)) #order responses as in t3

p3 + geom_bar(aes(x = plot), data = t3, stat = "identity", colour="black") +
  guides(fill = FALSE) +
  scale_fill_brewer(palette = "BuGn", direction=-1) +
      ylab("Percent of total") +
      xlab("Bicycling number of days per week") +
      ggtitle("How often do you typically travel by bicycle during the winter?")

summary(d$Q3_freq_winter)
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##   0.000   2.000   4.000   3.675   5.000   7.000

spring

t4 <- prop.table(table(factor(d$Q3_freq_spring, levels = 0:7)))*100
t4 <- as.data.frame(t4)
t4$days <- substring(row.names(t4), 1)
t4$days <- revalue(as.character(t4$days), c("1" = "0",  "2" = "1", "3" = "2", "4" = "3", "5" = "4", "6" = "5", "7" = "6", "8" = "7"))
t4$plot <- factor(t4$days, t4$days)

p4 <- ggplot(t4, aes(x = days, y = Freq, fill = days)) + theme(axis.text.x  = element_text(angle=90, vjust=.6)) #order responses as in t4

p4 + geom_bar(aes(x = plot), data = t4, stat = "identity", colour="black") +
  guides(fill = FALSE) +
  scale_fill_brewer(palette = "BuGn", direction=-1) +
      ylab("Percent of total") +
      xlab("Bicycling number of days per week") +
      ggtitle("How often do you typically travel by bicycle during the winter?")

summary(d$Q3_freq_spring)
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##   0.000   4.000   5.000   4.825   6.000   7.000

summer

t5 <- prop.table(table(factor(d$Q3_freq_summer, levels = 0:7)))*100
t5 <- as.data.frame(t5)
t5$days <- substring(row.names(t5), 1)
t5$days <- revalue(as.character(t5$days), c("1" = "0",  "2" = "1", "3" = "2", "4" = "3", "5" = "4", "6" = "5", "7" = "6", "8" = "7"))
t5$plot <- factor(t5$days, t5$days)

p4 <- ggplot(t5, aes(x = days, y = Freq, fill = days)) + theme(axis.text.x  = element_text(angle=90, vjust=.6)) #order responses as in t5

p4 + geom_bar(aes(x = plot), data = t5, stat = "identity", colour="black") +
  guides(fill = FALSE) +
  scale_fill_brewer(palette = "BuGn", direction=-1) +
      ylab("Percent of total") +
      xlab("Bicycling number of days per week") +
      ggtitle("How often do you typically travel by bicycle during the winter?")

summary(d$Q3_freq_summer)
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##   0.000   5.000   5.000   5.217   6.000   7.000

Q4: How often are your cycling trips made with children?

bike.ch <- prop.table(table(factor(d$Q4_bike_children, levels = 1:4)))*100
bike.ch <- as.data.frame(bike.ch)
bike.ch$group <- substring(row.names(bike.ch), 1)
bike.ch$group <- revalue(as.character(bike.ch$group), c("1" = "Never", "2" = "Sometimes", "3" = "Often", "4" = "Always"))

bike.ch$plot <- factor(bike.ch$group, bike.ch$group)

ch <- ggplot(bike.ch, aes(x = group, y = Freq, fill = group)) + theme(axis.text.x  = element_text(angle=90, vjust=.6)) #order responses as in t5

cols <- c(rev(brewer.pal(4,"RdYlGn")),"grey")
ch + geom_bar(aes(x = plot), data = bike.ch, stat = "identity", colour="black") +
  guides(fill = FALSE) +
  scale_fill_manual(values = cols) +
      ylab("Percent of total") +
      xlab("Bicyle trips with children") +
      ggtitle("How often are your cycling trips made with children?")

trips.ch <- as.factor(d$Q4_bike_children)
trips.ch <- summary(trips.ch)
trips.ch <- as.data.frame(trips.ch)
trips.ch$Var1 <- substring(row.names(trips.ch), 1)
trips.ch$group <- revalue(as.character(trips.ch$Var1), c("1" = "Never", "2" = "Sometimes", "3" = "Often", "4" = "Always"))
plot.ch <- merge(bike.ch, trips.ch, by = "group")
plot.ch <- plot.ch[-c(1:2, 6)]
plot.ch <- setcolorder(plot.ch, c("plot", "trips.ch", "Freq"))
plot.ch$order <- c(4, 1, 3, 2)
plot.ch <- plot.ch %>% arrange(order)
plot.ch <- plot.ch[-c(4)]
colnames(plot.ch) <- c("Response", "N", "Proportion")

kable(plot.ch)
Response N Proportion
Never 199 69.580420
Sometimes 53 18.531468
Often 29 10.139860
Always 5 1.748252

Q5: Do you currently use any of the following roads when you bike in Victoria?

Cook St or Fifth St

cook <- prop.table(table(factor(d$Q5_vicroads_a, levels = c("1", "2", "77"))))*100
cook <- as.data.frame(cook)
cook$answer <- substring(row.names(cook), 1)
cook$answer <- revalue(as.character(cook$answer), c("1" = "Yes",  "2" = "No", "3" = "Don't know"))

cook$plot <- factor(cook$answer, cook$answer)

cols <- c("#31a354","#f03b20","grey","grey") #get colors for plot
cook.plot <- ggplot(plot, aes(x = answer, y = Freq, fill = plot)) + theme(axis.text.x  = element_text(angle=90, vjust=.6)) #order responses as in t5

cook.plot + geom_bar(aes(x = plot), data = cook, stat = "identity", colour="black") +
      guides(fill = FALSE) +
      scale_fill_manual(values = cols) +
      ylab("Percent of total") +
      xlab("Response")

cook.tb <- as.factor(d$Q5_vicroads_a)
cook.tb <- summary(cook.tb)
cook.tb <- as.data.frame(cook.tb)
cook.tb$Var1 <- substring(row.names(cook.tb), 1)
cook.tb$answer <- revalue(as.character(cook.tb$Var1), c("1" = "Yes", "2" = "No", "77" = "Don't know"))
plot.cook <- merge(cook, cook.tb, by = "answer")
plot.cook <- plot.cook[-c(2, 4, 6)]
plot.cook <- setcolorder(plot.cook, c("answer", "cook.tb", "Freq"))
plot.cook$order <- c(3, 2, 1)
plot.cook <- plot.cook %>% arrange(order)
plot.cook <- plot.cook[-c(4)]
colnames(plot.cook) <- c("Response", "N", "Proportion")

kable(plot.cook)
Response N Proportion
Yes 182 63.636364
No 101 35.314685
Don’t know 3 1.048951

Fairfield Rd or Humboldt St

ffield <- prop.table(table(factor(d$Q5_vicroads_b, levels = c("1", "2", "77"))))*100
ffield <- as.data.frame(ffield)
ffield$answer <- substring(row.names(ffield), 1)
ffield$answer <- revalue(as.character(ffield$answer), c("1" = "Yes",  "2" = "No", "3" = "Don't know"))

ffield$plot <- factor(ffield$answer, ffield$answer)

cols <- c("#31a354","#f03b20","grey","grey") #get colors for plot
ffield.plot <- ggplot(plot, aes(x = answer, y = Freq, fill = plot)) + theme(axis.text.x  = element_text(angle=90, vjust=.6)) +
      guides(fill = FALSE) +
      scale_fill_manual(values = cols) +
      ylab("Percent of total") +
      xlab("")
      
      
ffield.plot + geom_bar(aes(x = plot), data = ffield, stat = "identity", colour="black") 

ffield.tb <- as.factor(d$Q5_vicroads_b)
ffield.tb <- summary(ffield.tb)
ffield.tb <- as.data.frame(ffield.tb)
ffield.tb$Var1 <- substring(row.names(ffield.tb), 1)
ffield.tb$answer <- revalue(as.character(ffield.tb$Var1), c("1" = "Yes", "2" = "No", "77" = "Don't know"))
plot.ffield <- merge(ffield, ffield.tb, by = "answer")
plot.ffield <- plot.ffield[-c(2, 4, 6)]
plot.ffield <- setcolorder(plot.ffield, c("answer", "ffield.tb", "Freq"))
plot.ffield$order <- c(3, 2, 1)
plot.ffield <- plot.ffield %>% arrange(order)
plot.ffield <- plot.ffield[-c(4)]
colnames(plot.ffield) <- c("Response", "N", "Proportion")

kable(plot.ffield)
Response N Proportion
Yes 143 50.000000
No 140 48.951049
Don’t know 3 1.048951

Fort St

fort <- prop.table(table(factor(d$Q5_vicroads_c, levels = c("1", "2", "77"))))*100
fort <- as.data.frame(fort)
fort$answer <- substring(row.names(fort), 1)
fort$answer <- revalue(as.character(fort$answer), c("1" = "Yes",  "2" = "No", "3" = "Don't know"))

fort$plot <- factor(fort$answer, fort$answer)

cols <- c("#31a354","#f03b20","grey","grey") #get colors for plot
fort.plot <- ggplot(plot, aes(x = answer, y = Freq, fill = plot)) + theme(axis.text.x  = element_text(angle=90, vjust=.6)) +
      guides(fill = FALSE) +
      scale_fill_manual(values = cols) +
      ylab("Percent of total") +
      xlab("")
      
fort.plot + geom_bar(aes(x = plot), data = fort, stat = "identity", colour="black") 

fort.tb <- as.factor(d$Q5_vicroads_c)
fort.tb <- summary(fort.tb)
fort.tb <- as.data.frame(fort.tb)
fort.tb$Var1 <- substring(row.names(fort.tb), 1)
fort.tb$answer <- revalue(as.character(fort.tb$Var1), c("1" = "Yes", "2" = "No", "77" = "Don't know"))
plot.fort <- merge(fort, fort.tb, by = "answer")
plot.fort <- plot.fort[-c(2, 4, 6)]
plot.fort <- setcolorder(plot.fort, c("answer", "fort.tb", "Freq"))
plot.fort$order <- c(3, 2, 1)
plot.fort <- plot.fort %>% arrange(order)
plot.fort <- plot.fort[-c(4)]
colnames(plot.fort) <- c("Response", "N", "Proportion")

kable(plot.fort)
Response N Proportion
Yes 221 77.2727273
No 64 22.3776224
Don’t know 1 0.3496503
###Government St
gvt <- prop.table(table(factor(d$Q5_vicroads_d, levels = c("1", "2", "77"))))*100
gvt <- as.data.frame(gvt)
gvt$answer <- substring(row.names(gvt), 1)
gvt$answer <- revalue(as.character(gvt$answer), c("1" = "Yes",  "2" = "No", "3" = "Don't know"))

gvt$plot <- factor(gvt$answer, gvt$answer)

cols <- c("#31a354","#f03b20","grey","grey") #get colors for plot
gvt.plot <- ggplot(plot, aes(x = answer, y = Freq, fill = plot)) + theme(axis.text.x  = element_text(angle=90, vjust=.6)) +
      guides(fill = FALSE) +
      scale_fill_manual(values = cols) +
      ylab("Percent of total") +
      xlab("")
      
gvt.plot + geom_bar(aes(x = plot), data = gvt, stat = "identity", colour="black") 

gvt.tb <- as.factor(d$Q5_vicroads_d)
gvt.tb <- summary(gvt.tb)
gvt.tb <- as.data.frame(gvt.tb)
gvt.tb$Var1 <- substring(row.names(gvt.tb), 1)
gvt.tb$answer <- revalue(as.character(gvt.tb$Var1), c("1" = "Yes", "2" = "No", "77" = "Don't know"))
plot.gvt <- merge(gvt, gvt.tb, by = "answer")
plot.gvt <- plot.gvt[-c(2, 4, 6)]
plot.gvt <- setcolorder(plot.gvt, c("answer", "gvt.tb", "Freq"))
plot.gvt$order <- c(3, 2, 1)
plot.gvt <- plot.gvt %>% arrange(order)
plot.gvt <- plot.gvt[-c(4)]
colnames(plot.gvt) <- c("Response", "N", "Proportion")

kable(plot.gvt)
Response N Proportion
Yes 216 75.5244755
No 69 24.1258741
Don’t know 1 0.3496503

Haultain St or Kings Rd

haultain <- prop.table(table(factor(d$Q5_vicroads_e, levels = c("1", "2", "77"))))*100
haultain <- as.data.frame(haultain)
haultain$answer <- substring(row.names(haultain), 1)
haultain$answer <- revalue(as.character(haultain$answer), c("1" = "Yes",  "2" = "No", "3" = "Don't know"))

haultain$plot <- factor(haultain$answer, haultain$answer)

cols <- c("#31a354","#f03b20","grey","grey") #get colors for plot
haultain.plot <- ggplot(plot, aes(x = answer, y = Freq, fill = plot)) + theme(axis.text.x  = element_text(angle=90, vjust=.6)) +
      guides(fill = FALSE) +
      scale_fill_manual(values = cols) +
      ylab("Percent of total") +
      xlab("")
      
haultain.plot + geom_bar(aes(x = plot), data = haultain, stat = "identity", colour="black") 

haultain.tb <- as.factor(d$Q5_vicroads_e)
haultain.tb <- summary(haultain.tb)
haultain.tb <- as.data.frame(haultain.tb)
haultain.tb$Var1 <- substring(row.names(haultain.tb), 1)
haultain.tb$answer <- revalue(as.character(haultain.tb$Var1), c("1" = "Yes", "2" = "No", "77" = "Don't know"))
plot.haultain <- merge(haultain, haultain.tb, by = "answer")
plot.haultain <- plot.haultain[-c(2, 4, 6)]
plot.haultain <- setcolorder(plot.haultain, c("answer", "haultain.tb", "Freq"))
plot.haultain$order <- c(3, 2, 1)
plot.haultain <- plot.haultain %>% arrange(order)
plot.haultain <- plot.haultain[-c(4)]
colnames(plot.haultain) <- c("Response", "N", "Proportion")

kable(plot.haultain)
Response N Proportion
Yes 165 57.692308
No 115 40.209790
Don’t know 6 2.097902

Pandora Ave

pand <- prop.table(table(factor(d$Q5_vicroads_f, levels = c("1", "2", "77"))))*100
pand <- as.data.frame(pand)
pand$answer <- substring(row.names(pand), 1)
pand$answer <- revalue(as.character(pand$answer), c("1" = "Yes",  "2" = "No", "3" = "Don't know"))

pand$plot <- factor(pand$answer, pand$answer)

cols <- c("#31a354","#f03b20","grey","grey") #get colors for plot
pand.plot <- ggplot(plot, aes(x = answer, y = Freq, fill = plot)) + theme(axis.text.x  = element_text(angle=90, vjust=.6)) +
      guides(fill = FALSE) +
      scale_fill_manual(values = cols) +
      ylab("Percent of total") +
      xlab("")
      
pand.plot + geom_bar(aes(x = plot), data = pand, stat = "identity", colour="black") 

pand.tb <- as.factor(d$Q5_vicroads_f)
pand.tb <- summary(pand.tb)
pand.tb <- as.data.frame(pand.tb)
pand.tb$Var1 <- substring(row.names(pand.tb), 1)
pand.tb$answer <- revalue(as.character(pand.tb$Var1), c("1" = "Yes", "2" = "No", "77" = "Don't know"))
plot.pand <- merge(pand, pand.tb, by = "answer")
plot.pand <- plot.pand[-c(2, 4, 6)]
plot.pand <- setcolorder(plot.pand, c("answer", "pand.tb", "Freq"))
plot.pand$order <- c(3, 2, 1)
plot.pand <- plot.pand %>% arrange(order)
plot.pand <- plot.pand[-c(4)]
colnames(plot.pand) <- c("Response", "N", "Proportion")

kable(plot.pand)
Response N Proportion
Yes 245 85.6643357
No 40 13.9860140
Don’t know 1 0.3496503

Shelbourne St or Begbie St

shelb <- prop.table(table(factor(d$Q5_vicroads_g, levels = c("1", "2", "77"))))*100
shelb <- as.data.frame(shelb)
shelb$answer <- substring(row.names(shelb), 1)
shelb$answer <- revalue(as.character(shelb$answer), c("1" = "Yes",  "2" = "No", "3" = "Don't know"))

shelb$plot <- factor(shelb$answer, shelb$answer)

cols <- c("#31a354","#f03b20","grey","grey") #get colors for plot
shelb.plot <- ggplot(plot, aes(x = answer, y = Freq, fill = plot)) + theme(axis.text.x  = element_text(angle=90, vjust=.6)) +
      guides(fill = FALSE) +
      scale_fill_manual(values = cols) +
      ylab("Percent of total") +
      xlab("")
      
shelb.plot + geom_bar(aes(x = plot), data = shelb, stat = "identity", colour="black") 

shelb.tb <- as.factor(d$Q5_vicroads_g)
shelb.tb <- summary(shelb.tb)
shelb.tb <- as.data.frame(shelb.tb)
shelb.tb$Var1 <- substring(row.names(shelb.tb), 1)
shelb.tb$answer <- revalue(as.character(shelb.tb$Var1), c("1" = "Yes", "2" = "No", "77" = "Don't know"))
plot.shelb <- merge(shelb, shelb.tb, by = "answer")
plot.shelb <- plot.shelb[-c(2, 4, 6)]
plot.shelb <- setcolorder(plot.shelb, c("answer", "shelb.tb", "Freq"))
plot.shelb$order <- c(3, 2, 1)
plot.shelb <- plot.shelb %>% arrange(order)
plot.shelb <- plot.shelb[-c(4)]
colnames(plot.shelb) <- c("Response", "N", "Proportion")

kable(plot.shelb)
Response N Proportion
Yes 117 40.909091
No 166 58.041958
Don’t know 3 1.048951

Harbour Rd, Wharf St or Belville St

bellv <- prop.table(table(factor(d$Q5_vicroads_h, levels = c("1", "2", "77"))))*100
bellv <- as.data.frame(bellv)
bellv$answer <- substring(row.names(bellv), 1)
bellv$answer <- revalue(as.character(bellv$answer), c("1" = "Yes",  "2" = "No", "3" = "Don't know"))

bellv$plot <- factor(bellv$answer, bellv$answer)

cols <- c("#31a354","#f03b20","grey","grey") #get colors for plot
bellv.plot <- ggplot(plot, aes(x = answer, y = Freq, fill = plot)) + theme(axis.text.x  = element_text(angle=90, vjust=.6)) +
      guides(fill = FALSE) +
      scale_fill_manual(values = cols) +
      ylab("Percent of total") +
      xlab("")
      
bellv.plot + geom_bar(aes(x = plot), data = bellv, stat = "identity", colour="black") 

bellv.tb <- as.factor(d$Q5_vicroads_h)
bellv.tb <- summary(bellv.tb)
bellv.tb <- as.data.frame(bellv.tb)
bellv.tb$Var1 <- substring(row.names(bellv.tb), 1)
bellv.tb$answer <- revalue(as.character(bellv.tb$Var1), c("1" = "Yes", "2" = "No", "77" = "Don't know"))
plot.bellv <- merge(bellv, bellv.tb, by = "answer")
plot.bellv <- plot.bellv[-c(2, 4, 6)]
plot.bellv <- setcolorder(plot.bellv, c("answer", "bellv.tb", "Freq"))
plot.bellv$order <- c(3, 2, 1)
plot.bellv <- plot.bellv %>% arrange(order)
plot.bellv <- plot.bellv[-c(4)]
colnames(plot.bellv) <- c("Response", "N", "Proportion")

kable(plot.bellv)
Response N Proportion
Yes 224 78.321678
No 59 20.629371
Don’t know 3 1.048951

Galloping Goose or the E&N Trail

goose <- prop.table(table(factor(d$Q5_vicroads_i, levels = c("1", "2", "77"), exclude = NULL)))*100
goose <- as.data.frame(goose)
goose$answer <- substring(row.names(goose), 1)
goose$answer <- revalue(as.character(goose$answer), c("1" = "Yes",  "2" = "No", "3" = "Don't know"))

goose$plot <- factor(goose$answer, goose$answer)

cols <- c("#31a354","#f03b20","grey","grey") #get colors for plot
goose.plot <- ggplot(plot, aes(x = answer, y = Freq, fill = plot)) + theme(axis.text.x  = element_text(angle=90, vjust=.6)) +
      guides(fill = FALSE) +
      scale_fill_manual(values = cols) +
      ylab("Percent of total") +
      xlab("")
      
goose.plot + geom_bar(aes(x = plot), data = goose, stat = "identity", colour="black") 

goose.tb <- as.factor(d$Q5_vicroads_i)
goose.tb <- summary(goose.tb)
goose.tb <- as.data.frame(goose.tb)
goose.tb$Var1 <- substring(row.names(goose.tb), 1)
goose.tb$answer <- revalue(as.character(goose.tb$Var1), c("1" = "Yes", "2" = "No", "77" = "Don't know"))
plot.goose <- merge(goose, goose.tb, by = "answer")
plot.goose <- plot.goose[-c(2, 4, 6)]
plot.goose <- setcolorder(plot.goose, c("answer", "goose.tb", "Freq"))
plot.goose$order <- c(3, 2, 1)
plot.goose <- plot.goose %>% arrange(order)
plot.goose <- plot.goose[-c(4)]
colnames(plot.goose) <- c("Response", "N", "Proportion")

kable(plot.goose)
Response N Proportion
Yes 251 87.7622378
No 34 11.8881119
Don’t know 1 0.3496503

Q6: How much would you agree with the following statement: “I would like to travel by bicycle more than I do now”?

bike.more <- prop.table(table(factor(d$Q6_bike_more, levels = c("1", "2", "3", "4", "77"))))*100
bike.more <- as.data.frame(bike.more)
bike.more$group <- substring(row.names(bike.more), 1)
bike.more$group <- revalue(as.character(bike.more$group), c("1" = "Strongly agree", "2" = "Somewhat agree", "3" = "Somewhat disagree", "4" = "Strongly disagree", "5" = "Don't know"))

bike.more$plot <- factor(bike.more$group, bike.more$group)

ch <- ggplot(bike.more, aes(x = group, y = Freq, fill = group)) + theme(axis.text.x  = element_text(angle=90, vjust=.6)) #order responses as in t5

ch + geom_bar(aes(x = plot), data = bike.more, stat = "identity", colour="black") +
  guides(fill = FALSE) +
  scale_fill_brewer(palette = "YlGn", direction=-1) +
      ylab("Percent of total") +
      xlab("Bicyle more") +
      ggtitle("I would like to travel by bicycle more than I do now")

more.tb <- as.factor(d$Q6_bike_more)
more.tb <- summary(more.tb)
more.tb <- as.data.frame(more.tb)
more.tb$Var1 <- substring(row.names(more.tb), 1)
more.tb$group <- revalue(as.character(more.tb$Var1), c("1" = "Strongly agree", "2" = "Somewhat agree", "3" = "Somewhat disagree", "4" = "Strongly disagree", "77" = "Don't know"))
more.plot <- merge(bike.more, more.tb, by = "group")
more.plot <- more.plot[-c(1:2, 6)]
more.plot <- setcolorder(more.plot, c("plot", "more.tb", "Freq"))
more.plot$order <- c(5, 2, 3, 1, 4)
more.plot <- more.plot %>% arrange(order)
more.plot <- more.plot[-c(4)]
colnames(more.plot) <- c("Response", "N", "Proportion")

kable(more.plot)
Response N Proportion
Strongly agree 111 38.811189
Somewhat agree 126 44.055944
Somewhat disagree 24 8.391608
Strongly disagree 17 5.944056
Don’t know 8 2.797203

Q7: How comfortable would you feel biking in the following places?

A path or trail that is physically separate from the street

path <- prop.table(table(factor(d$Q7_bike_comf_a, levels = c("1", "2", "3", "4", "77"))))*100
path <- as.data.frame(path)
path$answer <- substring(row.names(path), 1)
path$answer <- revalue(as.character(path$answer), c("1" = "Very uncomfortable",  "2" = "Somewhat uncomfortable", "3" = "Somewhat comfortable", "4" = "Very comfortable", "5" = "Don't know"))

path$plot <- factor(path$answer, path$answer)

path.plot <- ggplot(plot, aes(x = answer, y = Freq, fill = plot)) + theme(axis.text.x  = element_text(angle=90, vjust=.6)) +
      guides(fill = FALSE) +
      scale_fill_brewer(palette = "YlGn") +
      ylab("Percent of total") +
      xlab("")
      
path.plot + geom_bar(aes(x = plot), data = path, stat = "identity", colour="black") 

path.tb <- as.factor(d$Q7_bike_comf_a)
path.tb <- summary(path.tb)
path.tb <- as.data.frame(path.tb)
path.tb$Var1 <- substring(row.names(path.tb), 1)

nval.df <- c("0", "0") #insert missing values 
nval.df <- as.data.frame(nval.df)
nval.df$path.tb <- as.factor(nval.df$nval.df)
nval.df$Var1 <- c("2", "5")
nval.df <- nval.df[-c(1)]

path.tb <- rbind(path.tb, nval.df)

path.tb$answer <- revalue(as.character(path.tb$Var1), c("1" = "Very uncomfortable", "2" = "Somewhat uncomfortable", "3" = "Somewhat comfortable", "4" = "Very comfortable", "5" = "Don't know"))
plot.path <- merge(path, path.tb, by = "answer")
plot.path <- plot.path[-c(2, 4, 6)]
plot.path <- setcolorder(plot.path, c("answer", "path.tb", "Freq"))
plot.path$order <- c(5, 3, 2, 4, 1)
plot.path <- plot.path %>% arrange(order)
plot.path <- plot.path[-c(4)]
colnames(plot.path) <- c("Response", "N", "Proportion")

kable(plot.path)
Response N Proportion
Very uncomfortable 22 7.692308
Somewhat uncomfortable 0 0.000000
Somewhat comfortable 18 6.293706
Very comfortable 246 86.013986
Don’t know 0 0.000000

A quiet, residential street with traffic speeds of 30-40 km per hour

res <- prop.table(table(factor(d$Q7_bike_comf_b, levels = c("1", "2", "3", "4", "77"))))*100
res <- as.data.frame(res)
res$answer <- substring(row.names(res), 1)
res$answer <- revalue(as.character(res$answer), c("1" = "Very uncomfortable",  "2" = "Somewhat uncomfortable", "3" = "Somewhat comfortable", "4" = "Very comfortable", "5" = "Don't know"))

res$plot <- factor(res$answer, res$answer)

res.plot <- ggplot(plot, aes(x = answer, y = Freq, fill = plot)) + theme(axis.text.x  = element_text(angle=90, vjust=.6)) +
      guides(fill = FALSE) +
      scale_fill_brewer(palette = "YlGn") +
      ylab("Percent of total") +
      xlab("")
      
res.plot + geom_bar(aes(x = plot), data = res, stat = "identity", colour="black") 

res.tb <- as.factor(d$Q7_bike_comf_b)
res.tb <- summary(res.tb)
res.tb <- as.data.frame(res.tb)
res.tb$Var1 <- substring(row.names(res.tb), 1)

nval.df <- c("0") #insert missing values 
nval.df <- as.data.frame(nval.df)
nval.df$res.tb <- as.factor(nval.df$nval.df)
nval.df$Var1 <- c( "5")
nval.df <- nval.df[-c(1)]

res.tb <- rbind(res.tb, nval.df)

res.tb$answer <- revalue(as.character(res.tb$Var1), c("1" = "Very uncomfortable", "2" = "Somewhat uncomfortable", "3" = "Somewhat comfortable", "4" = "Very comfortable", "5" = "Don't know"))
plot.res <- merge(res, res.tb, by = "answer")
plot.res <- plot.res[-c(2, 4, 6)]
plot.res <- setcolorder(plot.res, c("answer", "res.tb", "Freq"))
plot.res$order <- c(5, 3, 2, 4, 1)
plot.res <- plot.res %>% arrange(order)
plot.res <- plot.res[-c(4)]
colnames(plot.res) <- c("Response", "N", "Proportion")

kable(plot.res)
Response N Proportion
Very uncomfortable 22 7.692308
Somewhat uncomfortable 20 6.993007
Somewhat comfortable 89 31.118881
Very comfortable 155 54.195804
Don’t know 0 0.000000

A quiet residential street, with a 30 km per hour speed limit, bicycle route markings, wide speed bumps, and other things that slow down and discourage car traffic

bkwy <- prop.table(table(factor(d$Q7_bike_comf_c, levels = c("1", "2", "3", "4", "77"))))*100
bkwy <- as.data.frame(bkwy)
bkwy$answer <- substring(row.names(bkwy), 1)
bkwy$answer <- revalue(as.character(bkwy$answer), c("1" = "Very uncomfortable",  "2" = "Somewhat uncomfortable", "3" = "Somewhat comfortable", "4" = "Very comfortable", "5" = "Don't know"))

bkwy$plot <- factor(bkwy$answer, bkwy$answer)

bkwy.plot <- ggplot(plot, aes(x = answer, y = Freq, fill = plot)) + theme(axis.text.x  = element_text(angle=90, vjust=.6)) +
      guides(fill = FALSE) +
      scale_fill_brewer(palette = "YlGn") +
      ylab("Percent of total") +
      xlab("")
      
bkwy.plot + geom_bar(aes(x = plot), data = bkwy, stat = "identity", colour="black") 

bkwy.tb <- as.factor(d$Q7_bike_comf_c)
bkwy.tb <- summary(bkwy.tb)
bkwy.tb <- as.data.frame(bkwy.tb)
bkwy.tb$Var1 <- substring(row.names(bkwy.tb), 1)
bkwy.tb$answer <- revalue(as.character(bkwy.tb$Var1), c("1" = "Very uncomfortable", "2" = "Somewhat uncomfortable", "3" = "Somewhat comfortable", "4" = "Very comfortable", "77" = "Don't know"))
plot.bkwy <- merge(bkwy, bkwy.tb, by = "answer")
plot.bkwy <- plot.bkwy[-c(2, 4, 6)]
plot.bkwy <- setcolorder(plot.bkwy, c("answer", "bkwy.tb", "Freq"))
plot.bkwy$order <- c(5, 3, 2, 4, 1)
plot.bkwy <- plot.bkwy %>% arrange(order)
plot.bkwy <- plot.bkwy[-c(4)]
colnames(plot.bkwy) <- c("Response", "N", "Proportion")

kable(plot.bkwy)
Response N Proportion
Very uncomfortable 23 8.0419580
Somewhat uncomfortable 4 1.3986014
Somewhat comfortable 42 14.6853147
Very comfortable 216 75.5244755
Don’t know 1 0.3496503

A major urban or suburban street with four lanes, on-street parking, traffic speeds of 50-60 km per hour, and no bike lane

major <- prop.table(table(factor(d$Q7_bike_comf_d, levels = c("1", "2", "3", "4", "77"))))*100
major <- as.data.frame(major)
major$answer <- substring(row.names(major), 1)
major$answer <- revalue(as.character(major$answer), c("1" = "Very uncomfortable",  "2" = "Somewhat uncomfortable", "3" = "Somewhat comfortable", "4" = "Very comfortable", "5" = "Don't know"))

major$plot <- factor(major$answer, major$answer)

major.plot <- ggplot(plot, aes(x = answer, y = Freq, fill = plot)) + theme(axis.text.x  = element_text(angle=90, vjust=.6)) +
      guides(fill = FALSE) +
      scale_fill_brewer(palette = "YlGn") +
      ylab("Percent of total") +
      xlab("")
      
major.plot + geom_bar(aes(x = plot), data = major, stat = "identity", colour="black") 

major.tb <- as.factor(d$Q7_bike_comf_d)
major.tb <- summary(major.tb)
major.tb <- as.data.frame(major.tb)
major.tb$Var1 <- substring(row.names(major.tb), 1)

nval.df <- c("0") #insert missing values 
nval.df <- as.data.frame(nval.df)
nval.df$major.tb <- as.factor(nval.df$nval.df)
nval.df$Var1 <- c( "77")
nval.df <- nval.df[-c(1)]

major.tb <- rbind(major.tb, nval.df)

major.tb$answer <- revalue(as.character(major.tb$Var1), c("1" = "Very uncomfortable", "2" = "Somewhat uncomfortable", "3" = "Somewhat comfortable", "4" = "Very comfortable", "77" = "Don't know"))
plot.major <- merge(major, major.tb, by = "answer")
plot.major <- plot.major[-c(2, 4, 6)]
plot.major <- setcolorder(plot.major, c("answer", "major.tb", "Freq"))
plot.major$order <- c(5, 3, 2, 4, 1)
plot.major <- plot.major %>% arrange(order)
plot.major <- plot.major[-c(4)]
colnames(plot.major) <- c("Response", "N", "Proportion")

kable(plot.major)
Response N Proportion
Very uncomfortable 127 44.405594
Somewhat uncomfortable 109 38.111888
Somewhat comfortable 39 13.636364
Very comfortable 11 3.846154
Don’t know 0 0.000000

A major urban or suburban street with four lanes, on-street parking, traffic speeds of 50-60 km per hour, but with a striped bike lane added

lane <- prop.table(table(factor(d$Q7_bike_comf_e, levels = c("1", "2", "3", "4", "77"))))*100
lane <- as.data.frame(lane)
lane$answer <- substring(row.names(lane), 1)
lane$answer <- revalue(as.character(lane$answer), c("1" = "Very uncomfortable",  "2" = "Somewhat uncomfortable", "3" = "Somewhat comfortable", "4" = "Very comfortable", "5" = "Don't know"))

lane$plot <- factor(lane$answer, lane$answer)

lane.plot <- ggplot(plot, aes(x = answer, y = Freq, fill = plot)) + theme(axis.text.x  = element_text(angle=90, vjust=.6)) +
      guides(fill = FALSE) +
      scale_fill_brewer(palette = "YlGn") +
      ylab("Percent of total") +
      xlab("")
      
lane.plot + geom_bar(aes(x = plot), data = lane, stat = "identity", colour="black") 

lane.tb <- as.factor(d$Q7_bike_comf_e)
lane.tb <- summary(lane.tb)
lane.tb <- as.data.frame(lane.tb)
lane.tb$Var1 <- substring(row.names(lane.tb), 1)

nval.df <- c("0") #insert missing values 
nval.df <- as.data.frame(nval.df)
nval.df$lane.tb <- as.factor(nval.df$nval.df)
nval.df$Var1 <- c( "77")
nval.df <- nval.df[-c(1)]

lane.tb <- rbind(lane.tb, nval.df)

lane.tb$answer <- revalue(as.character(lane.tb$Var1), c("1" = "Very uncomfortable", "2" = "Somewhat uncomfortable", "3" = "Somewhat comfortable", "4" = "Very comfortable", "77" = "Don't know"))
plot.lane <- merge(lane, lane.tb, by = "answer")
plot.lane <- plot.lane[-c(2, 4, 6)]
plot.lane <- setcolorder(plot.lane, c("answer", "lane.tb", "Freq"))
plot.lane$order <- c(5, 3, 2, 4, 1)
plot.lane <- plot.lane %>% arrange(order)
plot.lane <- plot.lane[-c(4)]
colnames(plot.lane) <- c("Response", "N", "Proportion")

kable(plot.lane)
Response N Proportion
Very uncomfortable 26 9.090909
Somewhat uncomfortable 88 30.769231
Somewhat comfortable 131 45.804196
Very comfortable 41 14.335664
Don’t know 0 0.000000

A major urban or suburban street with four lanes, on-street parking, traffic speeds of 50-60 km per hour, but with a wide bike lane physically separated from traffic by a raised curb, planters, or parked cars

track <- prop.table(table(factor(d$Q7_bike_comf_f, levels = c("1", "2", "3", "4", "77"))))*100
track <- as.data.frame(track)
track$answer <- substring(row.names(track), 1)
track$answer <- revalue(as.character(track$answer), c("1" = "Very uncomfortable",  "2" = "Somewhat uncomfortable", "3" = "Somewhat comfortable", "4" = "Very comfortable", "5" = "Don't know"))

track$plot <- factor(track$answer, track$answer)

track.plot <- ggplot(plot, aes(x = answer, y = Freq, fill = plot)) + theme(axis.text.x  = element_text(angle=90, vjust=.6)) +
      guides(fill = FALSE) +
      scale_fill_brewer(palette = "YlGn") +
      ylab("Percent of total") +
      xlab("")
      
track.plot + geom_bar(aes(x = plot), data = track, stat = "identity", colour="black") 

track.tb <- as.factor(d$Q7_bike_comf_f)
track.tb <- summary(track.tb)
track.tb <- as.data.frame(track.tb)
track.tb$Var1 <- substring(row.names(track.tb), 1)

track.tb$answer <- revalue(as.character(track.tb$Var1), c("1" = "Very uncomfortable", "2" = "Somewhat uncomfortable", "3" = "Somewhat comfortable", "4" = "Very comfortable", "77" = "Don't know"))
plot.track <- merge(track, track.tb, by = "answer")
plot.track <- plot.track[-c(2, 4, 6)]
plot.track <- setcolorder(plot.track, c("answer", "track.tb", "Freq"))
plot.track$order <- c(5, 3, 2, 4, 1)
plot.track <- plot.track %>% arrange(order)
plot.track <- plot.track[-c(4)]
colnames(plot.track) <- c("Response", "N", "Proportion")

kable(plot.track)
Response N Proportion
Very uncomfortable 20 6.993007
Somewhat uncomfortable 10 3.496504
Somewhat comfortable 58 20.279720
Very comfortable 195 68.181818
Don’t know 3 1.048951

Q8: Have you ever heard of the All Ages and Abilities (AAA) Network (formerly known as Biketoria)?

AAA <- prop.table(table(factor(d$Q8aaa_familiarity, levels = c("1", "2")), exclude=NULL))*100
AAA <- as.data.frame(AAA)
AAA$answer <- substring(row.names(AAA), 1)
AAA$answer <- revalue(as.character(AAA$answer), c("1" = "Yes",  "2" = "No", "3" = "NA"))

AAA$plot <- factor(AAA$answer, AAA$answer)

cols <- c("#31a354","#f03b20", "grey") #get colors for plot
AAA.plot <- ggplot(plot, aes(x = answer, y = Freq, fill = plot)) + theme(axis.text.x  = element_text(angle=90, vjust=.6)) #order responses as in t5

AAA.plot + geom_bar(aes(x = plot), data = AAA, stat = "identity", colour="black") +
      guides(fill = FALSE) +
      scale_fill_manual(values = cols) +
      ylab("Percent of total") +
      xlab("Response")

AAA.tb <- as.factor(d$Q8aaa_familiarity)
AAA.tb <- summary(AAA.tb)
AAA.tb <- as.data.frame(AAA.tb)
AAA.tb$Var1 <- substring(row.names(AAA.tb), 1)
AAA.tb$answer <- revalue(as.character(AAA.tb$Var1), c("1" = "Yes", "2" = "No", "NA's" = "NA"))
plot.AAA <- merge(AAA, AAA.tb, by = "answer")
plot.AAA <- plot.AAA[-c(2, 4, 6)]
plot.AAA <- setcolorder(plot.AAA, c("answer", "AAA.tb", "Freq"))
plot.AAA$order <- c(3, 2, 1)
plot.AAA <- plot.AAA %>% arrange(order)
plot.AAA <- plot.AAA[-c(4)]
colnames(plot.AAA) <- c("Response", "N", "Proportion")

kable(plot.AAA)
Response N Proportion
Yes 192 67.1328671
No 92 32.1678322
NA 2 0.6993007

Q9: Do you think that the All Ages and Abilities (AAA) Network is a good or bad idea for Victoria? It is a…

aaa.idea <- prop.table(table(factor(d$Q9_aaa_idea, levels = c("1", "2", "3", "4", "77")), exclude=NULL))*100
aaa.idea <- as.data.frame(aaa.idea)
aaa.idea$answer <- substring(row.names(aaa.idea), 1)
aaa.idea$answer <- revalue(as.character(aaa.idea$answer), c("1" = "Very good idea",  "2" = "Somewhat good idea", "3" = "Somewhat bad idea", "4" = "Very bad idea", "5" = "Don't know", "6" = "NA"))

aaa.idea$plot <- factor(aaa.idea$answer, aaa.idea$answer)

cols <- c(rev(brewer.pal(4,"RdYlGn")),"grey", "grey")
aaa.idea.plot <- ggplot(plot, aes(x = answer, y = Freq, fill = plot)) + theme(axis.text.x  = element_text(angle=90, vjust=.6)) +
      guides(fill = FALSE) +
      scale_fill_manual(values = cols) +
      ylab("Percent of total") +
      xlab("")
      
aaa.idea.plot + geom_bar(aes(x = plot), data = aaa.idea, stat = "identity", colour="black") 

aaa.idea.tb <- as.factor(d$Q9_aaa_idea)
aaa.idea.tb <- summary(aaa.idea.tb)
aaa.idea.tb <- as.data.frame(aaa.idea.tb)
aaa.idea.tb$Var1 <- substring(row.names(aaa.idea.tb), 1)
aaa.idea.tb$answer <- revalue(as.character(aaa.idea.tb$Var1), c("1" = "Very good idea",  "2" = "Somewhat good idea", "3" = "Somewhat bad idea", "4" = "Very bad idea", "77" = "Don't know", "NA's" = "NA"))
plot.aaa.idea <- merge(aaa.idea, aaa.idea.tb, by = "answer")
plot.aaa.idea <- plot.aaa.idea[-c(2, 4, 6)]
plot.aaa.idea <- setcolorder(plot.aaa.idea, c("answer", "aaa.idea.tb", "Freq"))
plot.aaa.idea$order <- c(5, 6, 3, 2, 4, 1)
plot.aaa.idea <- plot.aaa.idea %>% arrange(order)
plot.aaa.idea <- plot.aaa.idea[-c(4)]
colnames(plot.aaa.idea) <- c("Response", "N", "Proportion")

kable(plot.aaa.idea)
Response N Proportion
Very good idea 244 85.3146853
Somewhat good idea 33 11.5384615
Somewhat bad idea 3 1.0489510
Very bad idea 1 0.3496503
Don’t know 3 1.0489510
NA 2 0.6993007

Q10:Will you likely cycle more in the future once the All Ages and Abilities (AAA) Network is built?

bike.more <- prop.table(table(factor(d$Q10_aaa_bike_more, levels = c("1", "2")), exclude=NULL))*100
bike.more <- as.data.frame(bike.more)
bike.more$answer <- substring(row.names(bike.more), 1)
bike.more$answer <- revalue(as.character(bike.more$answer), c("1" = "Yes",  "2" = "No", "3" = "NA"))

bike.more$plot <- factor(bike.more$answer, bike.more$answer)

cols <- c("#31a354","#f03b20", "grey") #get colors for plot
bike.more.plot <- ggplot(plot, aes(x = answer, y = Freq, fill = plot)) + theme(axis.text.x  = element_text(angle=90, vjust=.6)) #order responses as in t5

bike.more.plot + geom_bar(aes(x = plot), data = bike.more, stat = "identity", colour="black") +
      guides(fill = FALSE) +
      scale_fill_manual(values = cols) +
      ylab("Percent of total") +
      xlab("Response")

bike.more.tb <- as.factor(d$Q10_aaa_bike_more)
bike.more.tb <- summary(bike.more.tb)
bike.more.tb <- as.data.frame(bike.more.tb)
bike.more.tb$Var1 <- substring(row.names(bike.more.tb), 1)
bike.more.tb$answer <- revalue(as.character(bike.more.tb$Var1), c("1" = "Yes", "2" = "No", "NA's" = "NA"))
plot.bike.more <- merge(bike.more, bike.more.tb, by = "answer")
plot.bike.more <- plot.bike.more[-c(2, 4, 6)]
plot.bike.more <- setcolorder(plot.bike.more, c("answer", "bike.more.tb", "Freq"))
plot.bike.more$order <- c(3, 2, 1)
plot.bike.more <- plot.bike.more %>% arrange(order)
plot.bike.more <- plot.bike.more[-c(4)]
colnames(plot.bike.more) <- c("Response", "N", "Proportion")

kable(plot.bike.more)
Response N Proportion
Yes 223 77.9720280
No 61 21.3286713
NA 2 0.6993007

Q11:Do you currently have a valid driver’s license?

license <- prop.table(table(factor(d$Q11_license, levels = c("1", "2")), exclude=NULL))*100
license <- as.data.frame(license)
license$answer <- substring(row.names(license), 1)
license$answer <- revalue(as.character(license$answer), c("1" = "Yes",  "2" = "No", "3" = "NA"))

license$plot <- factor(license$answer, license$answer)

cols <- c("#31a354","#f03b20", "grey") #get colors for plot
license.plot <- ggplot(plot, aes(x = answer, y = Freq, fill = plot)) + theme(axis.text.x  = element_text(angle=90, vjust=.6)) #order responses as in t5

license.plot + geom_bar(aes(x = plot), data = license, stat = "identity", colour="black") +
      guides(fill = FALSE) +
      scale_fill_manual(values = cols) +
      ylab("Percent of total") +
      xlab("Response")

license.tb <- as.factor(d$Q11_)
license.tb <- summary(license.tb)
license.tb <- as.data.frame(license.tb)
license.tb$Var1 <- substring(row.names(license.tb), 1)
license.tb$answer <- revalue(as.character(license.tb$Var1), c("1" = "Yes", "2" = "No", "NA's" = "NA"))
plot.license <- merge(license, license.tb, by = "answer")
plot.license <- plot.license[-c(2, 4, 6)]
plot.license <- setcolorder(plot.license, c("answer", "license.tb", "Freq"))
plot.license$order <- c(3, 2, 1)
plot.license <- plot.license %>% arrange(order)
plot.license <- plot.license[-c(4)]
colnames(plot.license) <- c("Response", "N", "Proportion")

kable(plot.license)
Response N Proportion
Yes 275 96.1538462
No 9 3.1468531
NA 2 0.6993007

Q12:Do you have access to a car?

access <- prop.table(table(factor(d$Q12_car_access, levels = c("1", "2")), exclude=NULL))*100
access <- as.data.frame(access)
access$answer <- substring(row.names(access), 1)
access$answer <- revalue(as.character(access$answer), c("1" = "Yes",  "2" = "No", "3" = "NA"))

access$plot <- factor(access$answer, access$answer)

cols <- c("#31a354","#f03b20", "grey") #get colors for plot
access.plot <- ggplot(plot, aes(x = answer, y = Freq, fill = plot)) + theme(axis.text.x  = element_text(angle=90, vjust=.6)) #order responses as in t5

access.plot + geom_bar(aes(x = plot), data = access, stat = "identity", colour="black") +
      guides(fill = FALSE) +
      scale_fill_manual(values = cols) +
      ylab("Percent of total") +
      xlab("Response")

access.tb <- as.factor(d$Q12_car_access)
access.tb <- summary(access.tb)
access.tb <- as.data.frame(access.tb)
access.tb$Var1 <- substring(row.names(access.tb), 1)
access.tb$answer <- revalue(as.character(access.tb$Var1), c("1" = "Yes", "2" = "No", "NA's" = "NA"))
plot.access <- merge(access, access.tb, by = "answer")
plot.access <- plot.access[-c(2, 4, 6)]
plot.access <- setcolorder(plot.access, c("answer", "access.tb", "Freq"))
plot.access$order <- c(3, 2, 1)
plot.access <- plot.access %>% arrange(order)
plot.access <- plot.access[-c(4)]
colnames(plot.access) <- c("Response", "N", "Proportion")

kable(plot.access)
Response N Proportion
Yes 257 89.860140
No 18 6.293706
NA 11 3.846154

Q13:How many cars, trucks, or vans are kept in your household?

ggplot(d, aes(x = d$Q13_cars_household)) + geom_bar(na.rm = TRUE) + xlab("Number of cars, trucks or vans in household")

summary(d$Q13_cars_household)
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max.    NA's 
##   0.000   1.000   1.000   1.319   2.000   4.000      29

Q14: How much do you enjoy using each transportation mode?

Walking

pref.walk <- prop.table(table(factor(d$Q14_preferred_mode_a, levels = c("1", "2", "3", "4", "5")), exclude=NULL))*100
pref.walk <- as.data.frame(pref.walk)
pref.walk$answer <- substring(row.names(pref.walk), 1)
pref.walk$answer <- revalue(as.character(pref.walk$answer), c("1" = "A lot", "4" = "Not at all", "5" = "Not applicable", "6" = "NA"))

pref.walk$plot <- factor(pref.walk$answer, pref.walk$answer)

cols <- c(rev(brewer.pal(4,"RdYlGn")),"grey", "grey")
pref.walk.plot <- ggplot(plot, aes(x = answer, y = Freq, fill = plot)) + theme(axis.text.x  = element_text(angle=90, vjust=.6)) +
      guides(fill = FALSE) +
      scale_fill_manual(values = cols) +
      ylab("Percent of total") +
      xlab("")
      
pref.walk.plot + geom_bar(aes(x = plot), data = pref.walk, stat = "identity", colour="black") 

pref.walk.tb <- as.factor(d$Q14_preferred_mode_a)
pref.walk.tb <- summary(pref.walk.tb)
pref.walk.tb <- as.data.frame(pref.walk.tb)
pref.walk.tb$Var1 <- substring(row.names(pref.walk.tb), 1)
pref.walk.tb$answer <- revalue(as.character(pref.walk.tb$Var1), c("1" = "A lot",  "2" = "2", "3" = "3", "4" = "Not at all", "5" = "Not applicable", "NA's" = "NA"))
plot.pref.walk <- merge(pref.walk, pref.walk.tb, by = "answer")
plot.pref.walk <- plot.pref.walk[-c(2, 4, 6)]
plot.pref.walk <- setcolorder(plot.pref.walk, c("answer", "pref.walk.tb", "Freq"))
plot.pref.walk$order <- c(2, 3, 1, 6, 5, 4)
plot.pref.walk <- plot.pref.walk %>% arrange(order)
plot.pref.walk <- plot.pref.walk[-c(4)]
colnames(plot.pref.walk) <- c("Response", "N", "Proportion")

kable(plot.pref.walk)
Response N Proportion
A lot 159 55.5944056
2 94 32.8671329
3 21 7.3426573
Not at all 7 2.4475524
Not applicable 3 1.0489510
NA 2 0.6993007

Biking

pref.bike <- prop.table(table(factor(d$Q14_preferred_mode_b, levels = c("1", "2", "3", "4", "5")), exclude=NULL))*100
pref.bike <- as.data.frame(pref.bike)
pref.bike$answer <- substring(row.names(pref.bike), 1)
pref.bike$answer <- revalue(as.character(pref.bike$answer), c("1" = "A lot", "4" = "Not at all", "5" = "Not applicable", "6" = "NA"))

pref.bike$plot <- factor(pref.bike$answer, pref.bike$answer)

cols <- c(rev(brewer.pal(4,"RdYlGn")),"grey", "grey")
pref.bike.plot <- ggplot(plot, aes(x = answer, y = Freq, fill = plot)) + theme(axis.text.x  = element_text(angle=90, vjust=.6)) +
      guides(fill = FALSE) +
      scale_fill_manual(values = cols) +
      ylab("Percent of total") +
      xlab("")
      
pref.bike.plot + geom_bar(aes(x = plot), data = pref.bike, stat = "identity", colour="black") 

pref.bike.tb <- as.factor(d$Q14_preferred_mode_b)
pref.bike.tb <- summary(pref.bike.tb)
pref.bike.tb <- as.data.frame(pref.bike.tb)
pref.bike.tb$Var1 <- substring(row.names(pref.bike.tb), 1)

nval.df <- c("0", "0") #insert missing values 
nval.df <- as.data.frame(nval.df)
nval.df$pref.bike.tb <- as.factor(nval.df$nval.df)
nval.df$Var1 <- c("4", "5")
nval.df <- nval.df[-c(1)]

pref.bike.tb <- rbind(pref.bike.tb, nval.df)

pref.bike.tb$answer <- revalue(as.character(pref.bike.tb$Var1), c("1" = "A lot",  "2" = "2", "3" = "3", "4" = "Not at all", "5" = "Not applicable", "NA's" = "NA"))
plot.pref.bike <- merge(pref.bike, pref.bike.tb, by = "answer")
plot.pref.bike <- plot.pref.bike[-c(2, 4, 6)]
plot.pref.bike <- setcolorder(plot.pref.bike, c("answer", "pref.bike.tb", "Freq"))
plot.pref.bike$order <- c(2, 3, 1, 6, 5, 4)
plot.pref.bike <- plot.pref.bike %>% arrange(order)
plot.pref.bike <- plot.pref.bike[-c(4)]
colnames(plot.pref.bike) <- c("Response", "N", "Proportion")

kable(plot.pref.bike)
Response N Proportion
A lot 250 87.4125874
2 32 11.1888112
3 2 0.6993007
Not at all 0 0.0000000
Not applicable 0 0.0000000
NA 2 0.6993007

Public Transit

pref.transit <- prop.table(table(factor(d$Q14_preferred_mode_c, levels = c("1", "2", "3", "4", "5")), exclude=NULL))*100
pref.transit <- as.data.frame(pref.transit)
pref.transit$answer <- substring(row.names(pref.transit), 1)
pref.transit$answer <- revalue(as.character(pref.transit$answer), c("1" = "A lot", "4" = "Not at all", "5" = "Not applicable", "6" = "NA"))

pref.transit$plot <- factor(pref.transit$answer, pref.transit$answer)

cols <- c(rev(brewer.pal(4,"RdYlGn")),"grey", "grey")
pref.transit.plot <- ggplot(plot, aes(x = answer, y = Freq, fill = plot)) + theme(axis.text.x  = element_text(angle=90, vjust=.6)) +
      guides(fill = FALSE) +
      scale_fill_manual(values = cols) +
      ylab("Percent of total") +
      xlab("")
      
pref.transit.plot + geom_bar(aes(x = plot), data = pref.transit, stat = "identity", colour="black") 

pref.transit.tb <- as.factor(d$Q14_preferred_mode_c)
pref.transit.tb <- summary(pref.transit.tb)
pref.transit.tb <- as.data.frame(pref.transit.tb)
pref.transit.tb$Var1 <- substring(row.names(pref.transit.tb), 1)
pref.transit.tb$answer <- revalue(as.character(pref.transit.tb$Var1), c("1" = "A lot",  "2" = "2", "3" = "3", "4" = "Not at all", "5" = "Not applicable", "NA's" = "NA"))
plot.pref.transit <- merge(pref.transit, pref.transit.tb, by = "answer")
plot.pref.transit <- plot.pref.transit[-c(2, 4, 6)]
plot.pref.transit <- setcolorder(plot.pref.transit, c("answer", "pref.transit.tb", "Freq"))
plot.pref.transit$order <- c(2, 3, 1, 6, 5, 4)
plot.pref.transit <- plot.pref.transit %>% arrange(order)
plot.pref.transit <- plot.pref.transit[-c(4)]
colnames(plot.pref.transit) <- c("Response", "N", "Proportion")

kable(plot.pref.transit)
Response N Proportion
A lot 11 3.8461538
2 64 22.3776224
3 131 45.8041958
Not at all 68 23.7762238
Not applicable 10 3.4965035
NA 2 0.6993007

Car

pref.car <- prop.table(table(factor(d$Q14_preferred_mode_d, levels = c("1", "2", "3", "4", "5")), exclude=NULL))*100
pref.car <- as.data.frame(pref.car)
pref.car$answer <- substring(row.names(pref.car), 1)
pref.car$answer <- revalue(as.character(pref.car$answer), c("1" = "A lot", "4" = "Not at all", "5" = "Not applicable", "6" = "NA"))

pref.car$plot <- factor(pref.car$answer, pref.car$answer)

cols <- c(rev(brewer.pal(4,"RdYlGn")),"grey", "grey")
pref.car.plot <- ggplot(plot, aes(x = answer, y = Freq, fill = plot)) + theme(axis.text.x  = element_text(angle=90, vjust=.6)) +
      guides(fill = FALSE) +
      scale_fill_manual(values = cols) +
      ylab("Percent of total") +
      xlab("")
      
pref.car.plot + geom_bar(aes(x = plot), data = pref.car, stat = "identity", colour="black") 

pref.car.tb <- as.factor(d$Q14_preferred_mode_d)
pref.car.tb <- summary(pref.car.tb)
pref.car.tb <- as.data.frame(pref.car.tb)
pref.car.tb$Var1 <- substring(row.names(pref.car.tb), 1)
pref.car.tb$answer <- revalue(as.character(pref.car.tb$Var1), c("1" = "A lot",  "2" = "2", "3" = "3", "4" = "Not at all", "5" = "Not applicable", "NA's" = "NA"))
plot.pref.car <- merge(pref.car, pref.car.tb, by = "answer")
plot.pref.car <- plot.pref.car[-c(2, 4, 6)]
plot.pref.car <- setcolorder(plot.pref.car, c("answer", "pref.car.tb", "Freq"))
plot.pref.car$order <- c(2, 3, 1, 6, 5, 4)
plot.pref.car <- plot.pref.car %>% arrange(order)
plot.pref.car <- plot.pref.car[-c(4)]
colnames(plot.pref.car) <- c("Response", "N", "Proportion")

kable(plot.pref.car)
Response N Proportion
A lot 31 10.8391608
2 101 35.3146853
3 111 38.8111888
Not at all 35 12.2377622
Not applicable 6 2.0979021
NA 2 0.6993007

Motorcycle or scooter

pref.motor <- prop.table(table(factor(d$Q14_preferred_mode_e, levels = c("1", "2", "3", "4", "5")), exclude=NULL))*100
pref.motor <- as.data.frame(pref.motor)
pref.motor$answer <- substring(row.names(pref.motor), 1)
pref.motor$answer <- revalue(as.character(pref.motor$answer), c("1" = "A lot", "4" = "Not at all", "5" = "Not applicable", "6" = "NA"))

pref.motor$plot <- factor(pref.motor$answer, pref.motor$answer)

cols <- c(rev(brewer.pal(4,"RdYlGn")),"grey", "grey")
pref.motor.plot <- ggplot(plot, aes(x = answer, y = Freq, fill = plot)) + theme(axis.text.x  = element_text(angle=90, vjust=.6)) +
      guides(fill = FALSE) +
      scale_fill_manual(values = cols) +
      ylab("Percent of total") +
      xlab("")
      
pref.motor.plot + geom_bar(aes(x = plot), data = pref.motor, stat = "identity", colour="black") 

pref.motor.tb <- as.factor(d$Q14_preferred_mode_e)
pref.motor.tb <- summary(pref.motor.tb)
pref.motor.tb <- as.data.frame(pref.motor.tb)
pref.motor.tb$Var1 <- substring(row.names(pref.motor.tb), 1)
pref.motor.tb$answer <- revalue(as.character(pref.motor.tb$Var1), c("1" = "A lot",  "2" = "2", "3" = "3", "4" = "Not at all", "5" = "Not applicable", "NA's" = "NA"))
plot.pref.motor <- merge(pref.motor, pref.motor.tb, by = "answer")
plot.pref.motor <- plot.pref.motor[-c(2, 4, 6)]
plot.pref.motor <- setcolorder(plot.pref.motor, c("answer", "pref.motor.tb", "Freq"))
plot.pref.motor$order <- c(2, 3, 1, 6, 5, 4)
plot.pref.motor <- plot.pref.motor %>% arrange(order)
plot.pref.motor <- plot.pref.motor[-c(4)]
colnames(plot.pref.motor) <- c("Response", "N", "Proportion")

kable(plot.pref.motor)
Response N Proportion
A lot 8 2.7972028
2 15 5.2447552
3 8 2.7972028
Not at all 30 10.4895105
Not applicable 223 77.9720280
NA 2 0.6993007

Other

pref.other <- prop.table(table(factor(d$Q14_preferred_mode_a, levels = c("1", "2", "3", "4", "5")), exclude=NULL))*100
pref.other <- as.data.frame(pref.other)
pref.other$answer <- substring(row.names(pref.other), 1)
pref.other$answer <- revalue(as.character(pref.other$answer), c("1" = "A lot", "4" = "Not at all", "5" = "Not applicable", "6" = "NA"))

pref.other$plot <- factor(pref.other$answer, pref.other$answer)

cols <- c(rev(brewer.pal(4,"RdYlGn")),"grey", "grey")
pref.other.plot <- ggplot(plot, aes(x = answer, y = Freq, fill = plot)) + theme(axis.text.x  = element_text(angle=90, vjust=.6)) +
      guides(fill = FALSE) +
      scale_fill_manual(values = cols) +
      ylab("Percent of total") +
      xlab("")
      
pref.other.plot + geom_bar(aes(x = plot), data = pref.other, stat = "identity", colour="black") 

pref.other.tb <- as.factor(d$Q14_preferred_mode_a)
pref.other.tb <- summary(pref.other.tb)
pref.other.tb <- as.data.frame(pref.other.tb)
pref.other.tb$Var1 <- substring(row.names(pref.other.tb), 1)
pref.other.tb$answer <- revalue(as.character(pref.other.tb$Var1), c("1" = "A lot",  "2" = "2", "3" = "3", "4" = "Not at all", "5" = "Not applicable", "NA's" = "NA"))
plot.pref.other <- merge(pref.other, pref.other.tb, by = "answer")
plot.pref.other <- plot.pref.other[-c(2, 4, 6)]
plot.pref.other <- setcolorder(plot.pref.other, c("answer", "pref.other.tb", "Freq"))
plot.pref.other$order <- c(2, 3, 1, 6, 5, 4)
plot.pref.other <- plot.pref.other %>% arrange(order)
plot.pref.other <- plot.pref.other[-c(4)]
colnames(plot.pref.other) <- c("Response", "N", "Proportion")

kable(plot.pref.other)
Response N Proportion
A lot 159 55.5944056
2 94 32.8671329
3 21 7.3426573
Not at all 7 2.4475524
Not applicable 3 1.0489510
NA 2 0.6993007
carshare.df <- c("Car2Go", "Modo", "ZipCar", "Other") #insert missing values 
carshare.df <- as.data.frame(carshare.df)
carshare.df$Members <- c("21", "46", "5", "7")
as.numeric(carshare.df$Members)
## [1] 21 46  5  7
colnames(carshare.df) <- c("Carshare", "N Respondents")

Q15:Which car share services are you a member of??

noshare<- prop.table(table(factor(d$Q15_car_share_None, levels = c("0", "1")), exclude=NULL))*100
noshare <- as.data.frame(noshare)
noshare$answer <- substring(row.names(noshare), 1)
noshare$answer <- revalue(as.character(noshare$answer), c("1" = "Member",  "2" = "Non-member", "3" = "NA"))

noshare$plot <- factor(noshare$answer, noshare$answer)

cols <- c("#31a354","#f03b20", "grey") #get colors for plot
noshare.plot <- ggplot(plot, aes(x = answer, y = Freq, fill = plot)) + theme(axis.text.x  = element_text(angle=90, vjust=.6)) #order responses as in t5

noshare.plot + geom_bar(aes(x = plot), data = noshare, stat = "identity", colour="black") +
      guides(fill = FALSE) +
      scale_fill_manual(values = cols) +
      ylab("Percent of total") +
      xlab("Response")

noshare.tb <- as.factor(d$Q15_car_share_None)
noshare.tb <- summary(noshare.tb)
noshare.tb <- as.data.frame(noshare.tb)
noshare.tb$Var1 <- substring(row.names(noshare.tb), 1)
noshare.tb$answer <- revalue(as.character(noshare.tb$Var1), c("0" = "Member", "1" = "Non-member", "NA's" = "NA"))
plot.noshare <- merge(noshare, noshare.tb, by = "answer")
plot.noshare <- plot.noshare[-c(2, 4, 6)]
plot.noshare <- setcolorder(plot.noshare, c("answer", "noshare.tb", "Freq"))
plot.noshare$order <- c(1, 3, 2)
plot.noshare <- plot.noshare %>% arrange(order)
plot.noshare <- plot.noshare[-c(4)]
colnames(plot.noshare) <- c("Response", "N", "Proportion")

kable(plot.noshare)
Response N Proportion
Member 60 20.9790210
Non-member 224 78.3216783
NA 2 0.6993007
kable(carshare.df)
Carshare N Respondents
Car2Go 21
Modo 46
ZipCar 5
Other 7

-Some respondents are members of more than one carshare service Other carshare companies:
Evo (Vancouver, n=6)
Pogo (Edmonton, n=1)

Q16:Are you a member of a bike advocacy group (e.g., Greater Victoria Cycling Coalition)?

advocacy <- prop.table(table(factor(d$Q16_bike_advocacy, levels = c("1", "2")), exclude=NULL))*100
advocacy <- as.data.frame(advocacy)
advocacy$answer <- substring(row.names(advocacy), 1)
advocacy$answer <- revalue(as.character(advocacy$answer), c("1" = "Yes",  "2" = "No", "3" = "NA"))

advocacy$plot <- factor(advocacy$answer, advocacy$answer)

cols <- c("#31a354","#f03b20", "grey") #get colors for plot
advocacy.plot <- ggplot(plot, aes(x = answer, y = Freq, fill = plot)) + theme(axis.text.x  = element_text(angle=90, vjust=.6)) #order responses as in t5

advocacy.plot + geom_bar(aes(x = plot), data = advocacy, stat = "identity", colour="black") +
      guides(fill = FALSE) +
      scale_fill_manual(values = cols) +
      ylab("Percent of total") +
      xlab("Response")

advocacy.tb <- as.factor(d$Q16_bike_advocacy)
advocacy.tb <- summary(advocacy.tb)
advocacy.tb <- as.data.frame(advocacy.tb)
advocacy.tb$Var1 <- substring(row.names(advocacy.tb), 1)
advocacy.tb$answer <- revalue(as.character(advocacy.tb$Var1), c("1" = "Yes", "2" = "No", "NA's" = "NA"))
plot.advocacy <- merge(advocacy, advocacy.tb, by = "answer")
plot.advocacy <- plot.advocacy[-c(2, 4, 6)]
plot.advocacy <- setcolorder(plot.advocacy, c("answer", "advocacy.tb", "Freq"))
plot.advocacy$order <- c(3, 2, 1)
plot.advocacy <- plot.advocacy %>% arrange(order)
plot.advocacy <- plot.advocacy[-c(4)]
colnames(plot.advocacy) <- c("Response", "N", "Proportion")

kable(plot.advocacy)
Response N Proportion
Yes 65 22.7272727
No 219 76.5734266
NA 2 0.6993007

Q17:Do you ride with a recreational cycling group or club (e.g., Tripleshot, TriStars)?

group <- prop.table(table(factor(d$Q17_cycling_club, levels = c("1", "2")), exclude=NULL))*100
group <- as.data.frame(group)
group$answer <- substring(row.names(group), 1)
group$answer <- revalue(as.character(group$answer), c("1" = "Yes",  "2" = "No", "3" = "NA"))

group$plot <- factor(group$answer, group$answer)

cols <- c("#31a354","#f03b20", "grey") #get colors for plot
group.plot <- ggplot(plot, aes(x = answer, y = Freq, fill = plot)) + theme(axis.text.x  = element_text(angle=90, vjust=.6)) #order responses as in t5

group.plot + geom_bar(aes(x = plot), data = group, stat = "identity", colour="black") +
      guides(fill = FALSE) +
      scale_fill_manual(values = cols) +
      ylab("Percent of total") +
      xlab("Response")

group.tb <- as.factor(d$Q17_cycling_club)
group.tb <- summary(group.tb)
group.tb <- as.data.frame(group.tb)
group.tb$Var1 <- substring(row.names(group.tb), 1)

group.tb$answer <- revalue(as.character(group.tb$Var1), c("1" = "Yes", "2" = "No", "NA's" = "NA"))
plot.group <- merge(group, group.tb, by = "answer")
plot.group <- plot.group[-c(2, 4, 6)]
plot.group <- setcolorder(plot.group, c("answer", "group.tb", "Freq"))
plot.group$order <- c(3, 2, 1)
plot.group <- plot.group %>% arrange(order)
plot.group <- plot.group[-c(4)]
colnames(plot.group) <- c("Response", "N", "Proportion")

kable(plot.group)
Response N Proportion
Yes 46 16.0839161
No 238 83.2167832
NA 2 0.6993007

Section 2: Housing

Q18: Thinking about where you live now, are you .

tenure <- prop.table(table(factor(d$Q18_house_tenure, levels = c("1", "2", "3", "4", "5", "77")), exclude=NULL))*100
tenure <- as.data.frame(tenure)
tenure$answer <- substring(row.names(tenure), 1)
tenure$answer <- revalue(as.character(tenure$answer), c("1" = "An owner", "2" = "A tenant", "3" = "Resident in a relative or friend's home", "4" = "Resident other than in a relative or friend's home", "5" = "Other", "6" = "Don't know", "7" = "No anwer"))

tenure$plot <- factor(tenure$answer, tenure$answer)

tenure.plot <- ggplot(plot, aes(x = answer, y = Freq, fill = plot)) + theme(axis.text.x  = element_text(angle=90, vjust=.6)) +
      guides(fill = FALSE) +
      scale_fill_brewer(palette = "YlGn") +
      ylab("Percent of total") +
      xlab("")
      
tenure.plot + geom_bar(aes(x = plot), data = tenure, stat = "identity", colour="black") 

tenure.tb <- as.factor(d$Q18_house_tenure)
tenure.tb <- summary(tenure.tb)
tenure.tb <- as.data.frame(tenure.tb)
tenure.tb$Var1 <- substring(row.names(tenure.tb), 1)

nval.df <- c("0") #insert missing values 
nval.df <- as.data.frame(nval.df)
nval.df$tenure.tb <- as.factor(nval.df$nval.df)
nval.df$Var1 <- c("77")
nval.df <- nval.df[-c(1)]

tenure.tb <- rbind(tenure.tb, nval.df)

tenure.tb$answer <- revalue(as.character(tenure.tb$Var1), c("1" = "An owner", "2" = "A tenant", "3" = "Resident in a relative or friend's home", "4" = "Resident other than in a relative or friend's home", "5" = "Other", "77" = "Don't know", "NA's" = "No anwer"))
plot.tenure <- merge(tenure, tenure.tb, by = "answer")
plot.tenure <- plot.tenure[-c(2, 4, 6)]
plot.tenure <- setcolorder(plot.tenure, c("answer", "tenure.tb", "Freq"))
plot.tenure$order <- c(2, 1, 6, 7, 5, 3, 4)
plot.tenure <- plot.tenure %>% arrange(order)
plot.tenure <- plot.tenure[-c(4)]
colnames(plot.tenure) <- c("Response", "N", "Proportion")

kable(plot.tenure)
Response N Proportion
An owner 179 62.5874126
A tenant 90 31.4685315
Resident in a relative or friend’s home 11 3.8461538
Resident other than in a relative or friend’s home 2 0.6993007
Other 2 0.6993007
Don’t know 0 0.0000000
No anwer 2 0.6993007

Q19: In what type of dwelling to you currently live? Is it.

dwelling <- prop.table(table(factor(d$Q19_dwelling_type, levels = c("1", "2", "3", "4", "5", "6", "7", "8", "10", "77")), exclude=NULL))*100
dwelling <- as.data.frame(dwelling)
dwelling$answer <- substring(row.names(dwelling), 1)
dwelling$answer <- revalue(as.character(dwelling$answer), c("1" = "Single detached house", "2" = "Semi-detached house", "3" = "Row house",  "4" = "An apartment (or condo) in a duplex or triplex", "5" = "Apartment (or condo) in building with fewer than 5 storeys", "6" = "Apartment (or condo) in building with more than 5 storeys", "7" = "Mobile home/movable dwelling", "8" = "Senior's home", "9" = "Other", "10" = "Don't know", "11" = "NA"))

dwelling$plot <- factor(dwelling$answer, dwelling$answer)

dwelling.plot <- ggplot(plot, aes(x = answer, y = Freq, fill = plot)) + theme(axis.text.x  = element_text(angle=90, vjust=.6)) +
      guides(fill = FALSE) +
      scale_fill_brewer(palette = "YlGn") +
      ylab("Percent of total") +
      xlab("")
      
dwelling.plot + geom_bar(aes(x = plot), data = dwelling, stat = "identity", colour="black") 

dwelling.tb <- as.factor(d$Q19_dwelling_type)
dwelling.tb <- summary(dwelling.tb)
dwelling.tb <- as.data.frame(dwelling.tb)
dwelling.tb$Var1 <- substring(row.names(dwelling.tb), 1)

nval.df <- c("0", "0") #insert missing values 
nval.df <- as.data.frame(nval.df)
nval.df$dwelling.tb <- as.factor(nval.df$nval.df)
nval.df$Var1 <- c("8", "77")
nval.df <- nval.df[-c(1)]

dwelling.tb <- rbind(dwelling.tb, nval.df)

dwelling.tb$answer <- revalue(as.character(dwelling.tb$Var1), c("1" = "Single detached house", "2" = "Semi-detached house", "3" = "Row house",  "4" = "An apartment (or condo) in a duplex or triplex", "5" = "Apartment (or condo) in building with fewer than 5 storeys", "6" = "Apartment (or condo) in building with more than 5 storeys", "7" = "Mobile home/movable dwelling", "8" = "Senior's home", "10" = "Other", "77" = "Don't know", "NA's" = "NA"))
plot.dwelling <- merge(dwelling, dwelling.tb, by = "answer")
plot.dwelling <- plot.dwelling[-c(2, 4, 6)]
plot.dwelling <- setcolorder(plot.dwelling, c("answer", "dwelling.tb", "Freq"))
plot.dwelling$order <- c(4, 5, 6, 10, 7, 11, 9, 3, 2, 8, 1)
plot.dwelling <- plot.dwelling %>% arrange(order)
plot.dwelling <- plot.dwelling[-c(4)]
colnames(plot.dwelling) <- c("Response", "N", "Proportion")

kable(plot.dwelling)
Response N Proportion
Single detached house 169 59.0909091
Semi-detached house 15 5.2447552
Row house 16 5.5944056
An apartment (or condo) in a duplex or triplex 15 5.2447552
Apartment (or condo) in building with fewer than 5 storeys 43 15.0349650
Apartment (or condo) in building with more than 5 storeys 19 6.6433566
Mobile home/movable dwelling 1 0.3496503
Senior’s home 0 0.0000000
Other 6 2.0979021
Don’t know 0 0.0000000
NA 2 0.6993007

Section 3: Physical Activity-Job

Q20: During the last 7 days, on how many days did you do vigorous physical activities as part of your work?

ggplot(d, aes(x = d$Q20_work_vigpa)) + geom_bar(na.rm = TRUE) + xlab("N days vigorous job-related n/ physical activity")

summary(d$Q20_work_vigpa)
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max.    NA's 
##  0.0000  0.0000  0.0000  0.9225  1.0000  7.0000       2

Q21: How much time did you usually spend on one of those days doing vigorous physical activities as part of your work?

ggplot(d, aes(x = d$Q21_work_vigpa_freq)) + geom_histogram(na.rm = TRUE, binwidth = 20) + xlab("Minutes vigorous job-related n/ physical activity") 

summary(d$Q21_work_vigpa_freq, na.rm = TRUE)
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max.    NA's 
##     0.0    60.0   120.0   153.4   240.0   480.0     213

Section 3: Physical Activity-Transportation

Q22: During the last 7 days, on how many days did you travel in a motor vehicle like a train, bus, car, or tram?

ggplot(d, aes(x = d$Q22_travel_motor)) + geom_bar(na.rm = TRUE) + xlab("N days")

summary(d$Q22_travel_motor)
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max.    NA's 
##   0.000   2.000   3.000   2.982   4.000   7.000       3

Q23: How much time did you usually spend on one of those days traveling in a train, bus, car, tram, or other kind of motor vehicle?

ggplot(d, aes(x = d$Q23_travel_motor_freq)) + geom_histogram(na.rm = TRUE, binwidth = 20) + xlab("Minutes travel time") 

summary(d$Q23_travel_motor_freq)
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max.    NA's 
##    0.00   30.00   40.00   58.54   60.00  900.00      32

Q24: During the last 7 days, on how many days did you bicycle for at least 10 minutes at a time to go from place to place?

ggplot(d, aes(x = d$Q24_travel_bike)) + geom_bar(na.rm = TRUE) + xlab("N days")

summary(d$Q24_travel_bike)
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max.    NA's 
##   0.000   4.000   5.000   4.801   6.000   7.000       4

Q25: How much time did you usually spend on one of those days bicycling from place to place?

ggplot(d, aes(x = d$Q25_travel_bike_freq)) + geom_histogram(na.rm = TRUE, binwidth = 20) + xlab("Minutes travel by bicycle") 

summary(d$Q25_travel_bike_freq)
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max.    NA's 
##    1.00   30.00   45.00   58.61   60.00  300.00      14

Q26: During the last 7 days, on how many days did you walk for at least 10 minutes at a time to go from place to place?

ggplot(d, aes(x = d$Q26_travel_walk)) + geom_bar(na.rm = TRUE) + xlab("N days")

summary(d$Q26_travel_walk)
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max.    NA's 
##   0.000   1.000   3.000   3.511   6.000   7.000       4

Q27: How much time did you usually spend on one of those days bicycling from place to place?

ggplot(d, aes(x = d$Q27_travel_walk_freq)) + geom_histogram(na.rm = TRUE, binwidth = 10) + xlab("Minutes travel by walking") 

summary(d$Q27_travel_walk_freq)
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max.    NA's 
##   10.00   20.00   30.00   41.46   60.00  300.00      46

Section 3: Physical Activity-Recreation, sport & leisure

Q28: Not counting any walking for transportation that you have already mentioned, during the last 7 days, on how many days did you walk for at least 10 minutes at a time in your leisure time?

ggplot(d, aes(x = d$Q28_leisure_walk)) + geom_bar(na.rm = TRUE) + xlab("N days")

summary(d$Q28_leisure_walk)
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max.    NA's 
##   0.000   1.000   2.000   2.805   5.000   7.000       4

Q29: How much time did you usually spend on one of those days walking in your leisure time?

ggplot(d, aes(x = d$Q29_leisure_walk_freq)) + geom_histogram(na.rm = TRUE, binwidth = 20) + xlab("Minutes leisure time walking") 

summary(d$Q29_leisure_walk_freq)
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max.    NA's 
##   10.00   30.00   45.00   65.02   60.00  900.00      65

Q30:During the last 7 days, on how many days did you do vigorous physical activities like aerobics, running, fast bicycling, or fast swimming in your leisure time?

ggplot(d, aes(x = d$Q30_leisure_vigpa)) + geom_bar(na.rm = TRUE) + xlab("N days")

summary(d$Q30_leisure_vigpa)
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max.    NA's 
##    0.00    0.00    2.00    2.23    4.00    7.00       4

31:How much time did you usually spend on one of those days doing vigorous physical activities in your leisure time?

ggplot(d, aes(x = d$Q31_leisure_vigpa_freq)) + geom_histogram(na.rm = TRUE) + xlab("Minutes leisure time vigorous PA") 
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

summary(d$Q31_leisure_vigpa_freq)
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max.    NA's 
##    0.00   45.00   60.00   76.95  120.00  300.00      90

Q32:During the last 7 days, on how many days did you do moderate physical activities like bicycling at a regular pace, swimming at a regular pace, and doubles tennis in your leisure time?

ggplot(d, aes(x = d$Q32_modpa_leisure)) + geom_bar(na.rm = TRUE) + xlab("N days")

summary(d$Q32_modpa_leisure)
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max.    NA's 
##   0.000   0.000   1.000   1.868   3.000   7.000       5

33:How much time did you usually spend on one of those days doing moderate physical activities in your leisure time?

ggplot(d, aes(x = d$Q33_modpa_leisure_freq)) + geom_histogram(na.rm = TRUE) + xlab("Minutes leisure time moderate PA") 
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

summary(d$Q33_modpa_leisure_freq)
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max.    NA's 
##   10.00   30.00   60.00   68.57   60.00  360.00     115

Q34:During the last 7 days, how much time did you usually spend sitting on a weekday?

ggplot(d, aes(x = d$Q34_sit_weekday/60)) + geom_histogram(na.rm = TRUE, binwidth = 1) + xlab("Hours sitting, weekday") 

summary(d$Q34_sit_weekday/60)
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max.    NA's 
##  0.3333  4.0000  6.0000  6.2760  9.0000 14.0000       8

35:During the last 7 days, how much time did you usually spend sitting on a weekend day?

ggplot(d, aes(x = d$Q35_sit_weekend/60)) + geom_histogram(na.rm = TRUE, binwidth = 1) + xlab("Hours sitting, weekend") 

summary(d$Q35_sit_weekend/60)
##     Min.  1st Qu.   Median     Mean  3rd Qu.     Max.     NA's 
##  0.03333  2.00000  4.00000  3.82300  5.00000 14.00000        8

Section 3: Physical Activity-Dog Ownership

Q36:Do you live with a dog?

dog <- prop.table(table(factor(d$Q36_dog, levels = c("1", "2")), exclude=NULL))*100
dog <- as.data.frame(dog)
dog$answer <- substring(row.names(dog), 1)
dog$answer <- revalue(as.character(dog$answer), c("1" = "Yes",  "2" = "No", "3" = "NA"))

dog$plot <- factor(dog$answer, dog$answer)

cols <- c("#31a354","#f03b20", "grey") #get colors for plot
dog.plot <- ggplot(plot, aes(x = answer, y = Freq, fill = plot)) + theme(axis.text.x  = element_text(angle=90, vjust=.6)) #order responses as in t5

dog.plot + geom_bar(aes(x = plot), data = dog, stat = "identity", colour="black") +
      guides(fill = FALSE) +
      scale_fill_manual(values = cols) +
      ylab("Percent of total") +
      xlab("Response")

dog.tb <- as.factor(d$Q36_dog)
dog.tb <- summary(dog.tb)
dog.tb <- as.data.frame(dog.tb)
dog.tb$Var1 <- substring(row.names(dog.tb), 1)
dog.tb$answer <- revalue(as.character(dog.tb$Var1), c("1" = "Yes", "2" = "No", "NA's" = "NA"))
plot.dog <- merge(dog, dog.tb, by = "answer")
plot.dog <- plot.dog[-c(2, 4, 6)]
plot.dog <- setcolorder(plot.dog, c("answer", "dog.tb", "Freq"))
plot.dog$order <- c(3, 2, 1)
plot.dog <- plot.dog %>% arrange(order)
plot.dog <- plot.dog[-c(4)]
colnames(plot.dog) <- c("Response", "N", "Proportion")

kable(plot.dog)
Response N Proportion
Yes 57 19.930070
No 223 77.972028
NA 6 2.097902

Q37:Do you walk the dog regularly?

dog.walk <- prop.table(table(factor(d$Q37_dog_walk, levels = c("1", "2"))))*100
dog.walk <- as.data.frame(dog.walk)
dog.walk$answer <- substring(row.names(dog.walk), 1)
dog.walk$answer <- revalue(as.character(dog.walk$answer), c("1" = "Yes",  "2" = "No"))

dog.walk$plot <- factor(dog.walk$answer, dog.walk$answer)

cols <- c("#31a354","#f03b20") #get colors for plot
dog.walk.plot <- ggplot(plot, aes(x = answer, y = Freq, fill = plot)) + theme(axis.text.x  = element_text(angle=90, vjust=.6)) #order responses as in t5

dog.walk.plot + geom_bar(aes(x = plot), data = dog.walk, stat = "identity", colour="black") +
      guides(fill = FALSE) +
      scale_fill_manual(values = cols) +
      ylab("Percent of total") +
      xlab("Response")

dog.walk.tb <- as.factor(d$Q37_dog_walk)
dog.walk.tb <- summary(dog.walk.tb)
dog.walk.tb <- as.data.frame(dog.walk.tb)
dog.walk.tb$Var1 <- substring(row.names(dog.walk.tb), 1)
dog.walk.tb$answer <- revalue(as.character(dog.walk.tb$Var1), c("1" = "Yes", "2" = "No", "NA's" = "NA"))
plot.dog.walk <- merge(dog.walk, dog.walk.tb, by = "answer")
plot.dog.walk <- merge(dog.walk, plot.dog.walk, by = "answer")
plot.dog.walk <- plot.dog.walk[-c(2, 4:7, 9)]
plot.dog.walk <- setcolorder(plot.dog.walk, c("answer", "dog.walk.tb", "Freq.x"))
plot.dog.walk$order <- c(2, 1)
plot.dog.walk <- plot.dog.walk %>% arrange(order)
plot.dog.walk <- plot.dog.walk[-c(4)]
colnames(plot.dog.walk) <- c("Response", "N", "Proportion")

kable(plot.dog.walk)
Response N Proportion
Yes 43 75.4386
No 14 24.5614

Q38:How many hours or minutes a day on average do you walk the dog?

ggplot(d, aes(x = d$Q38_dog_walk_freq)) + geom_histogram(na.rm = TRUE) + xlab("Minutes dog walking") 
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

summary(d$Q38_dog_walk_freq)
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max.    NA's 
##   10.00   30.00   40.00   52.09   60.00  120.00     243

Section 4: General Health

Q39: How tall are you? (Choose either feet or centimetres)

ggplot(d, aes(x = d$Q39_height)) + geom_histogram(na.rm = TRUE, binwidth = 1) + xlab("Height (cm)") 

summary(d$Q39_height)
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max.    NA's 
##   155.0   165.0   170.0   172.3   178.5   201.0       6

Q40: How much do you weigh? (Choose either pounds or kilograms)

ggplot(d, aes(x = d$Q40_weight)) + geom_histogram(na.rm = TRUE, binwidth = 2) + xlab("Weight (kg)") 

summary(d$Q40_weight)
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max.    NA's 
##   45.00   61.00   70.00   71.75   80.25  150.00       6

Q41: In general, would you say your health is:

health <- prop.table(table(factor(d$Q41, levels = c("1", "2", "3", "4", "5")), exclude=NULL))*100
health <- as.data.frame(health)
health$answer <- substring(row.names(health), 1)
health$answer <- revalue(as.character(health$answer), c("1" = "Excellent", "2" = "Very good", "3" = "Good", "4" = "Fair", "5" = "Poor", "6" = "No anwer"))

health$plot <- factor(health$answer, health$answer)

health.plot <- ggplot(plot, aes(x = answer, y = Freq, fill = plot)) + theme(axis.text.x  = element_text(angle=90, vjust=.6)) +
      guides(fill = FALSE) +
      scale_fill_brewer(palette = "BuGn", direction=-1) +
      ylab("Percent of total") +
      xlab("")
      
health.plot + geom_bar(aes(x = plot), data = health, stat = "identity", colour="black") 

health.tb <- as.factor(d$Q41_sf1)
health.tb <- summary(health.tb)
health.tb <- as.data.frame(health.tb)
health.tb$Var1 <- substring(row.names(health.tb), 1)
health.tb$answer <- revalue(as.character(health.tb$Var1), c("1" = "Excellent", "2" = "Very good", "3" = "Good", "4" = "Fair", "5" = "Poor", "NA's" = "No anwer"))
plot.health <- merge(health, health.tb, by = "answer")
plot.health <- plot.health[-c(2, 4, 6)]
plot.health <- setcolorder(plot.health, c("answer", "health.tb", "Freq"))
plot.health$order <- c(1, 4, 3, 6, 5, 2)
plot.health <- plot.health %>% arrange(order)
plot.health <- plot.health[-c(4)]
colnames(plot.health) <- c("Response", "N", "Proportion")

kable(plot.health)
Response N Proportion
Excellent 69 24.1258741
Very good 138 48.2517483
Good 59 20.6293706
Fair 13 4.5454545
Poor 1 0.3496503
No anwer 6 2.0979021

Q42:The following items are about activities you might do during a typical day. Does your health now limit you in these activities? If so, how much?

Moderate activities such as moving a table, pushing a vacuum cleaner, bowling, or playing golf

mod <- prop.table(table(factor(d$Q42_sf2, levels = c("1", "2", "3")), exclude = NULL))*100
mod <- as.data.frame(mod)
mod$answer <- substring(row.names(mod), 1)
mod$answer <- revalue(as.character(mod$answer), c("1" = "Yes, limited a lot",  "2" = "Yes, limited a little", "3" = "No, not at all", "4" =  "NA"))

mod$plot <- factor(mod$answer, mod$answer)

cols <- c(brewer.pal(3,"RdYlGn"),"grey")
mod.plot <- ggplot(plot, aes(x = answer, y = Freq, fill = plot)) + theme(axis.text.x  = element_text(angle=90, vjust=.6)) +
      guides(fill = FALSE) +
      scale_fill_manual(values = cols) +
      ylab("Percent of total") +
      xlab("")
      
mod.plot + geom_bar(aes(x = plot), data = mod, stat = "identity", colour="black") 

mod.tb <- as.factor(d$Q42_sf2)
mod.tb <- summary(mod.tb)
mod.tb <- as.data.frame(mod.tb)
mod.tb$Var1 <- substring(row.names(mod.tb), 1)
mod.tb$answer <- revalue(as.character(mod.tb$Var1), c("1" = "Yes, limited a lot",  "2" = "Yes, limited a little", "3" = "No, not at all", "NA's" =  "NA"))
plot.mod <- merge(mod, mod.tb, by = "answer")
plot.mod <- plot.mod[-c(2, 4, 6)]
plot.mod <- setcolorder(plot.mod, c("answer", "mod.tb", "Freq"))
plot.mod$order <- c(4, 3, 2, 1)
plot.mod <- plot.mod %>% arrange(order)
plot.mod <- plot.mod[-c(4)]
colnames(plot.mod) <- c("Response", "N", "Proportion")

kable(plot.mod)
Response N Proportion
Yes, limited a lot 3 1.048951
Yes, limited a little 20 6.993007
No, not at all 257 89.860140
NA 6 2.097902

Climbing several flights of stairs

stairs <- prop.table(table(factor(d$Q42_sf3, levels = c("1", "2", "3")), exclude = NULL))*100
stairs <- as.data.frame(stairs)
stairs$answer <- substring(row.names(stairs), 1)
stairs$answer <- revalue(as.character(stairs$answer), c("1" = "Yes, limited a lot",  "2" = "Yes, limited a little", "3" = "No, not at all", "4" =  "NA"))

stairs$plot <- factor(stairs$answer, stairs$answer)

cols <- c(brewer.pal(3,"RdYlGn"),"grey")
stairs.plot <- ggplot(plot, aes(x = answer, y = Freq, fill = plot)) + theme(axis.text.x  = element_text(angle=90, vjust=.6)) +
      guides(fill = FALSE) +
      scale_fill_manual(values = cols) +
      ylab("Percent of total") +
      xlab("")
      
stairs.plot + geom_bar(aes(x = plot), data = stairs, stat = "identity", colour="black") 

stairs.tb <- as.factor(d$Q42_sf3)
stairs.tb <- summary(stairs.tb)
stairs.tb <- as.data.frame(stairs.tb)
stairs.tb$Var1 <- substring(row.names(stairs.tb), 1)
stairs.tb$answer <- revalue(as.character(stairs.tb$Var1), c("1" = "Yes, limited a lot",  "2" = "Yes, limited a little", "3" = "No, not at all", "NA's" =  "NA"))
plot.stairs <- merge(stairs, stairs.tb, by = "answer")
plot.stairs <- plot.stairs[-c(2, 4, 6)]
plot.stairs <- setcolorder(plot.stairs, c("answer", "stairs.tb", "Freq"))
plot.stairs$order <- c(4, 3, 2, 1)
plot.stairs <- plot.stairs %>% arrange(order)
plot.stairs <- plot.stairs[-c(4)]
colnames(plot.stairs) <- c("Response", "N", "Proportion")

kable(plot.stairs)
Response N Proportion
Yes, limited a lot 5 1.748252
Yes, limited a little 20 6.993007
No, not at all 255 89.160839
NA 6 2.097902

Q43: During the past 4 weeks, have you had any of the following problems with your work or other regular daily activities as a result of your physical health?

Accomplished less than you would like

Q43.a <- prop.table(table(factor(d$Q43_sf4, levels = c("1", "2")), exclude = NULL))*100
Q43.a <- as.data.frame(Q43.a)
Q43.a$answer <- substring(row.names(Q43.a), 1)
Q43.a$answer <- revalue(as.character(Q43.a$answer), c("1" = "Yes",  "2" = "No", "3" = "NA"))

Q43.a$plot <- factor(Q43.a$answer, Q43.a$answer)

cols <- c("#31a354","#f03b20", "grey") #get colors for plot
Q43.a.plot <- ggplot(plot, aes(x = answer, y = Freq, fill = plot)) + theme(axis.text.x  = element_text(angle=90, vjust=.6)) #order responses as in t5

Q43.a.plot + geom_bar(aes(x = plot), data = Q43.a, stat = "identity", colour="black") +
      guides(fill = FALSE) +
      scale_fill_manual(values = cols) +
      ylab("Percent of total") +
      xlab("Response")

Q43.a.tb <- as.factor(d$Q43_sf4)
Q43.a.tb <- summary(Q43.a.tb)
Q43.a.tb <- as.data.frame(Q43.a.tb)
Q43.a.tb$Var1 <- substring(row.names(Q43.a.tb), 1)
Q43.a.tb$answer <- revalue(as.character(Q43.a.tb$Var1), c("1" = "Yes", "2" = "No", "NA's" = "NA"))
plot.Q43.a <- merge(Q43.a, Q43.a.tb, by = "answer")
plot.Q43.a <- plot.Q43.a[-c(2, 4, 6)]
plot.Q43.a <- setcolorder(plot.Q43.a, c("answer", "Q43.a.tb", "Freq"))
plot.Q43.a$order <- c(3, 2, 1)
plot.Q43.a <- plot.Q43.a %>% arrange(order)
plot.Q43.a <- plot.Q43.a[-c(4)]
colnames(plot.Q43.a) <- c("Response", "N", "Proportion")

kable(plot.Q43.a)
Response N Proportion
Yes 58 20.279720
No 222 77.622378
NA 6 2.097902

Were limited in the kind of work or other activities

Q43.b <- prop.table(table(factor(d$Q43_sf5, levels = c("1", "2")), exclude = NULL))*100
Q43.b <- as.data.frame(Q43.b)
Q43.b$answer <- substring(row.names(Q43.b), 1)
Q43.b$answer <- revalue(as.character(Q43.b$answer), c("1" = "Yes",  "2" = "No", "3" = "NA"))

Q43.b$plot <- factor(Q43.b$answer, Q43.b$answer)

cols <- c("#31a354","#f03b20", "grey") #get colors for plot
Q43.b.plot <- ggplot(plot, aes(x = answer, y = Freq, fill = plot)) + theme(axis.text.x  = element_text(angle=90, vjust=.6)) #order responses as in t5

Q43.b.plot + geom_bar(aes(x = plot), data = Q43.b, stat = "identity", colour="black") +
      guides(fill = FALSE) +
      scale_fill_manual(values = cols) +
      ylab("Percent of total") +
      xlab("Response")

Q43.b.tb <- as.factor(d$Q43_sf5)
Q43.b.tb <- summary(Q43.b.tb)
Q43.b.tb <- as.data.frame(Q43.b.tb)
Q43.b.tb$Var1 <- substring(row.names(Q43.b.tb), 1)
Q43.b.tb$answer <- revalue(as.character(Q43.b.tb$Var1), c("1" = "Yes", "2" = "No", "NA's" = "NA"))
plot.Q43.b <- merge(Q43.b, Q43.b.tb, by = "answer")
plot.Q43.b <- plot.Q43.b[-c(2, 4, 6)]
plot.Q43.b <- setcolorder(plot.Q43.b, c("answer", "Q43.b.tb", "Freq"))
plot.Q43.b$order <- c(3, 2, 1)
plot.Q43.b <- plot.Q43.b %>% arrange(order)
plot.Q43.b <- plot.Q43.b[-c(4)]
colnames(plot.Q43.b) <- c("Response", "N", "Proportion")

kable(plot.Q43.b)
Response N Proportion
Yes 48 16.783217
No 232 81.118881
NA 6 2.097902

Q44: During the past 4 weeks, have you had any of the following problems with your work or other regular daily activities as a result of any emotional problems (such as feeling depressed or anxious)?

Accomplished less than you would like

Q44.a <- prop.table(table(factor(d$Q44_sf6, levels = c("1", "2")), exclude = NULL))*100
Q44.a <- as.data.frame(Q44.a)
Q44.a$answer <- substring(row.names(Q44.a), 1)
Q44.a$answer <- revalue(as.character(Q44.a$answer), c("1" = "Yes",  "2" = "No", "3" = "NA"))

Q44.a$plot <- factor(Q44.a$answer, Q44.a$answer)

cols <- c("#31a354","#f03b20", "grey") #get colors for plot
Q44.a.plot <- ggplot(plot, aes(x = answer, y = Freq, fill = plot)) + theme(axis.text.x  = element_text(angle=90, vjust=.6)) #order responses as in t5

Q44.a.plot + geom_bar(aes(x = plot), data = Q44.a, stat = "identity", colour="black") +
      guides(fill = FALSE) +
      scale_fill_manual(values = cols) +
      ylab("Percent of total") +
      xlab("Response")

Q44.a.tb <- as.factor(d$Q44_sf6)
Q44.a.tb <- summary(Q44.a.tb)
Q44.a.tb <- as.data.frame(Q44.a.tb)
Q44.a.tb$Var1 <- substring(row.names(Q44.a.tb), 1)
Q44.a.tb$answer <- revalue(as.character(Q44.a.tb$Var1), c("1" = "Yes", "2" = "No", "NA's" = "NA"))
plot.Q44.a <- merge(Q44.a, Q44.a.tb, by = "answer")
plot.Q44.a <- plot.Q44.a[-c(2, 4, 6)]
plot.Q44.a <- setcolorder(plot.Q44.a, c("answer", "Q44.a.tb", "Freq"))
plot.Q44.a$order <- c(3, 2, 1)
plot.Q44.a <- plot.Q44.a %>% arrange(order)
plot.Q44.a <- plot.Q44.a[-c(4)]
colnames(plot.Q44.a) <- c("Response", "N", "Proportion")

kable(plot.Q44.a)
Response N Proportion
Yes 62 21.678322
No 218 76.223776
NA 6 2.097902

Did work or activities less carefully than usual

Q44.b <- prop.table(table(factor(d$Q44_sf7, levels = c("1", "2")), exclude = NULL))*100
Q44.b <- as.data.frame(Q44.b)
Q44.b$answer <- substring(row.names(Q44.b), 1)
Q44.b$answer <- revalue(as.character(Q44.b$answer), c("1" = "Yes",  "2" = "No", "3" = "NA"))

Q44.b$plot <- factor(Q44.b$answer, Q44.b$answer)

cols <- c("#31a354","#f03b20", "grey") #get colors for plot
Q44.b.plot <- ggplot(plot, aes(x = answer, y = Freq, fill = plot)) + theme(axis.text.x  = element_text(angle=90, vjust=.6)) #order responses as in t5

Q44.b.plot + geom_bar(aes(x = plot), data = Q44.b, stat = "identity", colour="black") +
      guides(fill = FALSE) +
      scale_fill_manual(values = cols) +
      ylab("Percent of total") +
      xlab("Response")

Q44.b.tb <- as.factor(d$Q44_sf7)
Q44.b.tb <- summary(Q44.b.tb)
Q44.b.tb <- as.data.frame(Q44.b.tb)
Q44.b.tb$Var1 <- substring(row.names(Q44.b.tb), 1)
Q44.b.tb$answer <- revalue(as.character(Q44.b.tb$Var1), c("1" = "Yes", "2" = "No", "NA's" = "NA"))
plot.Q44.b <- merge(Q44.b, Q44.b.tb, by = "answer")
plot.Q44.b <- plot.Q44.b[-c(2, 4, 6)]
plot.Q44.b <- setcolorder(plot.Q44.b, c("answer", "Q44.b.tb", "Freq"))
plot.Q44.b$order <- c(3, 2, 1)
plot.Q44.b <- plot.Q44.b %>% arrange(order)
plot.Q44.b <- plot.Q44.b[-c(4)]
colnames(plot.Q44.b) <- c("Response", "N", "Proportion")

kable(plot.Q44.b)
Response N Proportion
Yes 50 17.482518
No 230 80.419580
NA 6 2.097902

Q45:During the past 4 weeks, how much did pain interfere with your normal work (including work outside the home and housework)?

pain <- prop.table(table(factor(d$Q45_sf8, levels = c("1", "2", "3", "4", "5")), exclude = NULL))*100
pain <- as.data.frame(pain)
pain$answer <- substring(row.names(pain), 1)
pain$answer <- revalue(as.character(pain$answer), c("1" = "Not at all",  "2" = "Slightly", "3" = "Moderately", "4" =  "Quite a bit", "5" = "Extremely", "6" = "NA"))

pain$plot <- factor(pain$answer, pain$answer)


pain.plot <- ggplot(plot, aes(x = answer, y = Freq, fill = plot)) + theme(axis.text.x  = element_text(angle=90, vjust=.6)) +
      guides(fill = FALSE) +
      scale_fill_brewer(palette = "BuGn", direction=-1) +
      ylab("Percent of total") +
      xlab("")
      
pain.plot + geom_bar(aes(x = plot), data = pain, stat = "identity", colour="black") 

pain.tb <- as.factor(d$Q45_sf8)
pain.tb <- summary(pain.tb)
pain.tb <- as.data.frame(pain.tb)
pain.tb$Var1 <- substring(row.names(pain.tb), 1)
pain.tb$answer <- revalue(as.character(pain.tb$Var1), c("1" = "Not at all",  "2" = "Slightly", "3" = "Moderately", "4" =  "Quite a bit", "5" = "Extremely", "NA's" = "NA"))
plot.pain <- merge(pain, pain.tb, by = "answer")
plot.pain <- plot.pain[-c(2, 4, 6)]
plot.pain <- setcolorder(plot.pain, c("answer", "pain.tb", "Freq"))
plot.pain$order <- c(5, 3, 6, 1, 4, 2)
plot.pain <- plot.pain %>% arrange(order)
plot.pain <- plot.pain[-c(4)]
colnames(plot.pain) <- c("Response", "N", "Proportion")

kable(plot.pain)
Response N Proportion
Not at all 176 61.538461
Slightly 74 25.874126
Moderately 18 6.293706
Quite a bit 9 3.146853
Extremely 3 1.048951
NA 6 2.097902

Q46:How much of the time during the past 4 weeks…

Have you felt calm and peaceful?

peace <- prop.table(table(factor(d$Q46_sf9, levels = c("1", "2", "3", "4", "5", "6")), exclude = NULL))*100
peace <- as.data.frame(peace)
peace$answer <- substring(row.names(peace), 1)
peace$answer <- revalue(as.character(peace$answer), c("1" = "All of the time",  "2" = "Most of the time", "3" = "A good bit of the time", "4" =  "Some of the time", "5" = "A little of the time", "6" = "None of the time", "7" =  "NA"))

peace$plot <- factor(peace$answer, peace$answer)

peace.plot <- ggplot(plot, aes(x = answer, y = Freq, fill = plot)) + theme(axis.text.x  = element_text(angle=90, vjust=.6)) +
      guides(fill = FALSE) +
      scale_fill_brewer(palette = "BuGn", direction=-1)  +
      ylab("Percent of total") +
      xlab("")
      
peace.plot + geom_bar(aes(x = plot), data = peace, stat = "identity", colour="black") 

peace.tb <- as.factor(d$Q46_sf9)
peace.tb <- summary(peace.tb)
peace.tb <- as.data.frame(peace.tb)
peace.tb$Var1 <- substring(row.names(peace.tb), 1)
peace.tb$answer <- revalue(as.character(peace.tb$Var1), c("1" = "All of the time",  "2" = "Most of the time", "3" = "A good bit of the time", "4" =  "Some of the time", "5" = "A little of the time", "6" = "None of the time", "NA's" = "NA"))
plot.peace <- merge(peace, peace.tb, by = "answer")
plot.peace <- plot.peace[-c(2, 4, 6)]
plot.peace <- setcolorder(plot.peace, c("answer", "peace.tb", "Freq"))
plot.peace$order <- c(3, 5, 1, 2, 7, 6 ,4)
plot.peace <- plot.peace %>% arrange(order)
plot.peace <- plot.peace[-c(4)]
colnames(plot.peace) <- c("Response", "N", "Proportion")

kable(plot.peace)
Response N Proportion
All of the time 7 2.4475524
Most of the time 103 36.0139860
A good bit of the time 92 32.1678322
Some of the time 59 20.6293706
A little of the time 17 5.9440559
None of the time 1 0.3496503
NA 7 2.4475524

Did you have a lot of energy?

energy <- prop.table(table(factor(d$Q46_sf10, levels = c("1", "2", "3", "4", "5", "6")), exclude = NULL))*100
energy <- as.data.frame(energy)
energy$answer <- substring(row.names(energy), 1)
energy$answer <- revalue(as.character(energy$answer), c("1" = "All of the time",  "2" = "Most of the time", "3" = "A good bit of the time", "4" =  "Some of the time", "5" = "A little of the time", "6" = "None of the time", "7" =  "NA"))

energy$plot <- factor(energy$answer, energy$answer)

energy.plot <- ggplot(plot, aes(x = answer, y = Freq, fill = plot)) + theme(axis.text.x  = element_text(angle=90, vjust=.6)) +
      guides(fill = FALSE) +
      scale_fill_brewer(palette = "BuGn", direction=-1)  +
      ylab("Percent of total") +
      xlab("")
      
energy.plot + geom_bar(aes(x = plot), data = energy, stat = "identity", colour="black") 

energy.tb <- as.factor(d$Q46_sf10)
energy.tb <- summary(energy.tb)
energy.tb <- as.data.frame(energy.tb)
energy.tb$Var1 <- substring(row.names(energy.tb), 1)
energy.tb$answer <- revalue(as.character(energy.tb$Var1), c("1" = "All of the time",  "2" = "Most of the time", "3" = "A good bit of the time", "4" =  "Some of the time", "5" = "A little of the time", "6" = "None of the time", "NA's" = "NA"))
plot.energy <- merge(energy, energy.tb, by = "answer")
plot.energy <- plot.energy[-c(2, 4, 6)]
plot.energy <- setcolorder(plot.energy, c("answer", "energy.tb", "Freq"))
plot.energy$order <- c(3, 5, 1, 2, 7, 6 ,4)
plot.energy <- plot.energy %>% arrange(order)
plot.energy <- plot.energy[-c(4)]
colnames(plot.energy) <- c("Response", "N", "Proportion")

kable(plot.energy)
Response N Proportion
All of the time 11 3.8461538
Most of the time 137 47.9020979
A good bit of the time 68 23.7762238
Some of the time 46 16.0839161
A little of the time 14 4.8951049
None of the time 2 0.6993007
NA 8 2.7972028

Have you felt downhearted and blue?

blue <- prop.table(table(factor(d$Q46_sf11, levels = c("1", "2", "3", "4", "5", "6")), exclude = NULL))*100
blue <- as.data.frame(blue)
blue$answer <- substring(row.names(blue), 1)
blue$answer <- revalue(as.character(blue$answer), c("1" = "All of the time",  "2" = "Most of the time", "3" = "A good bit of the time", "4" =  "Some of the time", "5" = "A little of the time", "6" = "None of the time", "7" =  "NA"))

blue$plot <- factor(blue$answer, blue$answer)

blue.plot <- ggplot(plot, aes(x = answer, y = Freq, fill = plot)) + theme(axis.text.x  = element_text(angle=90, vjust=.6)) +
      guides(fill = FALSE) +
      scale_fill_brewer(palette = "BuGn", direction=-1)  +
      ylab("Percent of total") +
      xlab("")
      
blue.plot + geom_bar(aes(x = plot), data = blue, stat = "identity", colour="black") 

blue.tb <- as.factor(d$Q46_sf11)
blue.tb <- summary(blue.tb)
blue.tb <- as.data.frame(blue.tb)
blue.tb$Var1 <- substring(row.names(blue.tb), 1)

nval.df <- c("0") #insert missing values 
nval.df <- as.data.frame(nval.df)
nval.df$blue.tb <- as.factor(nval.df$nval.df)
nval.df$Var1 <- c("1")
nval.df <- nval.df[-c(1)]

blue.tb <- rbind(blue.tb, nval.df)

blue.tb$answer <- revalue(as.character(blue.tb$Var1), c("1" = "All of the time",  "2" = "Most of the time", "3" = "A good bit of the time", "4" =  "Some of the time", "5" = "A little of the time", "6" = "None of the time", "NA's" = "NA"))
plot.blue <- merge(blue, blue.tb, by = "answer")
plot.blue <- plot.blue[-c(2, 4, 6)]
plot.blue <- setcolorder(plot.blue, c("answer", "blue.tb", "Freq"))
plot.blue$order <- c(3, 5, 1, 2, 7, 6 ,4)
plot.blue <- plot.blue %>% arrange(order)
plot.blue <- plot.blue[-c(4)]
colnames(plot.blue) <- c("Response", "N", "Proportion")

kable(plot.blue)
Response N Proportion
All of the time 0 0.0000000
Most of the time 2 0.6993007
A good bit of the time 14 4.8951049
Some of the time 58 20.2797203
A little of the time 135 47.2027972
None of the time 69 24.1258741
NA 8 2.7972028

Q47:During the past 4 weeks, how much of the time has your physical health or emotional problems interfered with your social activities (like visiting friends, relatives, etc.)?

social <- prop.table(table(factor(d$Q47_sf12, levels = c("1", "2", "3", "4", "5", "6")), exclude = NULL))*100
social <- as.data.frame(social)
social$answer <- substring(row.names(social), 1)
social$answer <- revalue(as.character(social$answer), c("1" = "All of the time",  "2" = "Most of the time", "3" = "A good bit of the time", "4" =  "Some of the time", "5" = "A little of the time", "6" = "None of the time", "7" =  "NA"))

social$plot <- factor(social$answer, social$answer)

social.plot <- ggplot(plot, aes(x = answer, y = Freq, fill = plot)) + theme(axis.text.x  = element_text(angle=90, vjust=.6)) +
      guides(fill = FALSE) +
      scale_fill_brewer(palette = "BuGn", direction=-1)  +
      ylab("Percent of total") +
      xlab("")
      
social.plot + geom_bar(aes(x = plot), data = social, stat = "identity", colour="black") 

social.tb <- as.factor(d$Q47_sf12)
social.tb <- summary(social.tb)
social.tb <- as.data.frame(social.tb)
social.tb$Var1 <- substring(row.names(social.tb), 1)

nval.df <- c("0") #insert missing values 
nval.df <- as.data.frame(nval.df)
nval.df$social.tb <- as.factor(nval.df$nval.df)
nval.df$Var1 <- c("2")
nval.df <- nval.df[-c(1)]

social.tb <- rbind(social.tb, nval.df)

social.tb$answer <- revalue(as.character(social.tb$Var1), c("1" = "All of the time",  "2" = "Most of the time", "3" = "A good bit of the time", "4" =  "Some of the time", "5" = "A little of the time", "6" = "None of the time", "NA's" = "NA"))
plot.social <- merge(social, social.tb, by = "answer")
plot.social <- plot.social[-c(2, 4, 6)]
plot.social <- setcolorder(plot.social, c("answer", "social.tb", "Freq"))
plot.social$order <- c(3, 5, 1, 2, 7, 6 ,4)
plot.social <- plot.social %>% arrange(order)
plot.social <- plot.social[-c(4)]
colnames(plot.social) <- c("Response", "N", "Proportion")

kable(plot.social)
Response N Proportion
All of the time 2 0.6993007
Most of the time 0 0.0000000
A good bit of the time 12 4.1958042
Some of the time 23 8.0419580
A little of the time 66 23.0769231
None of the time 176 61.5384615
NA 7 2.4475524

Section 5:Personal Wellbeing

Q48:Thinking about your own life and personal circumstances, how satisfied are you…

With your life as a whole?

life <- prop.table(table(factor(d$Q48_pwb_a, levels = c("1", "2", "3", "4", "5", "6", "7", "8", "9", "10")), exclude = NULL))*100
life <- as.data.frame(life)
life$answer <- substring(row.names(life), 1)
life$answer <- revalue(as.character(life$answer), c("1" = "Completely satisfied", "5" = "Neutral", "10" = "Completely dissatisfied", "11" = "NA"))

cols <- c(rev(brewer.pal(10,"RdYlGn")),"grey")
life$plot <- factor(life$answer, life$answer)
life.plot <- ggplot(plot, aes(x = answer, y = Freq, fill = plot)) + theme(axis.text.x  = element_text(angle=90, vjust=.6)) +
      guides(fill = FALSE) +
      scale_fill_manual(values = cols) +
      ylab("Percent of total") +
      xlab("")
      
life.plot + geom_bar(aes(x = plot), data = life, stat = "identity", colour="black") 

life.tb <- as.factor(d$Q48_pwb_a)
life.tb <- summary(life.tb)
life.tb <- as.data.frame(life.tb)
life.tb$Var1 <- substring(row.names(life.tb), 1)

nval.df <- c("0") #insert missing values 
nval.df <- as.data.frame(nval.df)
nval.df$life.tb <- as.factor(nval.df$nval.df)
nval.df$Var1 <- c("10")
nval.df <- nval.df[-c(1)]

life.tb <- rbind(life.tb, nval.df)

life.tb$answer <- revalue(as.character(life.tb$Var1), c("1" = "Completely satisfied", "5" = "Neutral", "10" = "Completely dissatisfied", "NA's" = "NA"))
plot.life <- merge(life, life.tb, by = "answer")
plot.life <- plot.life[-c(2, 4, 6)]
plot.life <- setcolorder(plot.life, c("answer", "life.tb", "Freq"))
plot.life$order <- c(2, 3, 4, 6, 7, 8, 9, 10, 1, 11, 5)
plot.life <- plot.life %>% arrange(order)
plot.life <- plot.life[-c(4)]
colnames(plot.life) <- c("Response", "N", "Proportion")

kable(plot.life)
Response N Proportion
Completely satisfied 32 11.1888112
2 119 41.6083916
3 63 22.0279720
4 27 9.4405594
Neutral 14 4.8951049
6 10 3.4965035
7 9 3.1468531
8 3 1.0489510
9 2 0.6993007
Completely dissatisfied 0 0.0000000
NA 7 2.4475524

With your standard of living?

living <- prop.table(table(factor(d$Q48_pwb_b, levels = c("1", "2", "3", "4", "5", "6", "7", "8", "9", "10")), exclude = NULL))*100
living <- as.data.frame(living)
living$answer <- substring(row.names(living), 1)
living$answer <- revalue(as.character(living$answer), c("1" = "Completely satisfied", "5" = "Neutral", "10" = "Completely dissatisfied", "11" = "NA"))

living$plot <- factor(living$answer, living$answer)
cols <- c(rev(brewer.pal(10,"RdYlGn")),"grey")
living.plot <- ggplot(plot, aes(x = answer, y = Freq, fill = plot)) + theme(axis.text.x  = element_text(angle=90, vjust=.6)) +
      guides(fill = FALSE) +
      scale_fill_manual(values = cols)  +
      ylab("Percent of total") +
      xlab("")
      
living.plot + geom_bar(aes(x = plot), data = living, stat = "identity", colour="black") 

living.tb <- as.factor(d$Q48_pwb_b)
living.tb <- summary(living.tb)
living.tb <- as.data.frame(living.tb)
living.tb$Var1 <- substring(row.names(living.tb), 1)

nval.df <- c("0") #insert missing values 
nval.df <- as.data.frame(nval.df)
nval.df$living.tb <- as.factor(nval.df$nval.df)
nval.df$Var1 <- c("9")
nval.df <- nval.df[-c(1)]

living.tb <- rbind(living.tb, nval.df)

living.tb$answer <- revalue(as.character(living.tb$Var1), c("1" = "Completely satisfied", "5" = "Neutral", "10" = "Completely dissatisfied", "NA's" = "NA"))
plot.living <- merge(living, living.tb, by = "answer")
plot.living <- plot.living[-c(2, 4, 6)]
plot.living <- setcolorder(plot.living, c("answer", "living.tb", "Freq"))
plot.living$order <- c(2, 3, 4, 6, 7, 8, 9, 10, 1, 11, 5)
plot.living <- plot.living %>% arrange(order)
plot.living <- plot.living[-c(4)]
colnames(plot.living) <- c("Response", "N", "Proportion")

kable(plot.living)
Response N Proportion
Completely satisfied 83 29.0209790
2 99 34.6153846
3 50 17.4825175
4 22 7.6923077
Neutral 12 4.1958042
6 3 1.0489510
7 4 1.3986014
8 4 1.3986014
9 0 0.0000000
Completely dissatisfied 2 0.6993007
NA 7 2.4475524

With your health?

healthsat <- prop.table(table(factor(d$Q48_pwb_c, levels = c("1", "2", "3", "4", "5", "6", "7", "8", "9", "10")), exclude = NULL))*100
healthsat <- as.data.frame(healthsat)
healthsat$answer <- substring(row.names(healthsat), 1)
healthsat$answer <- revalue(as.character(healthsat$answer), c("1" = "Completely satisfied", "5" = "Neutral", "10" = "Completely dissatisfied", "11" = "NA"))

healthsat$plot <- factor(healthsat$answer, healthsat$answer)
cols <- c(rev(brewer.pal(10,"RdYlGn")),"grey")
healthsat.plot <- ggplot(plot, aes(x = answer, y = Freq, fill = plot)) + theme(axis.text.x  = element_text(angle=90, vjust=.6)) +
      guides(fill = FALSE) +
      scale_fill_manual(values = cols)  +
      ylab("Percent of total") +
      xlab("")
      
healthsat.plot + geom_bar(aes(x = plot), data = healthsat, stat = "identity", colour="black") 

healthsat.tb <- as.factor(d$Q48_pwb_c)
healthsat.tb <- summary(healthsat.tb)
healthsat.tb <- as.data.frame(healthsat.tb)
healthsat.tb$Var1 <- substring(row.names(healthsat.tb), 1)

nval.df <- c("0") #insert missing values 
nval.df <- as.data.frame(nval.df)
nval.df$healthsat.tb <- as.factor(nval.df$nval.df)
nval.df$Var1 <- c("10")
nval.df <- nval.df[-c(1)]

healthsat.tb <- rbind(healthsat.tb, nval.df)

healthsat.tb$answer <- revalue(as.character(healthsat.tb$Var1), c("1" = "Completely satisfied", "5" = "Neutral", "10" = "Completely dissatisfied", "NA's" = "NA"))
plot.healthsat <- merge(healthsat, healthsat.tb, by = "answer")
plot.healthsat <- plot.healthsat[-c(2, 4, 6)]
plot.healthsat <- setcolorder(plot.healthsat, c("answer", "healthsat.tb", "Freq"))
plot.healthsat$order <- c(2, 3, 4, 6, 7, 8, 9, 10, 1, 11, 5)
plot.healthsat <- plot.healthsat %>% arrange(order)
plot.healthsat <- plot.healthsat[-c(4)]
colnames(plot.healthsat) <- c("Response", "N", "Proportion")

kable(plot.healthsat)
Response N Proportion
Completely satisfied 39 13.6363636
2 118 41.2587413
3 63 22.0279720
4 14 4.8951049
Neutral 11 3.8461538
6 14 4.8951049
7 13 4.5454545
8 6 2.0979021
9 1 0.3496503
Completely dissatisfied 0 0.0000000
NA 7 2.4475524

With what you are achieving in life?

ach <- prop.table(table(factor(d$Q48_pwb_d, levels = c("1", "2", "3", "4", "5", "6", "7", "8", "9", "10")), exclude = NULL))*100
ach <- as.data.frame(ach)
ach$answer <- substring(row.names(ach), 1)
ach$answer <- revalue(as.character(ach$answer), c("1" = "Completely satisfied", "5" = "Neutral", "10" = "Completely dissatisfied", "11" = "NA"))

ach$plot <- factor(ach$answer, ach$answer)
cols <- c(rev(brewer.pal(10,"RdYlGn")),"grey")
ach.plot <- ggplot(plot, aes(x = answer, y = Freq, fill = plot)) + theme(axis.text.x  = element_text(angle=90, vjust=.6)) +
      guides(fill = FALSE) +
      scale_fill_manual(values = cols)  +
      ylab("Percent of total") +
      xlab("")
      
ach.plot + geom_bar(aes(x = plot), data = ach, stat = "identity", colour="black") 

ach.tb <- as.factor(d$Q48_pwb_d)
ach.tb <- summary(ach.tb)
ach.tb <- as.data.frame(ach.tb)
ach.tb$Var1 <- substring(row.names(ach.tb), 1)

nval.df <- c("0") #insert missing values 
nval.df <- as.data.frame(nval.df)
nval.df$ach.tb <- as.factor(nval.df$nval.df)
nval.df$Var1 <- c("10")
nval.df <- nval.df[-c(1)]

ach.tb <- rbind(ach.tb, nval.df)

ach.tb$answer <- revalue(as.character(ach.tb$Var1), c("1" = "Completely satisfied", "5" = "Neutral", "10" = "Completely dissatisfied", "NA's" = "NA"))
plot.ach <- merge(ach, ach.tb, by = "answer")
plot.ach <- plot.ach[-c(2, 4, 6)]
plot.ach <- setcolorder(plot.ach, c("answer", "ach.tb", "Freq"))
plot.ach$order <- c(2, 3, 4, 6, 7, 8, 9, 10, 1, 11, 5)
plot.ach <- plot.ach %>% arrange(order)
plot.ach <- plot.ach[-c(4)]
colnames(plot.ach) <- c("Response", "N", "Proportion")

kable(plot.ach)
Response N Proportion
Completely satisfied 43 15.034965
2 91 31.818182
3 70 24.475524
4 25 8.741259
Neutral 21 7.342657
6 11 3.846154
7 4 1.398601
8 7 2.447552
9 7 2.447552
Completely dissatisfied 0 0.000000
NA 7 2.447552

With your personal relationships?

relat <- prop.table(table(factor(d$Q48_pwb_e, levels = c("1", "2", "3", "4", "5", "6", "7", "8", "9", "10")), exclude = NULL))*100
relat <- as.data.frame(relat)
relat$answer <- substring(row.names(relat), 1)
relat$answer <- revalue(as.character(relat$answer), c("1" = "Completely satisfied", "5" = "Neutral", "10" = "Completely dissatisfied", "11" = "NA"))

relat$plot <- factor(relat$answer, relat$answer)
cols <- c(rev(brewer.pal(10,"RdYlGn")),"grey")
relat.plot <- ggplot(plot, aes(x = answer, y = Freq, fill = plot)) + theme(axis.text.x  = element_text(angle=90, vjust=.6)) +
      guides(fill = FALSE) +
      scale_fill_manual(values = cols)  +
      ylab("Percent of total") +
      xlab("")
      
relat.plot + geom_bar(aes(x = plot), data = relat, stat = "identity", colour="black") 

relat.tb <- as.factor(d$Q48_pwb_e)
relat.tb <- summary(relat.tb)
relat.tb <- as.data.frame(relat.tb)
relat.tb$Var1 <- substring(row.names(relat.tb), 1)

relat.tb$answer <- revalue(as.character(relat.tb$Var1), c("1" = "Completely satisfied", "5" = "Neutral", "10" = "Completely dissatisfied", "NA's" = "NA"))
plot.relat <- merge(relat, relat.tb, by = "answer")
plot.relat <- plot.relat[-c(2, 4, 6)]
plot.relat <- setcolorder(plot.relat, c("answer", "relat.tb", "Freq"))
plot.relat$order <- c(2, 3, 4, 6, 7, 8, 9, 10, 1, 11, 5)
plot.relat <- plot.relat %>% arrange(order)
plot.relat <- plot.relat[-c(4)]
colnames(plot.relat) <- c("Response", "N", "Proportion")

kable(plot.relat)
Response N Proportion
Completely satisfied 54 18.8811189
2 105 36.7132867
3 44 15.3846154
4 30 10.4895105
Neutral 15 5.2447552
6 15 5.2447552
7 5 1.7482517
8 5 1.7482517
9 4 1.3986014
Completely dissatisfied 2 0.6993007
NA 7 2.4475524

With how safe you feel?

safe <- prop.table(table(factor(d$Q48_pwb_f, levels = c("1", "2", "3", "4", "5", "6", "7", "8", "9", "10")), exclude = NULL))*100
safe <- as.data.frame(safe)
safe$answer <- substring(row.names(safe), 1)
safe$answer <- revalue(as.character(safe$answer), c("1" = "Completely satisfied", "5" = "Neutral", "10" = "Completely dissatisfied", "11" = "NA"))

safe$plot <- factor(safe$answer, safe$answer)
cols <- c(rev(brewer.pal(10,"RdYlGn")),"grey")
safe.plot <- ggplot(plot, aes(x = answer, y = Freq, fill = plot)) + theme(axis.text.x  = element_text(angle=90, vjust=.6)) +
      guides(fill = FALSE) +
      scale_fill_manual(values = cols)  +
      ylab("Percent of total") +
      xlab("")
      
safe.plot + geom_bar(aes(x = plot), data = safe, stat = "identity", colour="black") 

safe.tb <- as.factor(d$Q48_pwb_f)
safe.tb <- summary(safe.tb)
safe.tb <- as.data.frame(safe.tb)
safe.tb$Var1 <- substring(row.names(safe.tb), 1)

nval.df <- c("0", "0") #insert missing values 
nval.df <- as.data.frame(nval.df)
nval.df$safe.tb <- as.factor(nval.df$nval.df)
nval.df$Var1 <- c("7", "8")
nval.df <- nval.df[-c(1)]

safe.tb <- rbind(safe.tb, nval.df)

safe.tb$answer <- revalue(as.character(safe.tb$Var1), c("1" = "Completely satisfied", "5" = "Neutral", "10" = "Completely dissatisfied", "NA's" = "NA"))
plot.safe <- merge(safe, safe.tb, by = "answer")
plot.safe <- plot.safe[-c(2, 4, 6)]
plot.safe <- setcolorder(plot.safe, c("answer", "safe.tb", "Freq"))
plot.safe$order <- c(2, 3, 4, 6, 7, 8, 9, 10, 1, 11, 5)
plot.safe <- plot.safe %>% arrange(order)
plot.safe <- plot.safe[-c(4)]
colnames(plot.safe) <- c("Response", "N", "Proportion")

kable(plot.safe)
Response N Proportion
Completely satisfied 123 43.0069930
2 97 33.9160839
3 24 8.3916084
4 17 5.9440559
Neutral 9 3.1468531
6 4 1.3986014
7 0 0.0000000
8 0 0.0000000
9 2 0.6993007
Completely dissatisfied 3 1.0489510
NA 7 2.4475524

With feeling part of your community?

com <- prop.table(table(factor(d$Q48_pwb_g, levels = c("1", "2", "3", "4", "5", "6", "7", "8", "9", "10")), exclude = NULL))*100
com <- as.data.frame(com)
com$answer <- substring(row.names(com), 1)
com$answer <- revalue(as.character(com$answer), c("1" = "Completely satisfied", "5" = "Neutral", "10" = "Completely dissatisfied", "11" = "NA"))

com$plot <- factor(com$answer, com$answer)
cols <- c(rev(brewer.pal(10,"RdYlGn")),"grey")
com.plot <- ggplot(plot, aes(x = answer, y = Freq, fill = plot)) + theme(axis.text.x  = element_text(angle=90, vjust=.6)) +
      guides(fill = FALSE) +
      scale_fill_manual(values = cols)  +
      ylab("Percent of total") +
      xlab("")
      
com.plot + geom_bar(aes(x = plot), data = com, stat = "identity", colour="black") 

com.tb <- as.factor(d$Q48_pwb_g)
com.tb <- summary(com.tb)
com.tb <- as.data.frame(com.tb)
com.tb$Var1 <- substring(row.names(com.tb), 1)
com.tb$answer <- revalue(as.character(com.tb$Var1), c("1" = "Completely satisfied", "5" = "Neutral", "10" = "Completely dissatisfied", "NA's" = "NA"))
plot.com <- merge(com, com.tb, by = "answer")
plot.com <- plot.com[-c(2, 4, 6)]
plot.com <- setcolorder(plot.com, c("answer", "com.tb", "Freq"))
plot.com$order <- c(2, 3, 4, 6, 7, 8, 9, 10, 1, 11, 5)
plot.com <- plot.com %>% arrange(order)
plot.com <- plot.com[-c(4)]
colnames(plot.com) <- c("Response", "N", "Proportion")

kable(plot.com)
Response N Proportion
Completely satisfied 50 17.482518
2 79 27.622378
3 60 20.979021
4 28 9.790210
Neutral 30 10.489510
6 17 5.944056
7 4 1.398601
8 3 1.048951
9 5 1.748252
Completely dissatisfied 3 1.048951
NA 7 2.447552

With your future security?

sec <- prop.table(table(factor(d$Q48_pwb_h, levels = c("1", "2", "3", "4", "5", "6", "7", "8", "9", "10")), exclude = NULL))*100
sec <- as.data.frame(sec)
sec$answer <- substring(row.names(sec), 1)
sec$answer <- revalue(as.character(sec$answer), c("1" = "Completely satisfied", "5" = "Neutral", "10" = "Completely dissatisfied", "11" = "NA"))

sec$plot <- factor(sec$answer, sec$answer)
cols <- c(rev(brewer.pal(10,"RdYlGn")),"grey")
sec.plot <- ggplot(plot, aes(x = answer, y = Freq, fill = plot)) + theme(axis.text.x  = element_text(angle=90, vjust=.6)) +
      guides(fill = FALSE) +
      scale_fill_manual(values = cols)  +
      ylab("Percent of total") +
      xlab("")
      
sec.plot + geom_bar(aes(x = plot), data = sec, stat = "identity", colour="black") 

sec.tb <- as.factor(d$Q48_pwb_h)
sec.tb <- summary(sec.tb)
sec.tb <- as.data.frame(sec.tb)
sec.tb$Var1 <- substring(row.names(sec.tb), 1)
sec.tb$answer <- revalue(as.character(sec.tb$Var1), c("1" = "Completely satisfied", "5" = "Neutral", "10" = "Completely dissatisfied", "NA's" = "NA"))
plot.sec <- merge(sec, sec.tb, by = "answer")
plot.sec <- plot.sec[-c(2, 4, 6)]
plot.sec <- setcolorder(plot.sec, c("answer", "sec.tb", "Freq"))
plot.sec$order <- c(2, 3, 4, 6, 7, 8, 9, 10, 1, 11, 5)
plot.sec <- plot.sec %>% arrange(order)
plot.sec <- plot.sec[-c(4)]
colnames(plot.sec) <- c("Response", "N", "Proportion")

kable(plot.sec)
Response N Proportion
Completely satisfied 49 17.132867
2 86 30.069930
3 49 17.132867
4 27 9.440559
Neutral 22 7.692308
6 20 6.993007
7 10 3.496504
8 6 2.097902
9 5 1.748252
Completely dissatisfied 5 1.748252
NA 7 2.447552

With your spirituality or religion?

spirit <- prop.table(table(factor(d$Q48_pwb_i, levels = c("1", "2", "3", "4", "5", "6", "7", "8", "9", "10")), exclude = NULL))*100
spirit <- as.data.frame(spirit)
spirit$answer <- substring(row.names(spirit), 1)
spirit$answer <- revalue(as.character(spirit$answer), c("1" = "Completely satisfied", "5" = "Neutral", "10" = "Completely dissatisfied", "11" = "NA"))

spirit$plot <- factor(spirit$answer, spirit$answer)
cols <- c(rev(brewer.pal(10,"RdYlGn")),"grey")
spirit.plot <- ggplot(plot, aes(x = answer, y = Freq, fill = plot)) + theme(axis.text.x  = element_text(angle=90, vjust=.6)) +
      guides(fill = FALSE) +
      scale_fill_manual(values = cols)  +
      ylab("Percent of total") +
      xlab("")
      
spirit.plot + geom_bar(aes(x = plot), data = spirit, stat = "identity", colour="black") 

spirit.tb <- as.factor(d$Q48_pwb_i)
spirit.tb <- summary(spirit.tb)
spirit.tb <- as.data.frame(spirit.tb)
spirit.tb$Var1 <- substring(row.names(spirit.tb), 1)

nval.df <- c("0", "0") #insert missing values 
nval.df <- as.data.frame(nval.df)
nval.df$spirit.tb <- as.factor(nval.df$nval.df)
nval.df$Var1 <- c("9", "10")
nval.df <- nval.df[-c(1)]

spirit.tb <- rbind(spirit.tb, nval.df)

spirit.tb$answer <- revalue(as.character(spirit.tb$Var1), c("1" = "Completely satisfied", "5" = "Neutral", "10" = "Completely dissatisfied", "NA's" = "NA"))
plot.spirit <- merge(spirit, spirit.tb, by = "answer")
plot.spirit <- plot.spirit[-c(2, 4, 6)]
plot.spirit <- setcolorder(plot.spirit, c("answer", "spirit.tb", "Freq"))
plot.spirit$order <- c(2, 3, 4, 6, 7, 8, 9, 10, 1, 11, 5)
plot.spirit <- plot.spirit %>% arrange(order)
plot.spirit <- plot.spirit[-c(4)]
colnames(plot.spirit) <- c("Response", "N", "Proportion")

kable(plot.spirit)
Response N Proportion
Completely satisfied 82 28.6713287
2 53 18.5314685
3 23 8.0419580
4 13 4.5454545
Neutral 97 33.9160839
6 5 1.7482517
7 4 1.3986014
8 2 0.6993007
9 0 0.0000000
Completely dissatisfied 0 0.0000000
NA 7 2.4475524

Section 6: Neighbourhood

Q49:Please indicate your satisfaction with each item

How satisfied are you with your neighbourhood as a good place to live? Are you…

nhds <- prop.table(table(factor(d$Q49_neighb_a, levels = c("1", "2", "3", "4", "5")), exclude = NULL))*100
nhds <- as.data.frame(nhds)
nhds$answer <- substring(row.names(nhds), 1)
nhds$answer <- revalue(as.character(nhds$answer), c("1" = "Strongly satisfied", "2" = "Satisfied", "3" = "Neither satisfied nor dissatisfied", "4" = "Dissatisfied", "5" = "Strongly dissatisfied", "6" = "NA"))

nhds$plot <- factor(nhds$answer, nhds$answer)
cols <- c(rev(brewer.pal(5,"RdYlGn")),"grey")
nhds.plot <- ggplot(plot, aes(x = answer, y = Freq, fill = plot)) + theme(axis.text.x  = element_text(angle=90, vjust=.6)) +
      guides(fill = FALSE) +
      scale_fill_manual(values = cols)  +
      ylab("Percent of total") +
      xlab("")
      
nhds.plot + geom_bar(aes(x = plot), data = nhds, stat = "identity", colour="black") 

nhds.tb <- as.factor(d$Q49_neighb_a)
nhds.tb <- summary(nhds.tb)
nhds.tb <- as.data.frame(nhds.tb)
nhds.tb$Var1 <- substring(row.names(nhds.tb), 1)
nhds.tb$answer <- revalue(as.character(nhds.tb$Var1), c("1" = "Strongly satisfied", "2" = "Satisfied", "3" = "Neither satisfied nor dissatisfied", "4" = "Dissatisfied", "5" = "Strongly dissatisfied", "NA's" = "NA"))
plot.nhds <- merge(nhds, nhds.tb, by = "answer")
plot.nhds <- plot.nhds[-c(2, 4, 6)]
plot.nhds <- setcolorder(plot.nhds, c("answer", "nhds.tb", "Freq"))
plot.nhds$order <- c(4, 6, 3, 2, 5, 1)
plot.nhds <- plot.nhds %>% arrange(order)
plot.nhds <- plot.nhds[-c(4)]
colnames(plot.nhds) <- c("Response", "N", "Proportion")

kable(plot.nhds)
Response N Proportion
Strongly satisfied 130 45.4545455
Satisfied 120 41.9580420
Neither satisfied nor dissatisfied 19 6.6433566
Dissatisfied 9 3.1468531
Strongly dissatisfied 1 0.3496503
NA 7 2.4475524

How satisfied are you with the number of people you know in your neighbourhood? Are you.

know <- prop.table(table(factor(d$Q49_neighb_b, levels = c("1", "2", "3", "4", "5")), exclude = NULL))*100
know <- as.data.frame(know)
know$answer <- substring(row.names(know), 1)
know$answer <- revalue(as.character(know$answer), c("1" = "Strongly satisfied", "2" = "Satisfied", "3" = "Neither satisfied nor dissatisfied", "4" = "Dissatisfied", "5" = "Strongly dissatisfied", "6" = "NA"))

know$plot <- factor(know$answer, know$answer)
cols <- c(rev(brewer.pal(5,"RdYlGn")),"grey")
know.plot <- ggplot(plot, aes(x = answer, y = Freq, fill = plot)) + theme(axis.text.x  = element_text(angle=90, vjust=.6)) +
      guides(fill = FALSE) +
      scale_fill_manual(values = cols)  +
      ylab("Percent of total") +
      xlab("")
      
know.plot + geom_bar(aes(x = plot), data = know, stat = "identity", colour="black") 

know.tb <- as.factor(d$Q49_neighb_b)
know.tb <- summary(know.tb)
know.tb <- as.data.frame(know.tb)
know.tb$Var1 <- substring(row.names(know.tb), 1)
know.tb$answer <- revalue(as.character(know.tb$Var1), c("1" = "Strongly satisfied", "2" = "Satisfied", "3" = "Neither satisfied nor dissatisfied", "4" = "Dissatisfied", "5" = "Strongly dissatisfied", "NA's" = "NA"))
plot.know <- merge(know, know.tb, by = "answer")
plot.know <- plot.know[-c(2, 4, 6)]
plot.know <- setcolorder(plot.know, c("answer", "know.tb", "Freq"))
plot.know$order <- c(4, 6, 3, 2, 5, 1)
plot.know <- plot.know %>% arrange(order)
plot.know <- plot.know[-c(4)]
colnames(plot.know) <- c("Response", "N", "Proportion")

kable(plot.know)
Response N Proportion
Strongly satisfied 40 13.986014
Satisfied 111 38.811189
Neither satisfied nor dissatisfied 84 29.370629
Dissatisfied 40 13.986014
Strongly dissatisfied 4 1.398601
NA 7 2.447552

How satisfied are you with the ethnic diversity of your neighbourhood? Are you…

div <- prop.table(table(factor(d$Q49_neighb_c, levels = c("1", "2", "3", "4", "5")), exclude = NULL))*100
div <- as.data.frame(div)
div$answer <- substring(row.names(div), 1)
div$answer <- revalue(as.character(div$answer), c("1" = "Strongly satisfied", "2" = "Satisfied", "3" = "Neither satisfied nor dissatisfied", "4" = "Dissatisfied", "5" = "Strongly dissatisfied", "6" = "NA"))

div$plot <- factor(div$answer, div$answer)
cols <- c(rev(brewer.pal(5,"RdYlGn")),"grey")
div.plot <- ggplot(plot, aes(x = answer, y = Freq, fill = plot)) + theme(axis.text.x  = element_text(angle=90, vjust=.6)) +
      guides(fill = FALSE) +
      scale_fill_manual(values = cols)  +
      ylab("Percent of total") +
      xlab("")
      
div.plot + geom_bar(aes(x = plot), data = div, stat = "identity", colour="black") 

div.tb <- as.factor(d$Q49_neighb_c)
div.tb <- summary(div.tb)
div.tb <- as.data.frame(div.tb)
div.tb$Var1 <- substring(row.names(div.tb), 1)
div.tb$answer <- revalue(as.character(div.tb$Var1), c("1" = "Strongly satisfied", "2" = "Satisfied", "3" = "Neither satisfied nor dissatisfied", "4" = "Dissatisfied", "5" = "Strongly dissatisfied", "NA's" = "NA"))
plot.div <- merge(div, div.tb, by = "answer")
plot.div <- plot.div[-c(2, 4, 6)]
plot.div <- setcolorder(plot.div, c("answer", "div.tb", "Freq"))
plot.div$order <- c(4, 6, 3, 2, 5, 1)
plot.div <- plot.div %>% arrange(order)
plot.div <- plot.div[-c(4)]
colnames(plot.div) <- c("Response", "N", "Proportion")

kable(plot.div)
Response N Proportion
Strongly satisfied 27 9.440559
Satisfied 79 27.622378
Neither satisfied nor dissatisfied 126 44.055944
Dissatisfied 39 13.636364
Strongly dissatisfied 8 2.797203
NA 7 2.447552

How satisfied are you with your neighbourhood as a good place to raise children? Are you…

rsch <- prop.table(table(factor(d$Q49_neighb_d, levels = c("1", "2", "3", "4", "5")), exclude = NULL))*100
rsch <- as.data.frame(rsch)
rsch$answer <- substring(row.names(rsch), 1)
rsch$answer <- revalue(as.character(rsch$answer), c("1" = "Strongly satisfied", "2" = "Satisfied", "3" = "Neither satisfied nor dissatisfied", "4" = "Dissatisfied", "5" = "Strongly dissatisfied", "6" = "NA"))

rsch$plot <- factor(rsch$answer, rsch$answer)
cols <- c(rev(brewer.pal(5,"RdYlGn")),"grey")
rsch.plot <- ggplot(plot, aes(x = answer, y = Freq, fill = plot)) + theme(axis.text.x  = element_text(angle=90, vjust=.6)) +
      guides(fill = FALSE) +
      scale_fill_manual(values = cols)  +
      ylab("Percent of total") +
      xlab("")
      
rsch.plot + geom_bar(aes(x = plot), data = rsch, stat = "identity", colour="black") 

rsch.tb <- as.factor(d$Q49_neighb_d)
rsch.tb <- summary(rsch.tb)
rsch.tb <- as.data.frame(rsch.tb)
rsch.tb$Var1 <- substring(row.names(rsch.tb), 1)
rsch.tb$answer <- revalue(as.character(rsch.tb$Var1), c("1" = "Strongly satisfied", "2" = "Satisfied", "3" = "Neither satisfied nor dissatisfied", "4" = "Dissatisfied", "5" = "Strongly dissatisfied", "NA's" = "NA"))
plot.rsch <- merge(rsch, rsch.tb, by = "answer")
plot.rsch <- plot.rsch[-c(2, 4, 6)]
plot.rsch <- setcolorder(plot.rsch, c("answer", "rsch.tb", "Freq"))
plot.rsch$order <- c(4, 6, 3, 2, 5, 1)
plot.rsch <- plot.rsch %>% arrange(order)
plot.rsch <- plot.rsch[-c(4)]
colnames(plot.rsch) <- c("Response", "N", "Proportion")

kable(plot.rsch)
Response N Proportion
Strongly satisfied 79 27.6223776
Satisfied 115 40.2097902
Neither satisfied nor dissatisfied 73 25.5244755
Dissatisfied 10 3.4965035
Strongly dissatisfied 2 0.6993007
NA 7 2.4475524

How satisfied are you with your neighbourhood as a good place to raise children? Are you…

rsch <- prop.table(table(factor(d$Q49_neighb_d, levels = c("1", "2", "3", "4", "5")), exclude = NULL))*100
rsch <- as.data.frame(rsch)
rsch$answer <- substring(row.names(rsch), 1)
rsch$answer <- revalue(as.character(rsch$answer), c("1" = "Strongly satisfied", "2" = "Satisfied", "3" = "Neither satisfied nor dissatisfied", "4" = "Dissatisfied", "5" = "Strongly dissatisfied", "6" = "NA"))

rsch$plot <- factor(rsch$answer, rsch$answer)
cols <- c(rev(brewer.pal(5,"RdYlGn")),"grey")
rsch.plot <- ggplot(plot, aes(x = answer, y = Freq, fill = plot)) + theme(axis.text.x  = element_text(angle=90, vjust=.6)) +
      guides(fill = FALSE) +
      scale_fill_manual(values = cols)  +
      ylab("Percent of total") +
      xlab("")
      
rsch.plot + geom_bar(aes(x = plot), data = rsch, stat = "identity", colour="black") 

rsch.tb <- as.factor(d$Q49_neighb_d)
rsch.tb <- summary(rsch.tb)
rsch.tb <- as.data.frame(rsch.tb)
rsch.tb$Var1 <- substring(row.names(rsch.tb), 1)
rsch.tb$answer <- revalue(as.character(rsch.tb$Var1), c("1" = "Strongly satisfied", "2" = "Satisfied", "3" = "Neither satisfied nor dissatisfied", "4" = "Dissatisfied", "5" = "Strongly dissatisfied", "NA's" = "NA"))
plot.rsch <- merge(rsch, rsch.tb, by = "answer")
plot.rsch <- plot.rsch[-c(2, 4, 6)]
plot.rsch <- setcolorder(plot.rsch, c("answer", "rsch.tb", "Freq"))
plot.rsch$order <- c(4, 6, 3, 2, 5, 1)
plot.rsch <- plot.rsch %>% arrange(order)
plot.rsch <- plot.rsch[-c(4)]
colnames(plot.rsch) <- c("Response", "N", "Proportion")

kable(plot.rsch)
Response N Proportion
Strongly satisfied 79 27.6223776
Satisfied 115 40.2097902
Neither satisfied nor dissatisfied 73 25.5244755
Dissatisfied 10 3.4965035
Strongly dissatisfied 2 0.6993007
NA 7 2.4475524

Section 7: Neighbourhood Selection

Q50:Before moving into your current dwelling, when you were looking for a neighbourhood to live in, to what extent were the following characteristics important?

Good access to public transportation

bus <- prop.table(table(factor(d$Q50_neigh_pref_a, levels = c("1", "2", "3", "4", "77")), exclude = NULL))*100
bus <- as.data.frame(bus)
bus$answer <- substring(row.names(bus), 1)
bus$answer <- revalue(as.character(bus$answer), c("1" = "Very important", "2" = "Somewhat important", "3" = "Not very important", "4" = "Not important at all", "5" = "Don't know", "6" = "NA"))

bus$plot <- factor(bus$answer, bus$answer)

cols <- c(rev(brewer.pal(4,"PRGn")),"grey", "grey")
bus.plot <- ggplot(plot, aes(x = answer, y = Freq, fill = plot)) + theme(axis.text.x  = element_text(angle=90, vjust=.6)) +
      guides(fill = FALSE) +
      scale_fill_manual(values = cols)  +
      ylab("Percent of total") +
      xlab("")
      
bus.plot + geom_bar(aes(x = plot), data = bus, stat = "identity", colour="black") 

bus.tb <- as.factor(d$Q50_neigh_pref_a)
bus.tb <- summary(bus.tb)
bus.tb <- as.data.frame(bus.tb)
bus.tb$Var1 <- substring(row.names(bus.tb), 1)
bus.tb$answer <- revalue(as.character(bus.tb$Var1), c("1" = "Very important", "2" = "Somewhat important", "3" = "Not very important", "4" = "Not important at all", "77" = "Don't know", "NA's" = "NA"))
plot.bus <- merge(bus, bus.tb, by = "answer")
plot.bus <- plot.bus[-c(2, 4, 6)]
plot.bus <- setcolorder(plot.bus, c("answer", "bus.tb", "Freq"))
plot.bus$order <- c(5, 6, 4, 3, 2, 1)
plot.bus <- plot.bus %>% arrange(order)
plot.bus <- plot.bus[-c(4)]
colnames(plot.bus) <- c("Response", "N", "Proportion")

kable(plot.bus)
Response N Proportion
Very important 99 34.6153846
Somewhat important 101 35.3146853
Not very important 52 18.1818182
Not important at all 26 9.0909091
Don’t know 1 0.3496503
NA 7 2.4475524

Sufficient parks and green spaces

parks <- prop.table(table(factor(d$Q50_neigh_pref_b, levels = c("1", "2", "3", "4", "77")), exclude = NULL))*100
parks <- as.data.frame(parks)
parks$answer <- substring(row.names(parks), 1)
parks$answer <- revalue(as.character(parks$answer), c("1" = "Very important", "2" = "Somewhat important", "3" = "Not very important", "4" = "Not important at all", "5" = "Don't know", "6" = "NA"))

parks$plot <- factor(parks$answer, parks$answer)

cols <- c(rev(brewer.pal(4,"PRGn")),"grey", "grey")
parks.plot <- ggplot(plot, aes(x = answer, y = Freq, fill = plot)) + theme(axis.text.x  = element_text(angle=90, vjust=.6)) +
      guides(fill = FALSE) +
      scale_fill_manual(values = cols)  +
      ylab("Percent of total") +
      xlab("")
      
parks.plot + geom_bar(aes(x = plot), data = parks, stat = "identity", colour="black") 

parks.tb <- as.factor(d$Q50_neigh_pref_b)
parks.tb <- summary(parks.tb)
parks.tb <- as.data.frame(parks.tb)
parks.tb$Var1 <- substring(row.names(parks.tb), 1)
parks.tb$answer <- revalue(as.character(parks.tb$Var1), c("1" = "Very important", "2" = "Somewhat important", "3" = "Not very important", "4" = "Not important at all", "77" = "Don't know", "NA's" = "NA"))
plot.parks <- merge(parks, parks.tb, by = "answer")
plot.parks <- plot.parks[-c(2, 4, 6)]
plot.parks <- setcolorder(plot.parks, c("answer", "parks.tb", "Freq"))
plot.parks$order <- c(5, 6, 4, 3, 2, 1)
plot.parks <- plot.parks %>% arrange(order)
plot.parks <- plot.parks[-c(4)]
colnames(plot.parks) <- c("Response", "N", "Proportion")

kable(plot.parks)
Response N Proportion
Very important 172 60.1398601
Somewhat important 91 31.8181818
Not very important 11 3.8461538
Not important at all 4 1.3986014
Don’t know 1 0.3496503
NA 7 2.4475524

Sufficient shops and services

shops <- prop.table(table(factor(d$Q50_neigh_pref_c, levels = c("1", "2", "3", "4", "77")), exclude = NULL))*100
shops <- as.data.frame(shops)
shops$answer <- substring(row.names(shops), 1)
shops$answer <- revalue(as.character(shops$answer), c("1" = "Very important", "2" = "Somewhat important", "3" = "Not very important", "4" = "Not important at all", "5" = "Don't know", "6" = "NA"))

shops$plot <- factor(shops$answer, shops$answer)

cols <- c(rev(brewer.pal(4,"PRGn")),"grey", "grey")
shops.plot <- ggplot(plot, aes(x = answer, y = Freq, fill = plot)) + theme(axis.text.x  = element_text(angle=90, vjust=.6)) +
      guides(fill = FALSE) +
      scale_fill_manual(values = cols)  +
      ylab("Percent of total") +
      xlab("")
      
shops.plot + geom_bar(aes(x = plot), data = shops, stat = "identity", colour="black") 

shops.tb <- as.factor(d$Q50_neigh_pref_c)
shops.tb <- summary(shops.tb)
shops.tb <- as.data.frame(shops.tb)
shops.tb$Var1 <- substring(row.names(shops.tb), 1)

nval.df <- c("0") #insert missing values 
nval.df <- as.data.frame(nval.df)
nval.df$shops.tb <- as.factor(nval.df$nval.df)
nval.df$Var1 <- c("77")
nval.df <- nval.df[-c(1)]

shops.tb <- rbind(shops.tb, nval.df)

shops.tb$answer <- revalue(as.character(shops.tb$Var1), c("1" = "Very important", "2" = "Somewhat important", "3" = "Not very important", "4" = "Not important at all", "77" = "Don't know", "NA's" = "NA"))

plot.shops <- merge(shops, shops.tb, by = "answer")
plot.shops <- plot.shops[-c(2, 4, 6)]
plot.shops <- setcolorder(plot.shops, c("answer", "shops.tb", "Freq"))
plot.shops$order <- c(5, 6, 4, 3, 2, 1)
plot.shops <- plot.shops %>% arrange(order)
plot.shops <- plot.shops[-c(4)]
colnames(plot.shops) <- c("Response", "N", "Proportion")

kable(plot.shops)
Response N Proportion
Very important 108 37.762238
Somewhat important 130 45.454546
Not very important 32 11.188811
Not important at all 9 3.146853
Don’t know 0 0.000000
NA 7 2.447552

Proximity to doctors, a pharmacy or other health services

docs <- prop.table(table(factor(d$Q50_neigh_pref_d, levels = c("1", "2", "3", "4", "77")), exclude = NULL))*100
docs <- as.data.frame(docs)
docs$answer <- substring(row.names(docs), 1)
docs$answer <- revalue(as.character(docs$answer), c("1" = "Very important", "2" = "Somewhat important", "3" = "Not very important", "4" = "Not important at all", "5" = "Don't know", "6" = "NA"))

docs$plot <- factor(docs$answer, docs$answer)

cols <- c(rev(brewer.pal(4,"PRGn")),"grey", "grey")
docs.plot <- ggplot(plot, aes(x = answer, y = Freq, fill = plot)) + theme(axis.text.x  = element_text(angle=90, vjust=.6)) +
      guides(fill = FALSE) +
      scale_fill_manual(values = cols)  +
      ylab("Percent of total") +
      xlab("")
      
docs.plot + geom_bar(aes(x = plot), data = docs, stat = "identity", colour="black") 

docs.tb <- as.factor(d$Q50_neigh_pref_d)
docs.tb <- summary(docs.tb)
docs.tb <- as.data.frame(docs.tb)
docs.tb$Var1 <- substring(row.names(docs.tb), 1)

docs.tb$answer <- revalue(as.character(docs.tb$Var1), c("1" = "Very important", "2" = "Somewhat important", "3" = "Not very important", "4" = "Not important at all", "77" = "Don't know", "NA's" = "NA"))

plot.docs <- merge(docs, docs.tb, by = "answer")
plot.docs <- plot.docs[-c(2, 4, 6)]
plot.docs <- setcolorder(plot.docs, c("answer", "docs.tb", "Freq"))
plot.docs$order <- c(5, 6, 4, 3, 2, 1)
plot.docs <- plot.docs %>% arrange(order)
plot.docs <- plot.docs[-c(4)]
colnames(plot.docs) <- c("Response", "N", "Proportion")

kable(plot.docs)
Response N Proportion
Very important 27 9.4405594
Somewhat important 107 37.4125874
Not very important 105 36.7132867
Not important at all 39 13.6363636
Don’t know 1 0.3496503
NA 7 2.4475524

A good knowledge of the neighbourhood

know <- prop.table(table(factor(d$Q50_neigh_pref_e, levels = c("1", "2", "3", "4", "77")), exclude = NULL))*100
know <- as.data.frame(know)
know$answer <- substring(row.names(know), 1)
know$answer <- revalue(as.character(know$answer), c("1" = "Very important", "2" = "Somewhat important", "3" = "Not very important", "4" = "Not important at all", "5" = "Don't know", "6" = "NA"))

know$plot <- factor(know$answer, know$answer)

cols <- c(rev(brewer.pal(4,"PRGn")),"grey", "grey")
know.plot <- ggplot(plot, aes(x = answer, y = Freq, fill = plot)) + theme(axis.text.x  = element_text(angle=90, vjust=.6)) +
      guides(fill = FALSE) +
      scale_fill_manual(values = cols)  +
      ylab("Percent of total") +
      xlab("")
      
know.plot + geom_bar(aes(x = plot), data = know, stat = "identity", colour="black") 

know.tb <- as.factor(d$Q50_neigh_pref_e)
know.tb <- summary(know.tb)
know.tb <- as.data.frame(know.tb)
know.tb$Var1 <- substring(row.names(know.tb), 1)

know.tb$answer <- revalue(as.character(know.tb$Var1), c("1" = "Very important", "2" = "Somewhat important", "3" = "Not very important", "4" = "Not important at all", "77" = "Don't know", "NA's" = "NA"))

plot.know <- merge(know, know.tb, by = "answer")
plot.know <- plot.know[-c(2, 4, 6)]
plot.know <- setcolorder(plot.know, c("answer", "know.tb", "Freq"))
plot.know$order <- c(5, 6, 4, 3, 2, 1)
plot.know <- plot.know %>% arrange(order)
plot.know <- plot.know[-c(4)]
colnames(plot.know) <- c("Response", "N", "Proportion")

kable(plot.know)
Response N Proportion
Very important 56 19.5804196
Somewhat important 131 45.8041958
Not very important 69 24.1258741
Not important at all 21 7.3426573
Don’t know 2 0.6993007
NA 7 2.4475524

Presence of relatives, friends or acquaintances

pres <- prop.table(table(factor(d$Q50_neigh_pref_f, levels = c("1", "2", "3", "4", "77")), exclude = NULL))*100
pres <- as.data.frame(pres)
pres$answer <- substring(row.names(pres), 1)
pres$answer <- revalue(as.character(pres$answer), c("1" = "Very important", "2" = "Somewhat important", "3" = "Not very important", "4" = "Not important at all", "5" = "Don't know", "6" = "NA"))

pres$plot <- factor(pres$answer, pres$answer)

cols <- c(rev(brewer.pal(4,"PRGn")),"grey", "grey")
pres.plot <- ggplot(plot, aes(x = answer, y = Freq, fill = plot)) + theme(axis.text.x  = element_text(angle=90, vjust=.6)) +
      guides(fill = FALSE) +
      scale_fill_manual(values = cols)  +
      ylab("Percent of total") +
      xlab("")
      
pres.plot + geom_bar(aes(x = plot), data = pres, stat = "identity", colour="black") 

pres.tb <- as.factor(d$Q50_neigh_pref_f)
pres.tb <- summary(pres.tb)
pres.tb <- as.data.frame(pres.tb)
pres.tb$Var1 <- substring(row.names(pres.tb), 1)

pres.tb$answer <- revalue(as.character(pres.tb$Var1), c("1" = "Very important", "2" = "Somewhat important", "3" = "Not very important", "4" = "Not important at all", "77" = "Don't know", "NA's" = "NA"))

plot.pres <- merge(pres, pres.tb, by = "answer")
plot.pres <- plot.pres[-c(2, 4, 6)]
plot.pres <- setcolorder(plot.pres, c("answer", "pres.tb", "Freq"))
plot.pres$order <- c(5, 6, 4, 3, 2, 1)
plot.pres <- plot.pres %>% arrange(order)
plot.pres <- plot.pres[-c(4)]
colnames(plot.pres) <- c("Response", "N", "Proportion")

kable(plot.pres)
Response N Proportion
Very important 40 13.986014
Somewhat important 96 33.566434
Not very important 79 27.622378
Not important at all 60 20.979021
Don’t know 4 1.398601
NA 7 2.447552

A neighbourhood where it is pleasant to walk

walkpleas <- prop.table(table(factor(d$Q50_neigh_pref_g, levels = c("1", "2", "3", "4", "77")), exclude = NULL))*100
walkpleas <- as.data.frame(walkpleas)
walkpleas$answer <- substring(row.names(walkpleas), 1)
walkpleas$answer <- revalue(as.character(walkpleas$answer), c("1" = "Very important", "2" = "Somewhat important", "3" = "Not very important", "4" = "Not important at all", "5" = "Don't know", "6" = "NA"))

walkpleas$plot <- factor(walkpleas$answer, walkpleas$answer)

cols <- c(rev(brewer.pal(4,"PRGn")),"grey", "grey")
walkpleas.plot <- ggplot(plot, aes(x = answer, y = Freq, fill = plot)) + theme(axis.text.x  = element_text(angle=90, vjust=.6)) +
      guides(fill = FALSE) +
      scale_fill_manual(values = cols)  +
      ylab("Percent of total") +
      xlab("")
      
walkpleas.plot + geom_bar(aes(x = plot), data = walkpleas, stat = "identity", colour="black") 

walkpleas.tb <- as.factor(d$Q50_neigh_pref_g)
walkpleas.tb <- summary(walkpleas.tb)
walkpleas.tb <- as.data.frame(walkpleas.tb)
walkpleas.tb$Var1 <- substring(row.names(walkpleas.tb), 1)

walkpleas.tb$answer <- revalue(as.character(walkpleas.tb$Var1), c("1" = "Very important", "2" = "Somewhat important", "3" = "Not very important", "4" = "Not important at all", "77" = "Don't know", "NA's" = "NA"))

plot.walkpleas <- merge(walkpleas, walkpleas.tb, by = "answer")
plot.walkpleas <- plot.walkpleas[-c(2, 4, 6)]
plot.walkpleas <- setcolorder(plot.walkpleas, c("answer", "walkpleas.tb", "Freq"))
plot.walkpleas$order <- c(5, 6, 4, 3, 2, 1)
plot.walkpleas <- plot.walkpleas %>% arrange(order)
plot.walkpleas <- plot.walkpleas[-c(4)]
colnames(plot.walkpleas) <- c("Response", "N", "Proportion")

kable(plot.walkpleas)
Response N Proportion
Very important 179 62.5874126
Somewhat important 85 29.7202797
Not very important 9 3.1468531
Not important at all 5 1.7482517
Don’t know 1 0.3496503
NA 7 2.4475524

A neighbourhood where it is practical to move around by car (ease of parking, low traffic, good access by car)

carprac <- prop.table(table(factor(d$Q50_neigh_pref_h, levels = c("1", "2", "3", "4", "77")), exclude = NULL))*100
carprac <- as.data.frame(carprac)
carprac$answer <- substring(row.names(carprac), 1)
carprac$answer <- revalue(as.character(carprac$answer), c("1" = "Very important", "2" = "Somewhat important", "3" = "Not very important", "4" = "Not important at all", "5" = "Don't know", "6" = "NA"))

carprac$plot <- factor(carprac$answer, carprac$answer)

cols <- c(rev(brewer.pal(4,"PRGn")),"grey", "grey")
carprac.plot <- ggplot(plot, aes(x = answer, y = Freq, fill = plot)) + theme(axis.text.x  = element_text(angle=90, vjust=.6)) +
      guides(fill = FALSE) +
      scale_fill_manual(values = cols)  +
      ylab("Percent of total") +
      xlab("")
      
carprac.plot + geom_bar(aes(x = plot), data = carprac, stat = "identity", colour="black") 

carprac.tb <- as.factor(d$Q50_neigh_pref_h)
carprac.tb <- summary(carprac.tb)
carprac.tb <- as.data.frame(carprac.tb)
carprac.tb$Var1 <- substring(row.names(carprac.tb), 1)

carprac.tb$answer <- revalue(as.character(carprac.tb$Var1), c("1" = "Very important", "2" = "Somewhat important", "3" = "Not very important", "4" = "Not important at all", "77" = "Don't know", "NA's" = "NA"))

plot.carprac <- merge(carprac, carprac.tb, by = "answer")
plot.carprac <- plot.carprac[-c(2, 4, 6)]
plot.carprac <- setcolorder(plot.carprac, c("answer", "carprac.tb", "Freq"))
plot.carprac$order <- c(5, 6, 4, 3, 2, 1)
plot.carprac <- plot.carprac %>% arrange(order)
plot.carprac <- plot.carprac[-c(4)]
colnames(plot.carprac) <- c("Response", "N", "Proportion")

kable(plot.carprac)
Response N Proportion
Very important 18 6.2937063
Somewhat important 75 26.2237762
Not very important 97 33.9160839
Not important at all 88 30.7692308
Don’t know 1 0.3496503
NA 7 2.4475524

Section 8:Demographics

Q51:What is your marital status? Are you.

marital <- prop.table(table(factor(d$Q51_marital_status, levels = c("1", "2", "3", "4")), exclude = NULL))*100
marital <- as.data.frame(marital)
marital$answer <- substring(row.names(marital), 1)
marital$answer <- revalue(as.character(marital$answer), c("1" = "Single", "2" = "Married/commonlaw", "3" = "Separated/divorced", "4" = "Widowed", "5" = "NA"))

marital$plot <- factor(marital$answer, marital$answer)

marital.plot <- ggplot(plot, aes(x = answer, y = Freq, fill = plot)) + theme(axis.text.x  = element_text(angle=90, vjust=.6)) +
      guides(fill = FALSE) +
      scale_fill_brewer(palette = "Set3")  +
      ylab("Percent of total") +
      xlab("")
      
marital.plot + geom_bar(aes(x = plot), data = marital, stat = "identity", colour="black") 

marital.tb <- as.factor(d$Q51_marital_status)
marital.tb <- summary(marital.tb)
marital.tb <- as.data.frame(marital.tb)
marital.tb$Var1 <- substring(row.names(marital.tb), 1)

marital.tb$answer <- revalue(as.character(marital.tb$Var1), c("1" = "Single", "2" = "Married/commonlaw", "3" = "Separated/divorced", "4" = "Widowed", "NA's" = "NA"))

plot.marital <- merge(marital, marital.tb, by = "answer")
plot.marital <- plot.marital[-c(2, 4, 6)]
plot.marital <- setcolorder(plot.marital, c("answer", "marital.tb", "Freq"))
plot.marital$order <- c(2, 5, 3, 1, 4)
plot.marital <- plot.marital %>% arrange(order)
plot.marital <- plot.marital[-c(4)]
colnames(plot.marital) <- c("Response", "N", "Proportion")

kable(plot.marital)
Response N Proportion
Single 54 18.8811189
Married/commonlaw 200 69.9300699
Separated/divorced 23 8.0419580
Widowed 2 0.6993007
NA 7 2.4475524

Q52:Do you have children?

kids <- prop.table(table(factor(d$Q52_children, levels = c("1", "2")), exclude=NULL))*100
kids <- as.data.frame(kids)
kids$answer <- substring(row.names(kids), 1)
kids$answer <- revalue(as.character(kids$answer), c("1" = "Yes",  "2" = "No", "3" = "NA"))

kids$plot <- factor(kids$answer, kids$answer)

cols <- c("#31a354","#f03b20", "grey") #get colors for plot
kids.plot <- ggplot(plot, aes(x = answer, y = Freq, fill = plot)) + theme(axis.text.x  = element_text(angle=90, vjust=.6)) #order responses as in t5

kids.plot + geom_bar(aes(x = plot), data = kids, stat = "identity", colour="black") +
      guides(fill = FALSE) +
      scale_fill_manual(values = cols) +
      ylab("Percent of total") +
      xlab("Response")

kids.tb <- as.factor(d$Q52_children)
kids.tb <- summary(kids.tb)
kids.tb <- as.data.frame(kids.tb)
kids.tb$Var1 <- substring(row.names(kids.tb), 1)
kids.tb$answer <- revalue(as.character(kids.tb$Var1), c("1" = "Yes", "2" = "No", "NA's" = "NA"))
plot.kids <- merge(kids, kids.tb, by = "answer")
plot.kids <- plot.kids[-c(2, 4, 6)]
plot.kids <- setcolorder(plot.kids, c("answer", "kids.tb", "Freq"))
plot.kids$order <- c(3, 2, 1)
plot.kids <- plot.kids %>% arrange(order)
plot.kids <- plot.kids[-c(4)]
colnames(plot.kids) <- c("Response", "N", "Proportion")

kable(plot.kids)
Response N Proportion
Yes 149 52.097902
No 130 45.454546
NA 7 2.447552

Q53:How many children do you have?

nkids <- prop.table(table(factor(d$Q53_living_children, levels = c("1", "2", "3", "4", "5", "6")), exclude=NULL))*100
nkids <- as.data.frame(nkids)
nkids <- as.data.frame(nkids)
nkids$answer <- substring(row.names(nkids), 1)
nkids$answer <- revalue(as.character(nkids$answer), c("7" = "No children"))

nkids$plot <- factor(nkids$answer, nkids$answer)

cols <- c(brewer.pal(6,"YlGnBu"),"grey")
nkids.plot <- ggplot(plot, aes(x = answer, y = Freq, fill = plot)) + theme(axis.text.x  = element_text(angle=90, vjust=.6)) #order responses as in t5

nkids.plot + geom_bar(aes(x = plot), data = nkids, stat = "identity", colour="black") +
      guides(fill = FALSE) +
      scale_fill_manual(values = cols) +
      ylab("Percent of total") +
      xlab("Response")

nkids.tb <- as.factor(d$Q53_living_children)
nkids.tb <- summary(nkids.tb)
nkids.tb <- as.data.frame(nkids.tb)
nkids.tb$Var1 <- substring(row.names(nkids.tb), 1)
nkids.tb$answer <- revalue(as.character(nkids.tb$Var1), c("NA's" = "No children"))
plot.nkids <- merge(nkids, nkids.tb, by = "answer")
plot.nkids <- plot.nkids[-c(2, 4, 6)]
plot.nkids <- setcolorder(plot.nkids, c("answer", "nkids.tb", "Freq"))

colnames(plot.nkids) <- c("Response", "N", "Proportion")

kable(plot.nkids)
Response N Proportion
1 39 13.6363636
2 82 28.6713287
3 23 8.0419580
4 2 0.6993007
5 2 0.6993007
6 1 0.3496503
No children 137 47.9020979

Q54:What is your current living arrangement? Do you live.

livewith <- prop.table(table(factor(d$Q54_living_arrange, levels = c("[1]", "[2]", "[3]", "[4]", "[5]", "[6]", "[7]", "[2, 3, 4, 7, 6]", "[2, 3, 4]", "[2, 3, 5]", "[2, 3]", "[2, 5]", "[2, 6]", "[2, 7]")), exclude=NULL))*100
livewith <- as.data.frame(livewith)
livewith <- as.data.frame(livewith)
livewith$answer <- substring(row.names(livewith), 1)
livewith$answer <- revalue(as.character(livewith$answer), c("1" = "Alone", "2" = "With a spouse/partner", "3" = "With children", "4" = "With grandchildren", "5" = "With relatives/siblings", "6" = "With friends", "7" = "With other people", "8" = "With spouse, children, grandchildren, friends & others", "9" = "With spouse, children & grandchildren", "10" = "With spouse, children & relatives/siblings", "11" = "With spouse & children", "12" = "With spouse & relatives/siblings", "13" = "With spouse & friends", "14" = "With spouse & others", "15" = "NA"))

livewith$plot <- factor(livewith$answer, livewith$answer)

livewith.plot <- ggplot(plot, aes(x = answer, y = Freq, fill = plot)) + theme(axis.text.x  = element_text(angle=90, vjust=.6)) #order responses as in t5

livewith.plot + geom_bar(aes(x = plot), data = livewith, stat = "identity", colour="black") +
      guides(fill = FALSE) +
      scale_fill_brewer(palette = "Set3") +
      ylab("Percent of total") +
      xlab("Response")

livewith.tb <- as.factor(d$Q54_living_arrange)
livewith.tb <- summary(livewith.tb)
livewith.tb <- as.data.frame(livewith.tb)
livewith.tb$Var1 <- substring(row.names(livewith.tb), 1)


nval.df <- c("0", "7") #insert missing values 
nval.df <- as.data.frame(nval.df)
nval.df$livewith.tb <- as.factor(nval.df$nval.df)
nval.df$Var1 <- c("[4]", "NA")
nval.df <- nval.df[-c(1)]

livewith.tb <- rbind(livewith.tb, nval.df)

livewith.tb$answer <- revalue(as.character(livewith.tb$Var1), c("[1]" = "Alone", "[2]" = "With a spouse/partner", "[3]" = "With children", "[4]" = "With grandchildren", "[5]" = "With relatives/siblings", "[6]" = "With friends", "[7]" = "With other people", "[2, 3, 4, 7, 6]" = "With spouse, children, grandchildren, friends & others", "[2, 3, 4]" = "With spouse, children & grandchildren", "[2, 3, 5]" = "With spouse, children & relatives/siblings", "[2, 3]" = "With spouse & children",  "[2, 5]" = "With spouse & relatives/siblings", "[2, 6]" = "With spouse & friends", "[2, 7]" = "With spouse & others"))
plot.livewith <- merge(livewith, livewith.tb, by = "answer")
plot.livewith <- plot.livewith[-c(2, 4, 6)]
plot.livewith <- setcolorder(plot.livewith, c("answer", "livewith.tb", "Freq"))
plot.livewith$order <- c(3, 15, 1, 7, 4, 13, 6, 5, 2, 10, 9, 11, 12, 8, 14)
plot.livewith <- plot.livewith %>% arrange(order)
plot.livewith <- plot.livewith[-c(4)]
colnames(plot.livewith) <- c("Response", "N", "Proportion")

kable(plot.livewith)
Response N Proportion
With a spouse/partner 120 41.9580420
With spouse & children 77 26.9230769
Alone 43 15.0349650
With friends 11 3.8461538
With relatives/siblings 8 2.7972028
With other people 7 2.4475524
With children 4 1.3986014
With spouse, children & relatives/siblings 3 1.0489510
With spouse & others 2 0.6993007
With spouse & friends 1 0.3496503
With spouse & relatives/siblings 1 0.3496503
With spouse, children & grandchildren 1 0.3496503
With grandchildren 0 0.0000000
With spouse, children, grandchildren, friends & others 1 0.3496503
NA 7 2.4475524

Q57:How many adults aged 16 or older live in your household including yourself?

ggplot(d, aes(x = d$Q57_adults_household)) + geom_bar(na.rm = TRUE) + xlab("Number of adults in household")

summary(d$Q57_adults_household)
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max.    NA's 
##   1.000   2.000   2.000   2.202   2.000  16.000      23

Q58:When did you move to your current residence?

ggplot(d, aes(x = d$Q58_residence.time)) + geom_bar(na.rm = TRUE, binwidth = 1) + xlab("Number of years at residence")

summary(d$Q58_residence.time)
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max.    NA's 
##   1.000   2.000   5.000   7.711  10.500  38.000      23

Q59:Were you born in Canada?

can <- prop.table(table(factor(d$Q59_born_can, levels = c("1", "2")), exclude=NULL))*100
can <- as.data.frame(can)
can$answer <- substring(row.names(can), 1)
can$answer <- revalue(as.character(can$answer), c("1" = "Yes",  "2" = "No", "3" = "NA"))

can$plot <- factor(can$answer, can$answer)

cols <- c("#31a354","#f03b20", "grey") #get colors for plot
can.plot <- ggplot(plot, aes(x = answer, y = Freq, fill = plot)) + theme(axis.text.x  = element_text(angle=90, vjust=.6)) #order responses as in t5

can.plot + geom_bar(aes(x = plot), data = can, stat = "identity", colour="black") +
      guides(fill = FALSE) +
      scale_fill_manual(values = cols) +
      ylab("Percent of total") +
      xlab("Response")

can.tb <- as.factor(d$Q59_born_can)
can.tb <- summary(can.tb)
can.tb <- as.data.frame(can.tb)
can.tb$Var1 <- substring(row.names(can.tb), 1)
can.tb$answer <- revalue(as.character(can.tb$Var1), c("1" = "Yes", "2" = "No", "NA's" = "NA"))
plot.can <- merge(can, can.tb, by = "answer")
plot.can <- plot.can[-c(2, 4, 6)]
plot.can <- setcolorder(plot.can, c("answer", "can.tb", "Freq"))
plot.can$order <- c(3, 2, 1)
plot.can <- plot.can %>% arrange(order)
plot.can <- plot.can[-c(4)]
colnames(plot.can) <- c("Response", "N", "Proportion")

kable(plot.can)
Response N Proportion
Yes 194 67.832168
No 69 24.125874
NA 23 8.041958
imm <- d %>%  
  select(Q59_born_can, Q60_move_can, Q60_numYears) %>%
  filter(Q59_born_can == "2")
ggplot(imm, aes(x = Q60_move_can)) + geom_bar(na.rm = TRUE, binwidth = 1) + xlab("Moved to  Canada")

summary(d$Q60_move_can)
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max.    NA's 
##    1946    1972    1988    1987    2002    2017     217
summary(d$Q60_numYears)
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max.    NA's 
##     0.0    15.0    29.0    30.3    45.0    71.0     217

Q61:To which ethnic or cultural groups did your ancestors belong? (Check all that apply)

ethnic <- prop.table(table(factor(d$Q61_group_id, levels = c("[1]", "[1, 2, 4]", "[1, 4]", "[2]", "[2, 4]", "[3]", "[4]", "[4, 6]", "[5]", "[6]", "[77]")), exclude=NULL))*100
ethnic <- as.data.frame(ethnic)
ethnic <- as.data.frame(ethnic)
ethnic$answer <- substring(row.names(ethnic), 1)
ethnic$answer <- revalue(as.character(ethnic$answer), c("1" = "Aboriginal", "2" = "Aboriginal/Asian/Caucasian", "3" = "Aboriginal/Caucasian", "4" = "Asian", "5" = "Asian/Caucasian", "6" = "Black", "7" = "Caucasian", "8" = "Caucasian/Middle Eastern", "9" = "Latin American", "10" = "Middle Eastern", "11" = "Don't know/prefer no answer", "12" = "NA"))

ethnic$plot <- factor(ethnic$answer, ethnic$answer)

ethnic.plot <- ggplot(plot, aes(x = answer, y = Freq, fill = plot)) + theme(axis.text.x  = element_text(angle=90, vjust=.6)) #order responses as in t5

ethnic.plot + geom_bar(aes(x = plot), data = ethnic, stat = "identity", colour="black") +
      guides(fill = FALSE) +
      scale_fill_brewer(palette = "Set3") +
      ylab("Percent of total") +
      xlab("Response")

ethnic.tb <- as.factor(d$Q61_group_id)
ethnic.tb <- summary(ethnic.tb)
ethnic.tb <- as.data.frame(ethnic.tb)
ethnic.tb$Var1 <- substring(row.names(ethnic.tb), 1)


nval.df <- c("0", "0", "0", "23") #insert missing values 
nval.df <- as.data.frame(nval.df)
nval.df$ethnic.tb <- as.factor(nval.df$nval.df)
nval.df$Var1 <- c("[1]", "[3]","[6]", "[99]")
nval.df <- nval.df[-c(1)]

ethnic.tb <- rbind(ethnic.tb, nval.df)

ethnic.tb$answer <- revalue(as.character(ethnic.tb$Var1), c("[1]" = "Aboriginal", "[1, 2, 4]" = "Aboriginal/Asian/Caucasian", "[1, 4]" = "Aboriginal/Caucasian", "[2]" = "Asian", "[2, 4]" = "Asian/Caucasian", "[3]" = "Black", "[4]" = "Caucasian", "[4, 6]" = "Caucasian/Middle Eastern", "[5]" = "Latin American", "[6]" = "Middle Eastern", "[77]" = "Don't know/prefer no answer", "[99]" = "NA"))
plot.ethnic <- merge(ethnic, ethnic.tb, by = "answer")
plot.ethnic <- plot.ethnic[-c(2, 4, 6)]
plot.ethnic <- setcolorder(plot.ethnic, c("answer", "ethnic.tb", "Freq"))
plot.ethnic$order <- c(1, 2, 3, 4, 5, 6, 7, 8, 11, 9, 10, 12)
plot.ethnic <- plot.ethnic %>% arrange(order)
plot.ethnic <- plot.ethnic[-c(4)]
colnames(plot.ethnic) <- c("Response", "N", "Proportion")

kable(plot.ethnic)
Response N Proportion
Aboriginal 0 0.0000000
Aboriginal/Asian/Caucasian 1 0.3496503
Aboriginal/Caucasian 3 1.0489510
Asian 15 5.2447552
Asian/Caucasian 2 0.6993007
Black 0 0.0000000
Caucasian 228 79.7202797
Caucasian/Middle Eastern 1 0.3496503
Latin American 4 1.3986014
Middle Eastern 0 0.0000000
Don’t know/prefer no answer 9 3.1468531
NA 23 8.0419580

Q62: Which category best describes your annual household income, taking into account all sources of income?

income <- prop.table(table(factor(d$Q62_income, levels = c("1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "77")), exclude = NULL))*100
income <- as.data.frame(income)
income$answer <- substring(row.names(income), 1)
income$answer <- revalue(as.character(income$answer), c("1" = "No income", "2" = "$1 to $9,999", "3" = "$10,000 to $14,999", "4" = "$15,000 to $19,999", "5" = "$20,000 to $29,999", "6" = "$30,000 to $39,999", "7" = "$40,000 to $49,999", "8" = "$50,000 to $99,999", "9" = "$100,000 to $149,999", "10" = " $150,000 to $199,999", "11" = "$200,000 or more", "12" = "Don't know/prefer no answer", "13" = "NA"))

income$plot <- factor(income$answer, income$answer)

income.plot <- ggplot(plot, aes(x = answer, y = Freq, fill = plot)) + theme(axis.text.x  = element_text(angle=90, vjust=.6)) +
      guides(fill = FALSE) +
      scale_fill_brewer(palette = (rev("YlGn")))  +
      ylab("Percent of total") +
      xlab("")
      
income.plot + geom_bar(aes(x = plot), data = income, stat = "identity", colour="black") 

income.tb <- as.factor(d$Q62_income)
income.tb <- summary(income.tb)
income.tb <- as.data.frame(income.tb)
income.tb$Var1 <- substring(row.names(income.tb), 1)

nval.df <- c("0") #insert missing values 
nval.df <- as.data.frame(nval.df)
nval.df$income.tb <- as.factor(nval.df$nval.df)
nval.df$Var1 <- c("1")
nval.df <- nval.df[-c(1)]

income.tb <- rbind(income.tb, nval.df)

income.tb$answer <- revalue(as.character(income.tb$Var1), c("1" = "No income", "2" = "$1 to $9,999", "3" = "$10,000 to $14,999", "4" = "$15,000 to $19,999", "5" = "$20,000 to $29,999", "6" = "$30,000 to $39,999", "7" = "$40,000 to $49,999", "8" = "$50,000 to $99,999", "9" = "$100,000 to $149,999", "10" = " $150,000 to $199,999", "11" = "$200,000 or more", "77" = "Don't know/prefer no answer", "NA's" = "NA"))

plot.income <- merge(income, income.tb, by = "answer")
plot.income <- plot.income[-c(2, 4, 6)]
plot.income <- setcolorder(plot.income, c("answer", "income.tb", "Freq"))
plot.income$order <- c(10, 2, 3, 9, 4, 5, 11, 6, 7, 8, 12, 13, 1)
plot.income <- plot.income %>% arrange(order)
plot.income <- plot.income[-c(4)]
colnames(plot.income) <- c("Response", "N", "Proportion")

kable(plot.income)
Response N Proportion
No income 0 0.0000000
$1 to $9,999 3 1.0489510
$10,000 to $14,999 2 0.6993007
$15,000 to $19,999 5 1.7482517
$20,000 to $29,999 9 3.1468531
$30,000 to $39,999 11 3.8461538
$40,000 to $49,999 15 5.2447552
$50,000 to $99,999 99 34.6153846
$100,000 to $149,999 61 21.3286713
$150,000 to $199,999 31 10.8391608
$200,000 or more 9 3.1468531
Don’t know/prefer no answer 18 6.2937063
NA 23 8.0419580

Q63: To what extent does this annual household income allow you to satisfy your household’s needs?

needs <- prop.table(table(factor(d$Q63_income_needs, levels = c("1", "2", "3", "4", "77")), exclude = NULL))*100
needs <- as.data.frame(needs)
needs$answer <- substring(row.names(needs), 1)
needs$answer <- revalue(as.character(needs$answer), c("1" = "Very well", "2" = "Well", "3" = "Not so well", "4" = "Not at all", "5" = "Don't know/prefer no answer", "6" = "NA"))

needs$plot <- factor(needs$answer, needs$answer)

needs.plot <- ggplot(plot, aes(x = answer, y = Freq, fill = plot)) + theme(axis.text.x  = element_text(angle=90, vjust=.6)) +
      guides(fill = FALSE) +
      scale_fill_brewer(palette = "YlGn", direction=-1) +
      ylab("Percent of total") +
      xlab("")
      
needs.plot + geom_bar(aes(x = plot), data = needs, stat = "identity", colour="black") 

needs.tb <- as.factor(d$Q63_income_needs)
needs.tb <- summary(needs.tb)
needs.tb <- as.data.frame(needs.tb)
needs.tb$Var1 <- substring(row.names(needs.tb), 1)


needs.tb$answer <- revalue(as.character(needs.tb$Var1), c("1" = "Very well", "2" = "Well", "3" = "Not so well", "4" = "Not at all", "77" = "Don't know/prefer no answer", "NA's" = "NA"))

plot.needs <- merge(needs, needs.tb, by = "answer")
plot.needs <- plot.needs[-c(2, 4, 6)]
plot.needs <- setcolorder(plot.needs, c("answer", "needs.tb", "Freq"))
plot.needs$order <- c(5, 6, 4, 3, 1, 2)
plot.needs <- plot.needs %>% arrange(order)
plot.needs <- plot.needs[-c(4)]
colnames(plot.needs) <- c("Response", "N", "Proportion")

kable(plot.needs)
Response N Proportion
Very well 104 36.363636
Well 113 39.510489
Not so well 29 10.139860
Not at all 5 1.748252
Don’t know/prefer no answer 11 3.846154
NA 24 8.391608