I am trying to create a 3D scatter plot using plot3D
package. Unfortunately I have a trouble in assigning color to each points.
For example, when I try to draw 8 points on the plot and I want to assign "black" to first 4 points and "red" to last 4 points respectively, I have written the following script (in this script, I employed 8 sample from the sample dataset iris
and tried to assign Sepal.Length
, Petal.Length
, Sepal.Width
to X, Y, Z axis, respectively);
data(iris)
sep.l <- iris[1:8,]$Sepal.Length
pet.l <- iris[1:8,]$Petal.Length
sep.w <- iris[1:8,]$Sepal.Width
library(plot3D)
scatter3D(x=sep.l, y=pet.l, z=sep.w,
pch =19,
bty = "b2",
colkey= FALSE,
col=c(rep("black", 4), rep("red", 4)))
In this case, strangely enough, 6 points were colored black and 2 points were colored red, respectively. I am completely at a loss why this happens.
I would appreciate so much if you kindly let me know how to solve this problem. Thank you very much in advance!