Rで解析:深度データのプロットが楽しい!「marmap」パッケージ

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

アメリカ海洋大気庁(National Oceanic and Atmospheric Administration:NOAA)から深度データを取得しプロットできるパッケージの紹介です。プロットの基本はbase::plotなのでプロットの装飾に使うコマンドは共通です。そのため、幅広い装飾が可能です。

CRANのパッケージページのVignettesに解析例が紹介されています。非常に参考になるので確認をおすすめします。

https://cran.r-project.org/web/packages/marmap/index.html

パッケージバージョンは1.0.9。R version 4.2.2で確認しています。

スポンサーリンク

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

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

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

実行コマンド

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

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

#NOAAサーバーから深度データを取得しbathy class作成:getNOAA.bathyコマンド
#座標範囲の指定:経度:lon1,lon2;緯度:lat1,lat2オプション;
#同じ座標範囲の場合は実行済みのデータを読み込みます
#解像度の設定:resolutionオプション;初期値:4
#作業フォルダに取得深度データをcsvで保存:keepオプション;TRUE/FALSE
#反太平洋子午線のデータを取得:antimeridianオプション;keep=TRUEが推奨;TRUE/FALSE
TestBathy <- getNOAA.bathy(lon1 = 138, lon2 = 148,
                           lat1 = 41, lat2 = 46, 
                           resolution = 4, keep = TRUE,
                           antimeridian = FALSE)

#bathy class&#12434;&#12503;&#12525;&#12483;&#12488;:plot.bathy&#12467;&#12510;&#12531;&#12489;
#&#12300;plot&#12301;&#12391;&#20351;&#29992;&#12364;&#21487;&#33021;
#bathy class&#12434;&#25351;&#23450;:x&#12458;&#12503;&#12471;&#12519;&#12531;
#&#28145;&#24230;&#12398;&#33394;&#12398;&#26377;&#28961;:image&#12458;&#12503;&#12471;&#12519;&#12531;;&#21021;&#26399;&#20516;:FALSE/TRUE
#image=TRUE&#12398;&#22580;&#21512;&#12395;&#20351;&#29992;&#12377;&#12427;&#33394;:bpal&#12458;&#12503;&#12471;&#12519;&#12531;;&#21021;&#26399;&#20516;:NULL(&#38738;&#33394;)
#bathy class&#12395;&#21547;&#12414;&#12428;&#12427;&#22320;&#24418;&#12487;&#12540;&#12479;&#12398;&#21033;&#29992;:land&#12458;&#12503;&#12471;&#12519;&#12531;:TRUE/FALSE
#&#31561;&#28145;&#32218;&#38291;&#38548;&#12398;&#35373;&#23450;:n&#12458;&#12503;&#12471;&#12519;&#12531;
#&#31561;&#28145;&#32218;&#12398;&#22826;&#12373;/&#32218;&#31278;/&#33394;:lwd/lty/col&#12458;&#12503;&#12471;&#12519;&#12531;
#&#31561;&#28145;&#32218;&#12521;&#12505;&#12523;:drawlabels&#12458;&#12503;&#12471;&#12519;&#12531;
#X&#36600;/Y&#36600;&#12398;&#12521;&#12505;&#12523;:xlab/ylab&#12458;&#12503;&#12471;&#12519;&#12531;
#X/Y&#12398;&#12450;&#12473;&#12506;&#12463;&#12488;&#27604;:asp&#12458;&#12503;&#12471;&#12519;&#12531;
#&#12300;base::plot&#12301;&#12398;&#12458;&#12503;&#12471;&#12519;&#12531;&#12364;&#35373;&#23450;&#21487;&#33021;
plot(x = TestBathy, image = TRUE,
     #help&#12424;&#12426;[&#28145;&#12373;&#21046;&#38480;&#12398;&#12354;&#12427;&#12497;&#12524;&#12483;&#12488;]&#20316;&#25104;&#20363;
     bpal = list(c(min(TestBathy), 0, "purple", "blue", "lightblue"),
                 c(0, max(TestBathy), "gray90", "gray10")),
     land = TRUE, n = 15, lwd = 1, lty = 1, col = "black",
     drawlabels = TRUE, xlab = "Longitude", ylab = "Latitude",
     asp = 1,
     #&#20197;&#19979;&#12300;base::plot&#12301;&#12398;&#12458;&#12503;&#12471;&#12519;&#12531;
     #&#26528;&#12398;&#25551;&#20889;&#26377;&#28961;
     bty = "n",
     #&#12479;&#12452;&#12488;&#12523;&#12392;&#20307;&#35009;
     main = "&#12363;&#12425;&#12384;&#12395;&#12356;&#12356;&#12418;&#12398; TEST",
     font.main = 2, col.main = "blue", 
     #&#36600;&#12398;&#20307;&#35009;
     font.lab = 2, font.axis = 2, col.axis = "yellow",
     xaxs = "r", tcl = 0.3)

