Skip to content

Instantly share code, notes, and snippets.

@abikoushi
Created May 30, 2022 11:30
Show Gist options
  • Save abikoushi/0127565b4978842779bceb8e3bcaada8 to your computer and use it in GitHub Desktop.
Save abikoushi/0127565b4978842779bceb8e3bcaada8 to your computer and use it in GitHub Desktop.
choropleth map of Japan
nuriwake_chizu <-function(d,pal.name="Oranges"){
n.FD <-nclass.FD(d)
n.bins <-min(n.FD,9)
colclass=cut(d,seq(min(d),max(d),length.out = n.bins+1),include.lowest = TRUE,dig.lab = 2)
col_ <-RColorBrewer::brewer.pal(n.bins,name=pal.name)
col_tab <-data.frame(class=factor(levels(colclass)),col=col_,stringsAsFactors = FALSE)
outcol <-merge(data.frame(id=1:47,class=colclass),col_tab,by="class")
outcol <- outcol[order(outcol$id),]
old_par =par(no.readonly = TRUE)
par(mai=c(0,0,0,0))
p = NipponMap::JapanPrefMap(col=outcol$col)
legend("bottomright",legend=col_tab$class,fill=col_tab$col,bty = "n")
par(old_par)
invisible(p)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment