[1] "Age10" "Age26" "Age5" "DemoQ" "DemoY107" "DemoY108"
[7] "dicRitw01" "Income"
DemoY108
- 村里季度資料
97 98 99 100 101 102 103 104 105 106 107 108
7822 7834 7835 7835 7835 7839 7851 7851 7851 7851 7760 7760
BIG6 = c("桃園市","臺北市","臺中市","臺南市","高雄市","新北市")
Y = DemoY108 %>% select(
year, vid=`村里代碼`, city=`縣市名稱`, county=`鄉鎮市區名稱`,
vname=`村里名稱`, house=`戶數`, pop=`人口數`, fm.ratio=`性比例`,
sp.ratio=`扶養比`, elderly=`老化指數`) %>%
filter(! city %in% c("連江縣","金門縣","澎湖縣")) %>%
mutate(city = case_when(
city == "臺北縣" ~ "新北市",
city == "桃園縣" ~ "桃園市",
city == "高雄縣" ~ "高雄市",
city == "臺南縣" ~ "臺南市",
city == "臺中縣" ~ "臺中市",
TRUE ~ city ))
Y %>% is.na %>% colSums
year vid city county vname house pop fm.ratio
0 0 0 0 0 0 0 0
sp.ratio elderly
0 0
Y %>% group_by(year, city) %>%
summarise(Pop = sum(pop)) %>%
ggplot(aes(x=year, y=Pop, col=factor(city)) ) +
geom_line(size=1) -> g; ggplotly(g)
df = Y %>% group_by(city, year) %>% summarise(
`性比例` = sum(fm.ratio*pop)/sum(pop),
`扶養比` = sum(sp.ratio*pop)/sum(pop),
`老化指數` = sum(elderly*pop)/sum(pop),
`人口` = sum(pop)
) %>% filter(year %in% seq(99,108,3))
scale1 = function(mp=0) scale_color_gradient2(
midpoint=mp, low="seagreen4", mid="wheat2", high="firebrick2")
df %>% #filter(city %in% BIG6) %>%
ggplot(aes(x=`扶養比`, y=`老化指數`, col=`性比例`, size=`人口`, label=year)) +
geom_point(alpha=1) + scale1(100) + theme_bw() +
facet_wrap(~city, ncol=4) -> g; ggplotly(g)
DemoQ
- 村里季度資料
100Y1S 100Y2S 100Y3S 100Y4S 101Y1S 101Y2S 101Y3S 101Y4S 102Y1S 102Y2S 102Y3S
7581 7500 7443 7460 7534 7471 7464 7450 7534 7451 7482
102Y4S 103Y1S 103Y2S 103Y3S 103Y4S 104Y1S 104Y2S 104Y3S 104Y4S 105Y1S 105Y2S
7519 7585 7535 7501 7500 7531 7531 7506 7535 7623 7542
105Y3S 105Y4S 106Y1S 106Y2S 106Y3S 106Y4S 107Y1S 107Y2S 107Y3S 107Y4S 108Y1S
7530 7502 7610 7514 7544 7549 7600 7461 7461 7442 7514
108Y2S 108Y3S 108Y4S 97Y1S 97Y2S 97Y3S 97Y4S 98Y1S 98Y2S 98Y3S 98Y4S
7464 7466 7502 7503 7411 7386 7435 7483 7406 7403 7441
99Y1S 99Y2S 99Y3S 99Y4S
7476 7436 7440 7458
Q = DemoQ %>% transmute(
year = str_remove(`資料時間`,"Y.*$") %>% as.integer,
qtr = str_remove(`資料時間`,"^\\d+Y"),
vid=`村里代碼`, city=`縣市名稱`, county=`鄉鎮市區名稱`, vname=`村里名稱`,
born=`出生數`, death=`死亡數`, marriage=`結婚對數`, devorce=`離婚對數`,
time=`資料時間`
) %>%
filter(! city %in% c("連江縣","金門縣","澎湖縣")) %>%
mutate(city = case_when(
city == "臺北縣" ~ "新北市",
city == "桃園縣" ~ "桃園市",
city == "高雄縣" ~ "高雄市",
city == "臺南縣" ~ "臺南市",
city == "臺中縣" ~ "臺中市",
TRUE ~ city )) %>%
mutate_at(vars(born:devorce), ~replace_na(as.integer(.), 0))
group_by(Q, qtr) %>%
summarise_at(vars(born:devorce), sum) %>%
gather("event", "n", -1) %>%
ggplot(aes(x=qtr, y=n)) + geom_bar(stat="identity") +
facet_wrap(~event, nrow=1)
group_by(Q, time) %>%
summarise_at(vars(born:devorce), sum) %>%
gather("event", "n", -1) %>%
ggplot(aes(x=time, y=n, group=event, col=event)) +
geom_line() -> g ; ggplotly(g)
Warning: Using `as.character()` on a quosure is deprecated as of rlang 0.3.0.
Please use `as_label()` or `as_name()` instead.
This warning is displayed once per session.