Population: 2013日本市町村の推移, r, widget

Last Updated on November 13, 2019 by shibatau

人口構成の推移を三種類のグラフで示しました。

 

I.作成の手順

 

1.日本語をローマ字に変換

RウィジェットのDataCamp Light WordPress Pluginは、日本語を表示できないので、地名を下記のサイトを利用してローマ字にしました。一部漢字が残っており、検索できない地名が数件あります。

ローマ字⇔ひらがな⇔漢字かな交じり文 変換

2.ライブラリreshape2を利用

Rウィジェットではtidyrを利用できないので、reshape2を利用して横長データを縦長にします。

3.データの取得

下記よりデータを取得しました。

『日本の地域別将来推計人口』(平成25年3月推計)

http://www.ipss.go.jp/pp-shicyoson/j/shicyoson13/2gaiyo_hyo/gaiyo.asp

 

II.利用方法

 

次のローマ字と漢字の対応リストより、表示したい地名のローマ字をコピーし、script.Rのしたのスクリプトの?にペーストし、Runをクリックします。

chooserregion….”?”

地域順(北から南)

アルファベット順

 

III.人口数の推移のグラフ

 

# population of regions roman in japan by age group # choose a region chooseregion.p <- "imabarishi" # call libraries library(ggplot2) library(ggthemes) library(reshape2) library(dplyr) # install data popdata14.p <- read.table("http://pastebin.com/raw/qVDg9Egf", sep=",", header=T, check.names=F) popdata15_64.p <- read.table("http://pastebin.com/raw/VUR32Uke", sep=",", header=T, check.names=F) popdata65.p <- read.table("http://pastebin.com/raw/yGzfUbeM", header=T, sep=",", check.names=F) # wide to long popdata14.p.long <- melt(popdata14.p, id.vars=c("id", "regionr"), variable.name="year", value.name="pop0_14") popdata14.p.long$year <- as.numeric(as.character(popdata14.p.long$year)) popdata15_64.p.long <- melt(popdata15_64.p, id.vars=c("id", "regionr"), variable.name="year", value.name="pop15_64") popdata15_64.p.long$year <- as.numeric(as.character(popdata15_64.p.long$year)) popdata65.p.long <- melt(popdata65.p, id.vars=c("id", "regionr"), variable.name="year", value.name="pop65") popdata65.p.long$year <- as.numeric(as.character(popdata65.p.long$year)) # get the data popdata14.p.long.region <- popdata14.p.long %>% dplyr::filter(regionr == chooseregion.p) popdata15_64.p.long.region <- popdata15_64.p.long %>% dplyr::filter(regionr == chooseregion.p) popdata65.p.long.region <- popdata65.p.long %>% dplyr::filter(regionr == chooseregion.p) # merge the age groups popdataall.p.long.region <- merge(popdata14.p.long.region, merge(popdata15_64.p.long.region, popdata65.p.long.region)) # print the data of the city popdataall.p.long.region # wide to long popdataall.p.long.region <- melt(popdataall.p.long.region, id.vars=c("id", "regionr", "year"), variable.name="group", value.name="population") # population in 2015 pop2015.group <- popdataall.p.long.region %>% dplyr::filter(year == "2015") pop2015 <- sum(pop2015.group$population) # print poplulation 2015 pop2015 ## [1] 712548 # plot p1 = ggplot(aes(y = population, x = year, fill = group), data = popdataall.p.long.region) + geom_area() + ggtitle(paste(chooseregion.p, "\n", pop2015, "(2015)")) + labs(x="year",y="population") p1

 

 

IV. 人口割合の推移

 

