plot3D::scatter3D
colvar: 色指定のためのベクトル
phiとthetaで角度調節
col: カラーパレット. デフォルトはplot3D::jet.col()
# data
x <- iris$Sepal.Length; y <- iris$Petal.Length; z <- iris$Sepal.Width
# scatter3D
## x, y, zを与える.
plot3D::scatter3D(x, y, z, col = 1)

## 色と軸ラベル
plot3D::scatter3D(
x, y, z,
xlab = "Sepal.Length", ylab = "Petal.Length", zlab = "Sepal.Width", # 軸ラベル
colvar = as.integer(iris$Species), # 色指定の為のベクトル, not factor
col = adjustcolor(c("#999999", "#E69F00", "#56B4E9"), 0.7), # colvarに対応するパレット
colkey = FALSE)

## 軸目盛り,
plot3D::scatter3D(
x, y, z,
xlab = "Sepal.Length", ylab = "Petal.Length", zlab = "Sepal.Width",
phi = 30, theta = 60,
colvar = as.integer(iris$Species),
col = adjustcolor(c("#999999", "#E69F00", "#56B4E9"), 0.5),
colkey = FALSE,
bty = "b2", # "b"[default], "g", "b2", "bl"
ticktype = "detailed", # 軸目盛り
pch = 20, cex = 2, cex.axis = 0.5
)
# textを追加する
lab <- paste0(substr(iris$Species, 1,2), 1:50)
plot3D::text3D(
x, y, z, labels = lab, cex = 0.5, add = T
)

# カラーバーを追加
plot3D::scatter3D(x, y, z,
groups = iris$Species,
xlab = "Sepal.Length", ylab = "Petal.Length", zlab = "Sepal.Width",
surf = NULL,
bty = "b2", # "g", "b2", "bl"
pch = 16,
colvar = as.integer(iris$Species),
col = adjustcolor(c("#1B9E77", "#D95F02", "#7570B3"), 0.5),
cex = 1.5,
colkey = list(at = c(1.3, 2, 2.7),
side = 1,
addlines = FALSE,
length = 0.5,
width = 0.5,
labels = c("setosa", "versicolor", "virginica"))
)

plot3D::plotdev
# data
x <- iris$Sepal.Length; y <- iris$Petal.Length; z <- iris$Sepal.Width
# plotdev
par(mfrow = c(2, 2), mar = c(2, 2, 2, 2))
plot3D::scatter3D(
x, y, z,
xlab = "Sepal.Length", ylab = "Petal.Length", zlab = "Sepal.Width",
phi = 30,
theta = 60,
colvar = as.integer(iris$Species),
col = c("#999999", "#E69F00", "#56B4E9"),
colkey = FALSE)
plot3D::plotdev(theta = 10, clab = "theta = 10")
plot3D::plotdev(theta = 40, clab = "theta = 20")
plot3D::plotdev(theta = 80, clab = "theta = 40")

plotly::plot_ly
# scatter plot
plotly::plot_ly(x=iris$Sepal.Length, y=iris$Sepal.Width, z=iris$Petal.Length,
type="scatter3d",
mode="markers",
color=iris$Species,
size = 5,
alpha = 0.8)
plotly::plot_ly(data = iris, x=~Sepal.Length, y=~Sepal.Width, z=~Petal.Length,
type="scatter3d",
mode="markers",
color=iris$Species,
size = 5,
alpha = 0.8)
# manual color
cols <- c("#999999", "#E69F00", "#56B4E9")
plotly::plot_ly(x=iris$Sepal.Length, y=iris$Sepal.Width, z=iris$Petal.Length,
type="scatter3d",
mode="markers",
color=iris$Species,
marker = list(color=cols[iris$Species]),
size = 5)