class: center, middle, inverse, title-slide # .hi-grey[原住民族資料分析線上訓練工作坊:R的基礎與應用] ## .smallest.hi-slate[第四週] ### .hi-slate[Kacing 廖彥傑] ### .smallest[英國艾賽克斯大學博士候選人] --- exclude: true --- layout: true # ggplot 案例一 --- name: ```r library(tidyverse) taitung_county <- read_csv("data/taitung_county.csv", show_col_types = FALSE) member <- taitung_county %>% rename(menber = 議員, money = `建議金額(單位:千元)`, year = 年, district = `選區(95-100年)`) %>% group_by(menber) %>% mutate(sum_money = sum(money)) %>% dplyr::select(menber, sum_money) %>% dplyr::distinct(menber, .keep_all = TRUE) ``` --- ```r member %>% ggplot(aes(x= reorder(menber, sum_money), y=sum_money)) + geom_bar(stat = "identity") + theme(text = element_text(family = "STHeiti")) + theme(axis.text.x = element_text(angle = 90, vjust = 0.5, hjust=1)) + coord_flip() + xlab("議員") + ylab("金額") ``` <img src="Week-04_files/figure-html/unnamed-chunk-3-1.svg" style="display: block; margin: auto;" /> --- layout: true # ggplot 案例二 --- name: ```r ethnicity <- taitung_county %>% rename(menber = 議員, money = `建議金額(單位:千元)`, year = 年, district = `選區(95-100年)`, ethnicity = 族群別) %>% group_by(ethnicity) %>% mutate(sum_money = sum(money)) %>% dplyr::select(ethnicity, sum_money) %>% dplyr::distinct(ethnicity, .keep_all = TRUE) ``` --- ```r options(scipen = 999) ethnicity %>% ggplot(aes(x= reorder(ethnicity, sum_money), y=sum_money)) + geom_bar(stat = "identity") + theme(text = element_text(family = "STHeiti")) + theme(axis.text.x = element_text(angle = 60, vjust = 0.5, hjust=1)) + #coord_flip() + xlab("族群") + ylab("金額") ``` <img src="Week-04_files/figure-html/unnamed-chunk-5-1.svg" style="display: block; margin: auto;" /> --- layout: true # ggplot 案例三 --- ```r taitung_county %>% rename(menber = 議員, money = `建議金額(單位:千元)`, year = 年, district = `選區(95-100年)`, ethnicity = 族群別, electoral = `勝選幅度DQ`) %>% ggplot(aes(x = money, y=electoral)) + geom_point() + #geom_point(aes(color=ethnicity)) + geom_point(aes(size=factor(ethnicity))) + theme(text = element_text(family = "STHeiti")) ``` <img src="Week-04_files/figure-html/unnamed-chunk-6-1.svg" style="display: block; margin: auto;" /> --- ```r taitung_county %>% rename(menber = 議員, money = `建議金額(單位:千元)`, year = 年, district = `選區(95-100年)`, ethnicity = 族群別, electoral = `勝選幅度DQ`) %>% ggplot(aes(x = money, y=electoral)) + geom_point() + geom_point(aes(color=ethnicity)) + theme(text = element_text(family = "STHeiti")) ``` <img src="Week-04_files/figure-html/unnamed-chunk-7-1.svg" style="display: block; margin: auto;" /> --- ```r taitung_county %>% rename(menber = 議員, money = `建議金額(單位:千元)`, year = 年, district = `選區(95-100年)`, ethnicity = 族群別, electoral = `勝選幅度DQ`) %>% ggplot(aes(x = money, y=electoral)) + geom_point() + theme(text = element_text(family = "STHeiti")) + geom_point(aes(shape=factor(ethnicity),color=factor(ethnicity)),size=4,alpha=0.6) ``` <img src="Week-04_files/figure-html/unnamed-chunk-8-1.svg" style="display: block; margin: auto;" /> --- ```r taitung_county %>% rename(menber = 議員, money = `建議金額(單位:千元)`, year = 年, district = `選區(95-100年)`, ethnicity = 族群別, electoral = `勝選幅度DQ`) %>% ggplot(aes(x = money, y=electoral)) + geom_point() + theme(text = element_text(family = "STHeiti")) + geom_point(aes(colour = year),size=4) + scale_colour_gradient(high='red',low = "blue") ``` <img src="Week-04_files/figure-html/unnamed-chunk-9-1.svg" style="display: block; margin: auto;" />