Skip to content

Instantly share code, notes, and snippets.

@kzktmr
kzktmr / 都道府県人口重心間距離行列.csv
Created August 29, 2025 03:53
都道府県人口重心間の距離行列。総務省統計局による都道府県人口重心(2020年)を元に、geosphere::distm関数で作成。
We can make this file beautiful and searchable if this error is corrected: It looks like row 2 should actually have 48 columns, instead of 46 in line 1.
"","北海道","青森県","岩手県","宮城県","秋田県","山形県","福島県","茨城県","栃木県","群馬県","埼玉県","千葉県","東京都","神奈川県","新潟県","富山県","石川県","福井県","山梨県","長野県","岐阜県","静岡県","愛知県","三重県","滋賀県","京都府","大阪府","兵庫県","奈良県","和歌山県","鳥取県","島根県","岡山県","広島県","山口県","徳島県","香川県","愛媛県","高知県","福岡県","佐賀県","長崎県","熊本県","大分県","宮崎県","鹿児島県","沖縄県"
"北海道",0,274.52635415008,399.421639381435,532.250303172182,397.736174266105,537.563054055637,640.684176575578,774.640288750855,747.536556219899,781.742010395394,818.213608474724,835.8400069535,842.539812475553,870.273877218146,654.627945041313,812.508474382985,844.695637214607,929.299815450719,873.15586169035,822.09621609504,947.399440043588,955.894923570874,981.555724095125,1033.13633473301,1016.30481088196,1042.75470686966,1082.92718132648,1092.14187718296,1079.99654867931,1147.7352568103,1095.7034266077,1170.48903344644,1161.63058576778,1245.10275081823,1345.13947408475,1190.95760479838,1193.4453382017,1293.43521596342,1294.18728553588,1440.81724813854,1489.36504905926,1538.87562231126,1508.4090315449,1414.43734292406,1535.8
@kzktmr
kzktmr / 都道府県庁間距離行列.csv
Created August 29, 2025 03:46
都道府県庁間の距離行列。国土数値情報「国・都道府県の機関データ」(令和4年度版)を元に、geosphere::distm関数で作成。
We can make this file beautiful and searchable if this error is corrected: It looks like row 2 should actually have 48 columns, instead of 46 in line 1.
"","北海道","青森県","岩手県","宮城県","秋田県","山形県","福島県","茨城県","栃木県","群馬県","埼玉県","千葉県","東京都","神奈川県","新潟県","富山県","石川県","福井県","山梨県","長野県","岐阜県","静岡県","愛知県","三重県","滋賀県","京都府","大阪府","兵庫県","奈良県","和歌山県","鳥取県","島根県","岡山県","広島県","山口県","徳島県","香川県","愛媛県","高知県","福岡県","佐賀県","長崎県","熊本県","大分県","宮崎県","鹿児島県","沖縄県"
"北海道",0,253.772215941208,373.607418009515,534.043685142136,385.894584824179,542.131459662591,594.79946018661,750.363208608895,732.307582494583,766.303905286783,813.303525857318,834.863062667206,831.08688417318,858.271395374067,606.115987332648,790.459183323064,823.891612103627,892.780314941579,855.573811808054,761.691459166574,940.317881621448,933.620284827482,955.417260770338,1015.45286703627,1012.1252358246,1014.93080898557,1058.00031304258,1071.67139880033,1045.43823419233,1118.24318749654,1038.7279854049,1104.71656478121,1132.11923765586,1232.5815947729,1306.15919086029,1159.9685885658,1157.18563511982,1266.9932014461,1255.80137697439,1417.06487704266,1454.87716647531,1523.35205630627,1470.52928977667,1382.69818623136,1514
@kzktmr
kzktmr / ggJapanPrefMap.R
Created August 25, 2024 15:49
Draw a very simple prefectural choropleth map of Japan with ggplot
ggJapanPrefMap <- function (col = NULL, inset = TRUE, ...)
{
require(sf)
require(ggplot2)
if(is.null(col)){
col <- rep(NULL, 47)
}else{
if (!is.factor(col)) col <- as.factor(col)
}
shp <- system.file("shapes/jpn.shp", package = "NipponMap")[1]
@kzktmr
kzktmr / Starbucks_saga.csv
Last active June 8, 2025 13:20
佐賀県内のスターバックス店舗
shop address
佐賀南バイパス店 佐賀県佐賀市本庄町袋306-6
佐賀大学通り店 佐賀県佐賀市与賀町70-1
鳥栖プレミアム・アウトレット店 佐賀県鳥栖市弥生が丘8-1
TSUTAYA鳥栖店 佐賀県鳥栖市本鳥栖町537-1
鳥栖蔵上町店 佐賀県鳥栖市蔵上町662-5
基山パーキングエリア(上り線)店 佐賀県三養基郡基山町小倉2097-1
蔦屋書店武雄市図書館店 佐賀県武雄市武雄町武雄5304-1
佐賀武雄店 佐賀県武雄市武雄町昭和277
唐津店 佐賀県唐津市和多田西山1-46-1
@kzktmr
kzktmr / ggradar.R
Created April 4, 2019 05:13
Draw a radar chart with ggplot.
library(tidyverse)
# http://www.cmap.polytechnique.fr/~lepennec/R/Radar/RadarAndParallelPlots.html
coord_radar <- function (theta = "x", start = 0, direction = 1){
theta <- match.arg(theta, c("x", "y"))
r <- if (theta == "x")
"y"
else "x"
ggproto("CordRadar", CoordPolar, theta = theta, r = r, start = start,
direction = sign(direction),
@kzktmr
kzktmr / 税関符号.csv
Last active May 25, 2018 01:50
税関符号表:外国貿易等に関する統計基本通達( http://www.customs.go.jp/toukei/sankou/dgorder/TU-S59k1048.pdf )別表第2
符号 事務所名
1000 東京税関(本関)
1001 東京税関東京外郵出張所
1005 東京税関立川出張所
1006 東京税関前橋出張所
1007 東京税関大井出張所
1012 東京税関東京航空貨物出張所
1030 東京税関羽田税関支署
1040 東京税関成田航空貨物出張所
1041 成田税関支署
@kzktmr
kzktmr / veterinary_migration.csv
Last active June 24, 2017 15:17
獣医系大学の入学率と就職率との関係について(http://www.kantei.go.jp/jp/singi/tiiki/kokusentoc_wg/hearing_s/140819siryou05_1.pdf
地域性 大学名 自県内入学率 自地域内入学率 自県内就職率 自地域内就職率 出身県への就職率 出身地域への就職率
地方型 帯広 15.2 23.2 29.1 32.6 22.7 34.8
地方型 岩手 13.9 36.1 6 15 26.1 35.2
地方型 鳥取 6.8 30.6 6.7 26.7 29.3 40.7
地方型 山口 9.9 27.3 13.5 20.6 23.8 41.3
地方型 宮崎 13.4 42.5 18.9 41.5 25.5 49.1
地方型 鹿児島 16.7 44.7 25.8 49.2 28.8 52.3
地方型 酪農 21.9 26.5 23.6 26.9 32.2 32.2
地方型 北里 0.5 6.9 3.5 9.2 39.2 61.8
都市型 北海道 7.3 11.3 23.3 25.8 12.9 26.5
@kzktmr
kzktmr / write_excel_mac_csv.R
Created December 27, 2016 14:45
Export csv file that can be opened by Excel for Mac.
write_excel_mac_csv <- function(x, path, na = "NA"){
tmp <- tempfile()
readr::write_tsv(x, tmp, na = na)
path <- paste0("'", path, "'")
system(paste("(printf '\xff\xfe'; iconv -f utf-8 -t utf-16le", tmp, ") >", path))
}
@kzktmr
kzktmr / ggJapanPrefecturesMap.R
Last active December 4, 2016 14:52
Draw a very simple prefectural choropleth map of Japan with ggplot
ggJapanPrefecturesMap <- function (col = "white", fill = NULL, inset = TRUE, silent = FALSE, ...)
{
require(Nippon)
if(require(ggplot2)){
require(foreign)
m <- readShapePoly(system.file("shapes/jpn.shp", package = "Nippon")[1],
proj4string = CRS("+proj=longlat +datum=WGS84"))
if (inset) {
xy.okinawa <- m@polygons[[47]]@Polygons[[1]]@coords
xy.okinawa[, 1] <- xy.okinawa[, 1] + 7
@kzktmr
kzktmr / googleChartJapanMap.R
Last active December 11, 2015 14:30
Draw choropleth map of Japan using (deprecated) Google Chart API from R
# This function uses an old API. It is not recommended to use this function.
googleChartJapanMap <- function(x, width=500, height=600, col.def="gray", col.min="lightgreen", col.max="darkgreen", col.bg="white", file=NULL, title=NULL){
#2010/12/28 ver.0.1 by kzktmr
#2015/12/11 ver.0.2 by kzktmr
stopifnot(length(x)==47, width*height<=300000)
col2hex <- function(col){
col.rgb <- col2rgb(col)
return(substring(rgb(col.rgb[1], col.rgb[2], col.rgb[3], maxColorValue=255), 2))
}
xx <- x[!is.na(x)]