グラフィックス参考実例集:三次元散布図
をテンプレートにして作成
[
トップ
] [
新規
|
一覧
|
検索
|
最終更新
|
ヘルプ
]
開始行:
COLOR(red){SIZE(20){グラフィックス参考実例集:三次元散布図 scatterplot3d}}~
([[グラフィックス参考実例集]]に戻る。[[Rのグラフィックスパラメータ]]を参照する。)~
アドオンパッケージのライブラリ scatterplot3d により実現できる三次元散布図の例。2ch で匿名子が絶賛。image, persp, contour (coplot も?) に続く三次元データのグラフィックス。たしかに三次元図は見栄えが良く、論文の飾りに好適だが、しばしばそれだけに留まるので注意がいるか。人間の視覚は二次元対象で最も鋭敏のようである。
#contents
~
** 例 1
scatterplot3d1 <- function() {
library(scatterplot3d)
z <- seq(-10, 10, 0.01)
x <- cos(z)
y <- sin(z)
scatterplot3d(x, y, z, highlight.3d=TRUE, col.axis="blue",
col.grid="lightblue", main="scatterplot3d - 1", pch=20)
pp <- recordPlot()
png("scatterplot3d1.png")
replayPlot(pp)
dev.off()
}
#ref(scatterplot3d1.png,left)
** 例 2
scatterplot3d2 <- function() {
library(scatterplot3d)
temp <- seq(-pi, 0, length = 50)
x <- c(rep(1, 50) %*% t(cos(temp)))
y <- c(cos(temp) %*% t(sin(temp)))
z <- c(sin(temp) %*% t(sin(temp)))
scatterplot3d(x, y, z, highlight.3d=TRUE,
col.axis="blue", col.grid="lightblue",
main="scatterplot3d - 2", pch=20)
pp <- recordPlot()
png("scatterplot3d2.png")
replayPlot(pp)
dev.off()
}
#ref(scatterplot3d2.png,left)
** 例 3
scatterplot3d3 <- function() {
library(scatterplot3d)
temp <- seq(-pi, 0, length = 50)
x <- c(rep(1, 50) %*% t(cos(temp)))
y <- c(cos(temp) %*% t(sin(temp)))
z <- 10 * c(sin(temp) %*% t(sin(temp)))
color <- rep("green", length(x))
temp <- seq(-10, 10, 0.01)
x <- c(x, cos(temp))
y <- c(y, sin(temp))
z <- c(z, temp)
color <- c(color, rep("red", length(temp)))
scatterplot3d(x, y, z, color, pch=20, zlim=c(-2, 10),
main="scatterplot3d - 3")
pp <- recordPlot()
png("scatterplot3d3.png")
replayPlot(pp)
dev.off()
}
#ref(scatterplot3d3.png,left)
** 例 4
scatterplot3d4 <- function() {
library(scatterplot3d)
my.mat <- matrix(runif(25), nrow=5)
dimnames(my.mat) <- list(LETTERS[1:5], letters[11:15])
s3d.dat <- data.frame(cols=as.vector(col(my.mat)),
rows=as.vector(row(my.mat)),
value=as.vector(my.mat))
scatterplot3d(s3d.dat, type="h", lwd=5, pch=" ",
x.ticklabs=colnames(my.mat), y.ticklabs=rownames(my.mat),
color=grey(25:1/40), main="scatterplot3d - 4")
pp <- recordPlot()
png("scatterplot3d4.png")
replayPlot(pp)
dev.off()
}
#ref(scatterplot3d4.png,left)
** 例 5
scatterplot3d5 <- function() {
library(scatterplot3d)
data(trees)
s3d <- scatterplot3d(trees, type="h", highlight.3d=TRUE,
angle=55, scale.y=0.7, pch=16, main="scatterplot3d - 5")
## Now adding some points to the "scatterplot3d"
s3d$points3d(seq(10,20,2), seq(85,60,-5), seq(60,10,-10),
col="blue", type="h", pch=16)
## Now adding a regression plane to the "scatterplot3d"
attach(trees)
my.lm <- lm(Volume ~ Girth + Height)
s3d$plane3d(my.lm)
pp <- recordPlot()
png("scatterplot3d5.png")
replayPlot(pp)
dev.off()
}
#ref(scatterplot3d5.png,left)
** 例 6; by Martin Maechler
scatterplot3d6 <- function() {
library(scatterplot3d)
cubedraw <- function(res3d, min = 0, max = 255, cex = 2)
{
## Purpose: Draw nice cube with corners
cube01 <- rbind(c(0,0,1),0,c(1,0,0),c(1,1,0),1,c(0,1,1),c(0,0,1),
c(1,0,1),c(1,0,0),c(1,0,1),1,c(1,1,0),
c(0,1,0),c(0,1,1), c(0,1,0),0)
cub <- min + (max-min)* cube01
res3d$points3d(cub[ 1:11,], cex = cex, type = 'b', lty = 1)
res3d$points3d(cub[11:15,], cex = cex, type = 'b', lty = 3)
}
## 6 a) The named colors in R, i.e. colors()
cc <- colors()
crgb <- t(col2rgb(cc))
par(xpd = TRUE)
rr <- scatterplot3d(crgb, color = cc, box = FALSE, angle = 24,
xlim = c(-50, 300), ylim = c(-50, 300), zlim = c(-50, 300))
cubedraw(rr)
## 6 b) The rainbow colors from rainbow(201)
rbc <- rainbow(201)
Rrb <- t(col2rgb(rbc))
rR <- scatterplot3d(Rrb, color = rbc, box = FALSE, angle = 24,
xlim = c(-50, 300), ylim = c(-50, 300), zlim = c(-50, 300))
cubedraw(rR)
rR$points3d(Rrb, col = rbc, pch = 16)
pp <- recordPlot()
png("scatterplot3d6.png")
replayPlot(pp)
dev.off()
}
#ref(scatterplot3d6.png,left)
終了行:
COLOR(red){SIZE(20){グラフィックス参考実例集:三次元散布図 scatterplot3d}}~
([[グラフィックス参考実例集]]に戻る。[[Rのグラフィックスパラメータ]]を参照する。)~
アドオンパッケージのライブラリ scatterplot3d により実現できる三次元散布図の例。2ch で匿名子が絶賛。image, persp, contour (coplot も?) に続く三次元データのグラフィックス。たしかに三次元図は見栄えが良く、論文の飾りに好適だが、しばしばそれだけに留まるので注意がいるか。人間の視覚は二次元対象で最も鋭敏のようである。
#contents
~
** 例 1
scatterplot3d1 <- function() {
library(scatterplot3d)
z <- seq(-10, 10, 0.01)
x <- cos(z)
y <- sin(z)
scatterplot3d(x, y, z, highlight.3d=TRUE, col.axis="blue",
col.grid="lightblue", main="scatterplot3d - 1", pch=20)
pp <- recordPlot()
png("scatterplot3d1.png")
replayPlot(pp)
dev.off()
}
#ref(scatterplot3d1.png,left)
** 例 2
scatterplot3d2 <- function() {
library(scatterplot3d)
temp <- seq(-pi, 0, length = 50)
x <- c(rep(1, 50) %*% t(cos(temp)))
y <- c(cos(temp) %*% t(sin(temp)))
z <- c(sin(temp) %*% t(sin(temp)))
scatterplot3d(x, y, z, highlight.3d=TRUE,
col.axis="blue", col.grid="lightblue",
main="scatterplot3d - 2", pch=20)
pp <- recordPlot()
png("scatterplot3d2.png")
replayPlot(pp)
dev.off()
}
#ref(scatterplot3d2.png,left)
** 例 3
scatterplot3d3 <- function() {
library(scatterplot3d)
temp <- seq(-pi, 0, length = 50)
x <- c(rep(1, 50) %*% t(cos(temp)))
y <- c(cos(temp) %*% t(sin(temp)))
z <- 10 * c(sin(temp) %*% t(sin(temp)))
color <- rep("green", length(x))
temp <- seq(-10, 10, 0.01)
x <- c(x, cos(temp))
y <- c(y, sin(temp))
z <- c(z, temp)
color <- c(color, rep("red", length(temp)))
scatterplot3d(x, y, z, color, pch=20, zlim=c(-2, 10),
main="scatterplot3d - 3")
pp <- recordPlot()
png("scatterplot3d3.png")
replayPlot(pp)
dev.off()
}
#ref(scatterplot3d3.png,left)
** 例 4
scatterplot3d4 <- function() {
library(scatterplot3d)
my.mat <- matrix(runif(25), nrow=5)
dimnames(my.mat) <- list(LETTERS[1:5], letters[11:15])
s3d.dat <- data.frame(cols=as.vector(col(my.mat)),
rows=as.vector(row(my.mat)),
value=as.vector(my.mat))
scatterplot3d(s3d.dat, type="h", lwd=5, pch=" ",
x.ticklabs=colnames(my.mat), y.ticklabs=rownames(my.mat),
color=grey(25:1/40), main="scatterplot3d - 4")
pp <- recordPlot()
png("scatterplot3d4.png")
replayPlot(pp)
dev.off()
}
#ref(scatterplot3d4.png,left)
** 例 5
scatterplot3d5 <- function() {
library(scatterplot3d)
data(trees)
s3d <- scatterplot3d(trees, type="h", highlight.3d=TRUE,
angle=55, scale.y=0.7, pch=16, main="scatterplot3d - 5")
## Now adding some points to the "scatterplot3d"
s3d$points3d(seq(10,20,2), seq(85,60,-5), seq(60,10,-10),
col="blue", type="h", pch=16)
## Now adding a regression plane to the "scatterplot3d"
attach(trees)
my.lm <- lm(Volume ~ Girth + Height)
s3d$plane3d(my.lm)
pp <- recordPlot()
png("scatterplot3d5.png")
replayPlot(pp)
dev.off()
}
#ref(scatterplot3d5.png,left)
** 例 6; by Martin Maechler
scatterplot3d6 <- function() {
library(scatterplot3d)
cubedraw <- function(res3d, min = 0, max = 255, cex = 2)
{
## Purpose: Draw nice cube with corners
cube01 <- rbind(c(0,0,1),0,c(1,0,0),c(1,1,0),1,c(0,1,1),c(0,0,1),
c(1,0,1),c(1,0,0),c(1,0,1),1,c(1,1,0),
c(0,1,0),c(0,1,1), c(0,1,0),0)
cub <- min + (max-min)* cube01
res3d$points3d(cub[ 1:11,], cex = cex, type = 'b', lty = 1)
res3d$points3d(cub[11:15,], cex = cex, type = 'b', lty = 3)
}
## 6 a) The named colors in R, i.e. colors()
cc <- colors()
crgb <- t(col2rgb(cc))
par(xpd = TRUE)
rr <- scatterplot3d(crgb, color = cc, box = FALSE, angle = 24,
xlim = c(-50, 300), ylim = c(-50, 300), zlim = c(-50, 300))
cubedraw(rr)
## 6 b) The rainbow colors from rainbow(201)
rbc <- rainbow(201)
Rrb <- t(col2rgb(rbc))
rR <- scatterplot3d(Rrb, color = rbc, box = FALSE, angle = 24,
xlim = c(-50, 300), ylim = c(-50, 300), zlim = c(-50, 300))
cubedraw(rR)
rR$points3d(Rrb, col = rbc, pch = 16)
pp <- recordPlot()
png("scatterplot3d6.png")
replayPlot(pp)
dev.off()
}
#ref(scatterplot3d6.png,left)
ページ名: