タイトル難しい。要は、rglでグリグリ動かせる3Dプロットを描いた上で、そのxy平面上に地図を描いたのでそのまとめ。
Rコード
library("rgl") library("maps") # 地図を取得する state.map <- map("state", xlim=c(-130,-60), ylim=c(25,50), plot = FALSE, fill = FALSE) # 経度緯度を含んだデータフレームを作る state.info <- data.frame(name = state.name, long = state.center$x,lat = state.center$y) # 適当なz軸の値を作る state.info$zvar <- rnorm (nrow (state.info), 20, 5) plot3d(state.info$lon, state.info$lat, state.info$zvar, type="h") lines3d(state.map$x,state.map$y,0, color="red")
解説的なもの
ちなみにstate.mapの構造は、
> str(state.map) List of 4 $ x : num [1:11687] -88.4 -88.4 -88.3 -88.3 -88.3 ... $ y : num [1:11687] 30.4 30.4 30.4 30.4 30.4 ... $ range: num [1:4] -124.7 -67 25.1 49.4 $ names: chr [1:63] "alabama" "arizona" "arkansas" "california" ... - attr(*, "class")= chr "map"
のようになっている。state.map$x が経度で、sate.map$yが緯度。state.map$nameが州の名前になっている。