グラフィックス参考実例集:鳥瞰図
をテンプレートにして作成
[
トップ
] [
新規
|
一覧
|
検索
|
最終更新
|
ヘルプ
]
開始行:
COLOR(red){SIZE(20){グラフィックス参考実例集:鳥瞰図 persp}}~
([[グラフィックス参考実例集]]に戻る。[[Rのグラフィックスパラメータ]]を参照する。)~
persp() 関数は二次元曲面の鳥瞰図を描く。[[ヒストグラムと密度の推定]] にも実例あり。
#contents
~
** 曲面の色調を与える関数 (r-help 記事より 2003.12.28) [#t9b2555b]
~
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)
#ref(グラフィックス参考実例集:鳥瞰図/surfcolors1.png, left)
persp(x, col = surf.colors(x, col = heat.colors(40)), phi = 30,
theta = 225, box = F, border = NA, shade = .4)
#ref(グラフィックス参考実例集:鳥瞰図/surfcolors2.png, left)
persp(x, col = surf.colors(x, col = topo.colors(40)), phi = 30,
theta = 225, box = F, border = NA, shade = .4)
#ref(グラフィックス参考実例集:鳥瞰図/surfcolors3.png, left)
persp(x, col = surf.colors(x, col = gray(seq(0, 1, len = 40))), phi = 30,
theta = 225, box = F, border = NA, shade = .4)
#ref(グラフィックス参考実例集:鳥瞰図/surfcolors4.png, left)
終了行:
COLOR(red){SIZE(20){グラフィックス参考実例集:鳥瞰図 persp}}~
([[グラフィックス参考実例集]]に戻る。[[Rのグラフィックスパラメータ]]を参照する。)~
persp() 関数は二次元曲面の鳥瞰図を描く。[[ヒストグラムと密度の推定]] にも実例あり。
#contents
~
** 曲面の色調を与える関数 (r-help 記事より 2003.12.28) [#t9b2555b]
~
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)
#ref(グラフィックス参考実例集:鳥瞰図/surfcolors1.png, left)
persp(x, col = surf.colors(x, col = heat.colors(40)), phi = 30,
theta = 225, box = F, border = NA, shade = .4)
#ref(グラフィックス参考実例集:鳥瞰図/surfcolors2.png, left)
persp(x, col = surf.colors(x, col = topo.colors(40)), phi = 30,
theta = 225, box = F, border = NA, shade = .4)
#ref(グラフィックス参考実例集:鳥瞰図/surfcolors3.png, left)
persp(x, col = surf.colors(x, col = gray(seq(0, 1, len = 40))), phi = 30,
theta = 225, box = F, border = NA, shade = .4)
#ref(グラフィックス参考実例集:鳥瞰図/surfcolors4.png, left)
ページ名: