# 資料探索和視覺化呈現

Jul 15, 2018 · 8 min read

# 一、脫貧方案是否有助於低收入戶脫離貧窮？

“入獄服刑、因案羈押或依法拘禁” “其他” “已通知未補件” “應徵(召)入營服役(含替代役)” “最近一年居住國內未達183日” “未實際居住本市” “未補附審查所需資料” “未設籍本市” “死亡” “系統補建異動” “自願放棄資格” “遷出戶內”

# 統計檢定

1. 比較實驗組和對照組在106年的平均收入，並用t-test檢定其統計學差異
`t.test(salary~group, dataset)`

2. 計算實驗組和對照組截至106年的脫貧率並卡方檢定是否有統計學差異

`prop.test(c(54,1463),c(64,1921))`

# 二、家庭特徵與脫貧的關係？

1. 如何用 `ggplot2` 畫出含有error bar的圖：
`library(readr)library(dplyr)library(ggplot2)poverty <- read_csv("~/Downloads/家庭特徵總表_已合併.csv")group<-poverty\$組別values<-poverty\$脫貧dat <- data_frame(group, values) %>%count(group, values) %>%group_by(group) %>%mutate(percent = n / sum(n),error = sqrt((percent * (1-percent))/sum(n))) %>%mutate(values = factor(values, levels = c("Y", "N"),labels=c("脫貧","未脫貧")))ggplot(dat, aes(values, percent, colour = group)) + geom_point(aes(size=0.6),show.legend = F)+geom_errorbar(aes(ymin = percent - 1.96*error, ymax = percent + 1.96*error))+geom_text(aes(label=paste(round(100*percent, 2), "%", sep="")), position = position_dodge(width = 2.7))+scale_colour_manual(values=c("darkturquoise", "firebrick1"))+theme(text = element_text(family = "MicrosoftYaHeiMono"))`

2. 用Mac如何解決 `ggplot2` 中出現中文亂碼？

` theme(text = element_text(family = “MicrosoftYaHeiMono”))`

Written by

Written by