日本地図

[2021年10月追記] 最新のデータを追加。

[2019年11月追記] NipponパッケージがCRANから消されてしまったのでNipponMapだけで描くように手直しした。

[2017年12月追記] 谷村先生ご自身によるNipponパッケージの紹介スライドが 2017年度 統計数理研究所共同研究集会「データ解析環境Rの整備と利用」 ページからダウンロードできる。また,Nipponパッケージの日本地図機能だけを含む NipponMap パッケージもリリースされた。

高校「情報」教員採用試験状況

2015年6月に三重大学医学部看護学科教授になられた 谷村 晋 先生によるパッケージ Nippon および NipponMap を使って日本地図を描いてみる。

データは,工学院大学附属中学校・高等学校校長の 中野 由章 先生が毎年調べられている高校「情報」教員採用試験状況である。

まずNipponMapパッケージのインストール:

install.packages("sf")
install.packages("NipponMap")

2022年度採用の高校「情報」教員採用試験で,副免許不要の都道府県は青,副免許必要の都道府県は黄を塗る。

library(NipponMap)
kenmei = c("北海道", "青森", "岩手", "宮城", "秋田", "山形", "福島", "茨城",
           "栃木", "群馬", "埼玉", "千葉", "東京", "神奈川", "新潟", "富山",
           "石川", "福井", "山梨", "長野", "岐阜", "静岡", "愛知", "三重",
           "滋賀", "京都", "大阪", "兵庫", "奈良", "和歌山", "鳥取", "島根",
           "岡山", "広島", "山口", "徳島", "香川", "愛媛", "高知", "福岡",
           "佐賀", "長崎", "熊本", "大分", "宮崎", "鹿児島", "沖縄")
cols = rep("white", 47)
names(cols) = kenmei
cols[c("青森","岩手","秋田","山形","福島","栃木","群馬","千葉","東京","神奈川","山梨",
       "新潟","富山","石川","福井","長野","静岡","愛知","岐阜","京都","大阪","和歌山",
       "鳥取","岡山","広島","徳島","香川","高知","福岡","佐賀","長崎","熊本","大分",
       "宮崎","沖縄")] = "blue"
cols[c("北海道","宮城","茨城","埼玉","滋賀","兵庫","島根","愛媛","山口","鹿児島")] = "yellow"
par(mar=c(0,0,0,0))
JapanPrefMap(col=cols)
legend(143, 33, c("副免許不要","副免許必要"), fill=c("blue","yellow"))
2022年度高校「情報」教員採用試験状況

白いところ(「採用なし」)はずいぶん減った。

アニメーション化

year = 2001:2022
cols = matrix(rep("white", 47*22), nrow=47)
rownames(cols) = kenmei

cols[c("青森","岩手","秋田","山形","福島","栃木","群馬","千葉","東京","神奈川","山梨",
       "新潟","富山","石川","福井","長野","静岡","愛知","岐阜","京都","大阪","和歌山",
       "鳥取","岡山","広島","徳島","香川","高知","福岡","佐賀","長崎","熊本","大分",
       "宮崎","沖縄"), 22] = "blue"
cols[c("北海道","宮城","茨城","埼玉","滋賀","兵庫","島根","愛媛","山口","鹿児島"), 22] = "yellow"

cols[c("青森","岩手","山形","栃木","千葉","東京","神奈川","山梨","新潟","石川","福井",
       "静岡","愛知","岐阜","京都","大阪","鳥取","岡山","広島","徳島","高知","福岡",
       "熊本","大分","宮崎","沖縄"), 21] = "blue"
cols[c("北海道","宮城","茨城","埼玉","富山","長野","兵庫","島根","香川","愛媛","山口"), 21] = "yellow"

cols[c("青森","岩手","千葉","石川","福井","静岡","愛知","岐阜","京都","大阪","和歌山",
       "岡山","広島","徳島","高知","福岡","佐賀","熊本","大分","宮崎","沖縄"), 20] = "blue"
cols[c("北海道","宮城","茨城","埼玉","東京","神奈川","富山","長野","兵庫","山口"), 20] = "yellow"

cols[c("青森","山形","千葉","岐阜","三重","京都","大阪","岡山","広島","福岡","大分","沖縄"), 19] = "blue"
cols[c("宮城","茨城","埼玉","東京","神奈川","富山","長野","愛知","兵庫"), 19] = "yellow"

cols[c("青森","千葉","京都","大阪","広島","高知","大分","沖縄"), 18] = "blue"
cols[c("宮城","埼玉","東京","神奈川","富山","長野","愛知","兵庫","山口"), 18] = "yellow"