#&#12503;&#12525;&#12483;&#12488;&#12395;&#12473;&#12465;&#12540;&#12523;&#12434;&#36861;&#21152;:scaleBathy&#12467;&#12510;&#12531;&#12489;
#bathy class&#12434;&#25351;&#23450;:mat&#12458;&#12503;&#12471;&#12519;&#12531;
#km&#12395;&#22793;&#25563;&#12377;&#12427;&#32076;&#24230;&#25968;:deg&#12458;&#12503;&#12471;&#12519;&#12531;;&#20363;&#12391;&#12399;1=84km
#&#12503;&#12525;&#12483;&#12488;&#20301;&#32622;:x/y&#12458;&#12503;&#12471;&#12519;&#12531;;"bottomleft","bottomright","topright","topleft"&#12398;
#&#12356;&#12378;&#12428;&#12363;&#12391;x&#12458;&#12503;&#12471;&#12519;&#12531;&#12398;&#12415;&#12434;&#25351;&#23450;&#12377;&#12427;&#12398;&#12364;&#31777;&#21336;&#12391;&#12377;
#x/y&#12458;&#12503;&#12471;&#12519;&#12531;&#12434;&#12461;&#12540;&#12527;&#12540;&#12489;&#12391;&#25351;&#23450;&#12375;&#12383;&#26178;&#12398;&#30456;&#23550;&#20301;&#32622;:inset&#12458;&#12503;&#12471;&#12519;&#12531;
scaleBathy(mat = TestBathy, deg = 3,
           x = "bottomleft", inset = 5, 
           angle = 90, lwd = 0.5, col = "black")

#plot.bathy&#12467;&#12510;&#12531;&#12489;&#12503;&#12525;&#12483;&#12488;&#12363;&#12425;&#12452;&#12531;&#12479;&#12521;&#12463;&#12486;&#12451;&#12502;&#12395;&#28145;&#24230;&#12434;&#21462;&#24471;:get.depth&#12467;&#12510;&#12531;&#12489;
#bathy class&#12434;&#25351;&#23450;:mat&#12458;&#12503;&#12471;&#12519;&#12531;
GetPoint <- get.depth(mat = TestBathy, distance = TRUE)

#&#21462;&#24471;&#12487;&#12540;&#12479;&#12363;&#12425;&#12395;&#36984;&#25246;&#28857;&#12434;&#12503;&#12525;&#12483;&#12488;
points(GetPoint$lon, GetPoint$lat, pch = 21,
       col = "black", bg = "yellow", cex = 2)

