Rで解析:方位記号とスケールバーの描写に便利です。「prettymapr」パッケージ

Rの解析に役に立つ記事
スポンサーリンク

方位記号やスケールバーをplotコマンドで出力した図へ追記できるパッケージの紹介です。rasterパッケージとの組み合わせも面白いかもしれません。

方位記号とスケールバーを描写する「addnortharrow」と「addscalebar」、地名から緯度経度を取得する「searchbbox」コマンドを紹介します。

パッケージバージョンは0.2.3。windows 11のR version 4.1.3で確認しています。

スポンサーリンク

パッケージのインストール

下記、コマンドを実行してください。

#パッケージのインストール
install.packages("prettymapr")

実行コマンド

詳細はコメント、パッケージのヘルプを確認してください。

#パッケージの読み込み
library("prettymapr")

###方位記号の描写:addnortharrowコマンド#####
#描写の準備
plot(0:1, 0:1, type = "n", axes = FALSE, xlab = "", ylab = "")
box()
#描写位置の指定
Position <- c("bottomleft", "bottomright", "topleft", "topright")
#&#33394;&#12398;&#25351;&#23450;
Cols <- c("#e1e6ea", "#505457", "#4b61ba", "#a87963")
#&#30690;&#21360;&#12398;&#25551;&#20889;
for(n in 1:4){
  addnortharrow(pos = Position[n], padin = c(0.15, 0.15), scale = n,
                lwd = 1, border = "black", cols = c("white", Cols[n]),
                text.col = "black")
}
########

###&#12473;&#12465;&#12540;&#12523;&#12496;&#12540;&#12398;&#25551;&#20889;:addscalebar&#12467;&#12510;&#12531;&#12489;#####
#&#25551;&#20889;&#12398;&#28310;&#20633;
plot(0:1, 0:1, type = "n", axes = FALSE, xlab = "", ylab = "")
box()
#&#25551;&#20889;&#20301;&#32622;&#12398;&#25351;&#23450;
Position <- c("bottomleft", "bottomright", "topleft", "topright")
#&#33394;&#12398;&#25351;&#23450;
Cols <- c("#e1e6ea", "#505457", "#4b61ba", "#a87963")
#&#12473;&#12479;&#12452;&#12523;&#12398;&#25351;&#23450;
Styles <- c("bar","ticks", "bar","ticks")
#&#32239;&#24230;&#32076;&#24230;&#12471;&#12473;&#12486;&#12512;&#12398;&#35373;&#23450;
#lat/lon,Spherical Mercator otherwise&#12398;&#38918;
LatLon <- c(4326, 3857, 4326, 3857)
#&#30690;&#21360;&#12398;&#25551;&#20889;
for(n in 1:4){
  addscalebar(plotunit = "cm", plotepsg = LatLon[n], widthhint = 0.25,
              unitcategory = "metric", htin = n, padin = c(0.15, 0.15),
              style = "bar", bar.cols = c(Cols[n], "white"), lwd = 1,
              linecol = "black", tick.cex = 0.7, labelpadin = 0.08, label.cex = 0.8,
              label.col = "black", pos = Position[n])
}
########

#&#32239;&#24230;&#32076;&#24230;&#12398;&#21462;&#24471;:searchbbox&#12467;&#12510;&#12531;&#12489;
#PickPoint.io API&#12434;&#21033;&#29992;
GetArea <- searchbbox("KYOTO")
#&#30906;&#35469;
GetArea
#        min       max
#x 135.55901 135.87844
#y  34.87492  35.32122

出力例

・addnortharrowコマンド

addnortharrow

・addscalebarコマンド

addscalebar

少しでも、あなたの解析が楽になりますように!!

タイトルとURLをコピーしました