# population of regions in japan by age group (%) roman letters # choose a region chooseregion <- "imabarishi" # call libraries library(ggplot2) library(ggthemes) library(dplyr) library(reshape2) # install data data14.pro.r <- read.table("http://pastebin.com/raw/iuiPNYTr", sep=",", header=T, check.names=F, ) data15_64.pro.r <- read.table("http://pastebin.com/raw/h25xFzzF", header=T, sep=",", check.names=F) data65.pro.r <- read.table("http://pastebin.com/raw/YtzTv9uD", header=T, sep=",", check.names=F) # wide to long data14.pro.r.long <- melt(data14.pro.r, id.vars=c("id", "regionr"), variable.name="year", value.name="pro0_14") data14.pro.r.long$year <- as.numeric(as.character(data14.pro.r.long$year)) data15_64.pro.r.long <- melt(data15_64.pro.r, id.vars=c("id", "regionr"), variable.name="year", value.name="pro15_64") data15_64.pro.r.long$year <- as.numeric(as.character(data15_64.pro.r.long$year)) data65.pro.r.long <- melt(data65.pro.r, id.vars=c("id", "regionr"), variable.name="year", value.name="pro65") data65.pro.r.long$year <- as.numeric(as.character(data65.pro.r.long$year)) # get the data data14.pro.r.long.region <- data14.pro.r.long %>% dplyr::filter(regionr == chooseregion) data15_64.pro.r.long.region <- data15_64.pro.r.long %>% dplyr::filter(regionr == chooseregion) data65.pro.r.long.region <- data65.pro.r.long %>% dplyr::filter(regionr == chooseregion) # merge the age groups dataall.pro.r.long.region <- merge(data14.pro.r.long.region, merge(data15_64.pro.r.long.region, data65.pro.r.long.region)) # print the data of the city dataall.pro.r.long.region # wide to long dataall.pro.r.long.region.long <- melt(dataall.pro.r.long.region, id.vars=c("id", "regionr", "year"), variable.name="group", value.name="population.pr") # plot p1 = ggplot(aes(y = population.pr, x = year, fill = group), data = dataall.pro.r.long.region.long) + geom_area()+ ggtitle(chooseregion) + labs(x="Year", y="percentage") + theme(plot.title = element_text(family = "Trebuchet MS", color="#666666", face="bold", size=16, hjust=0)) + theme(axis.title = element_text(family = "Trebuchet MS", color="#666666", face="bold", size=14)) p1

 

 

 
V.2010年を100とした推移

 

# population index of cities and villages in japan # choose a region chooseregion.index <- "imabarishi" # population index library(ggplot2) library(ggthemes) library(reshape2) library(dplyr) # install data data14.index.r <- read.table("http://pastebin.com/raw/CyKyqZnD", sep=",", header=T, check.names=F) data15_64.index.r <- read.table("http://pastebin.com/raw/TnbiDdg7", header=T, sep=",", check.names=F) data65.index.r <- read.table("http://pastebin.com/raw/zvT2KF6R", header=T, sep=",", check.names=F) # wide to long data14.index.r.long <- melt(data14.index.r, id.vars=c("id", "regionr"), variable.name="year", value.name="index0_14") data14.index.r.long$year <- as.numeric(as.character(data14.index.r.long$year)) data15_64.index.r.long <- melt(data15_64.index.r, id.vars=c("id", "regionr"), variable.name="year", value.name="index15_64") data15_64.index.r.long$year <- as.numeric(as.character(data15_64.index.r.long$year)) data65.index.r.long <- melt(data65.index.r, id.vars=c("id", "regionr"), variable.name="year", value.name="index65") data65.index.r.long$year <- as.numeric(as.character(data65.index.r.long$year)) # get the data data14.index.r.long.region <- data14.index.r.long %>% dplyr::filter(regionr == chooseregion.index) data15_64.index.r.long.region <- data15_64.index.r.long %>% dplyr::filter(regionr == chooseregion.index) data65.index.r.long.region <- data65.index.r.long %>% dplyr::filter(regionr == chooseregion.index) # merge the age groups dataall.index.r.long.region <- merge(data14.index.r.long.region, merge(data15_64.index.r.long.region, data65.index.r.long.region)) # print the data of the city dataall.index.r.long.region # wide to long dataall.index.r.long.region.long <- melt(dataall.index.r.long.region, id.vars=c("id", "regionr", "year"), variable.name="group", value.name="index") # plot p1 = ggplot(aes(y = index, x = year, fill = group), data = dataall.index.r.long.region.long) + geom_area() + ggtitle(paste(chooseregion.index)) + labs(x="year", y="index") + theme(plot.title = element_text(family = "Trebuchet MS", color="#666666", face="bold", size=16, hjust=0)) + theme(axis.title = element_text(family = "Trebuchet MS", color="#666666", face="bold", size=14)) p1

 

About shibatau

I was born and grown up in Kyoto. I studied western philosophy at the University and specialized in analytic philosophy, especially Ludwig Wittgenstein at the postgraduate school. I'm interested in new technology, especially machine learning and have been learning R language for two years and began to learn Python last summer. Listening toParamore, Sia, Amazarashi and MIyuki Nakajima. Favorite movies I've recently seen: "FREEHELD". Favorite actors and actresses: Anthony Hopkins, Denzel Washington, Ellen Page, Meryl Streep, Mia Wasikowska and Robert DeNiro. Favorite books: Fyodor Mikhailovich Dostoyevsky, "The Karamazov Brothers", Shinran, "Lamentations of Divergences". Favorite phrase: Salvation by Faith. Twitter: @shibatau

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.