#&#25351;&#23450;&#12375;&#12383;&#12505;&#12523;&#12488;&#31684;&#22258;&#12398;&#28145;&#24230;&#12434;&#21462;&#24471;:get.box&#12467;&#12510;&#12531;&#12489;
#bathy class&#12434;&#25351;&#23450;:bathy&#12458;&#12503;&#12471;&#12519;&#12531;
#&#24231;&#27161;&#31684;&#22258;&#12398;&#25351;&#23450;:&#32076;&#24230;:x1,x2;&#32239;&#24230;:y1,y2&#12458;&#12503;&#12471;&#12519;&#12531;
#&#24133;&#12434;&#25351;&#23450;:width&#12458;&#12503;&#12471;&#12519;&#12531;
#haversine Formula&#12398;&#36317;&#38626;&#12434;&#31639;&#20986;:distance&#12458;&#12503;&#12471;&#12519;&#12531;
#plot.bathy&#12467;&#12510;&#12531;&#12489;&#12503;&#12525;&#12483;&#12488;&#12363;&#12425;&#12452;&#12531;&#12479;&#12521;&#12463;&#12486;&#12451;&#12502;&#12395;&#22320;&#28857;&#12434;&#25351;&#23450;:locator&#12458;&#12503;&#12471;&#12519;&#12531;;TRUE/FALSE
GetBoxTransect <- get.box(bathy = TestBathy,
                          x1 = 139, y1 = 43,
                          x2 = 146, y2 = 43,
                          width = 1,
                          locator = FALSE)

#&#32080;&#26524;&#12434;3D&#12503;&#12525;&#12483;&#12488;:&#20844;&#24335;&#12469;&#12452;&#12488;&#12398;&#36039;&#26009;&#12424;&#12426;
#lattice&#12497;&#12483;&#12465;&#12540;&#12472;&#12364;&#12394;&#12369;&#12428;&#12400;&#12452;&#12531;&#12473;&#12488;&#12540;&#12523;
if(!require("lattice", quietly = TRUE)){
  install.packages("lattice");require("lattice")
}
#&#12503;&#12525;&#12483;&#12488;
wireframe(GetBoxTransect, shade = TRUE, zoom = 1.2, aspect = c(1/4, 0.2),
          screen = list(z =-20, x = -50),
          par.settings = list(axis.line = list(col = "transparent")),
          par.box = c(col = rgb(0, 0, 0, 0.1)))

#&#25351;&#23450;&#12375;&#12383;&#24231;&#27161;&#31684;&#22258;&#12398;&#28145;&#24230;&#12434;&#21462;&#24471;:get.transect&#12467;&#12510;&#12531;&#12489;
#bathy class&#12434;&#25351;&#23450;:mat&#12458;&#12503;&#12471;&#12519;&#12531;
#&#24231;&#27161;&#31684;&#22258;&#12398;&#25351;&#23450;:&#32076;&#24230;:x1,x2;&#32239;&#24230;:y1,y2&#12458;&#12503;&#12471;&#12519;&#12531;
#haversine Formula&#12398;&#36317;&#38626;&#12434;&#31639;&#20986;:distance&#12458;&#12503;&#12471;&#12519;&#12531;
#plot.bathy&#12467;&#12510;&#12531;&#12489;&#12503;&#12525;&#12483;&#12488;&#12363;&#12425;&#12452;&#12531;&#12479;&#12521;&#12463;&#12486;&#12451;&#12502;&#12395;&#22320;&#28857;&#12434;&#25351;&#23450;:locator&#12458;&#12503;&#12471;&#12519;&#12531;;TRUE/FALSE
GetTransect <- get.transect(mat = TestBathy,
                            x1 = 140, y1 = 41,
                            x2 = 140, y2 = 43,
                            locator = FALSE,
                            distance = TRUE)
#get.transect&#12467;&#12510;&#12531;&#12489;&#12398;&#32080;&#26524;&#12434;&#12503;&#12525;&#12483;&#12488;:plotProfile&#12467;&#12510;&#12531;&#12489;
#get.transect&#12467;&#12510;&#12531;&#12489;&#12398;&#32080;&#26524;&#12434;&#25351;&#23450;:profile&#12458;&#12503;&#12471;&#12519;&#12531;
plotProfile(profile = GetTransect)

出力例

・コマンド例の初めからget.boxコマンドまで実行時

・結果を3Dプロット

・plotProfileコマンド


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

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