cols[c("大阪","岡山","広島","沖縄"), 17] = "blue"
cols[c("福島","埼玉","東京","神奈川","富山","長野","岐阜","愛知","兵庫","山口"), 17] = "yellow"

cols[c("三重","大阪","岡山","広島","沖縄"), 16] = "blue"
cols[c("福島","埼玉","千葉","東京","神奈川","富山","長野","愛知","兵庫","奈良","山口"), 16] = "yellow"

cols[c("山形","大阪","広島","熊本","沖縄"), 15] = "blue"
cols[c("福島","埼玉","千葉","東京","神奈川","富山","長野","愛知","兵庫","山口","香川"), 15] = "yellow"

cols[c("静岡","岐阜","三重","大阪","広島","大分","沖縄"), 14] = "blue"
cols[c("福島","埼玉","千葉","東京","神奈川","長野","富山","愛知","兵庫","山口"), 14] = "yellow"

cols[c("山形","静岡","岐阜","三重","大阪","広島","沖縄"), 13] = "blue"
cols[c("埼玉","千葉","東京","神奈川","富山","愛知","奈良","兵庫","山口","香川"), 13] = "yellow"

cols[c("山形","静岡","大阪","岡山","広島","大分","宮崎","沖縄"), 12] = "blue"
cols[c("埼玉","千葉","東京","神奈川","富山","愛知","兵庫"), 12] = "yellow"

cols[c("静岡","三重","大阪","岡山","広島","沖縄"), 11] = "blue"
cols[c("山形","埼玉","東京","神奈川","富山","山梨","愛知","兵庫","奈良"), 11] = "yellow"

cols[c("静岡","大阪","広島","熊本","沖縄"), 10] = "blue"
cols[c("山形","群馬","埼玉","神奈川","富山","愛知","兵庫","鳥取"), 10] = "yellow"

cols[c("静岡","大阪","広島","沖縄"), 9] = "blue"
cols[c("山形","茨城","群馬","埼玉","神奈川","富山","愛知","鳥取"), 9] = "yellow"

cols[c("神奈川","静岡","大阪","大分","沖縄"), 8] = "blue"
cols[c("茨城","群馬","埼玉","東京","富山","愛知","鳥取"), 8] = "yellow"

library(animation)
saveGIF({
    for (i in 8:22) {
        par(mar=c(0,0,2,0))
        JapanPrefMap(col=cols[,i])
        title(year[i])
        legend(141, 33, c("副免許不要","副免許必要"), fill=c("blue","yellow"))
    }
})
高校で「情報」教員が採用された都道府県

投影法の変更

JapanPrefMap() を少々改造し,投影法を UTM 54N に変えてみる。座標変換は sf パッケージの st_transform() を使う。

library(sf)

JapanPrefMap2 <-
function (col = NULL, inset = TRUE, ...) 
{
    if (is.null(col)) 
        col <- rep("transparent", 47)
    shp <- system.file("shapes/jpn.shp", package = "NipponMap")[1]
    m <- read_sf(shp)
    st_crs(m) <- "+proj=longlat +datum=WGS84"
    m = st_transform(m, "+proj=utm +zone=54 +datum=WGS84 +units=km")
    if (inset) {
        m$geometry[[47]] <- m$geometry[[47]] + c(800, 1550)
        ylim <- c(3450, 5050)
        xlim <- c(-550, 1100)
    }
    else {
        ylim <- NULL
        xlim <- NULL
    }
    plot(st_geometry(m), col = col, xlim = xlim, ylim = ylim, 
        ...)
    if (inset) {
        lines(x = c(-300, 0, 200, 200), y = c(4250, 4250, 4500, 4800))
    }
    m.c <- suppressWarnings(st_centroid(m))
    return(invisible(st_coordinates(m.c)))
}

これで描いてみる。座標は経度/緯度ではなくEasting/Northing (km)になることに注意する(axes=TRUE を付けるとわかりやすい)。

JapanPrefMap2(col=cols)
legend(600, 3700, c("副免許不要","副免許必要"), fill=c("blue","yellow"))
2022年度高校「情報」教員採用試験状況

UTM 54N以外に,Suitable projection for a map of Japan で次のような経線がまっすぐになるものも薦められている:

+proj=eqdc +lat_0=0 +lon_0=138 +lat_1=34 +lat_2=40 +x_0=0 +y_0=0 +ellps=WGS84 +units=m +no_defs

参考文献