グラフィックス参考実例集:鳥瞰図 persp

(グラフィックス参考実例集に戻る。Rのグラフィックスパラメータを参照する。)

persp() 関数は二次元曲面の鳥瞰図を描く。ヒストグラムと密度の推定 にも実例あり。


曲面の色調を与える関数 (r-help 記事より 2003.12.28)


Function to generate a matrix of colors to be used in perspective plots (based on demo(persp) and the comments of U. Ligges

surf.colors <- function(x, col = terrain.colors(20)) {
  # First we drop the 'borders' and average the facet corners
  # we need (nx - 1)(ny - 1) facet colours!
  x.avg <- (x[-1, -1] + x[-1, -(ncol(x) - 1)] +
             x[-(nrow(x) -1), -1] + x[-(nrow(x) -1), -(ncol(x) - 1)]) / 4 
  # Now we construct the actual colours matrix
  colors = col[cut(x.avg, breaks = length(col), include.lowest = T)]
  return(colors)
}
# Now lets look at an example of using it:
# first lets build some random surface
library(MASS)
x <- cbind(rnorm(100), rnorm(100))
x <- kde2d(x[,1], x[,2], n = 100)$z
# now lets plot it!
par(bg = "gray")
persp(x, col = surf.colors(x), phi = 30, theta = 225, box = F, border = NA, shade = .4)
 left
persp(x, col = surf.colors(x, col = heat.colors(40)), phi = 30, 
      theta = 225, box = F, border = NA, shade = .4)
 left
persp(x, col = surf.colors(x, col = topo.colors(40)), phi = 30, 
      theta = 225, box = F, border = NA, shade = .4)
 left
persp(x, col = surf.colors(x, col = gray(seq(0, 1, len = 40))), phi = 30,
      theta = 225, box = F, border = NA, shade = .4)
 left

添付ファイル: filesurfcolors1.png 2738件 [詳細] filesurfcolors4.png 2427件 [詳細] filesurfcolors3.png 2311件 [詳細] filesurfcolors2.png 2398件 [詳細]

トップ   編集 凍結 差分 バックアップ 添付 複製 名前変更 リロード   新規 一覧 検索 最終更新   ヘルプ   最終更新のRSS
Last-modified: 2023-03-25 (土) 11:19:16