I am generating a 3D categorized plot with the code bellow. As you can see in the range of the examples, the range of vector Z is between 0 and 5, while the range of vector X is between 0 and 20. I want to see them in the 3D not as a square, but as a rectangle type of 3D figure because the lenth of the X is larger than that of the Z for example. How can I make in the plot make the length of the lines of based on range of the values. (So the length of the lines in the plot are based on their proportional length)
I am using lattice, but a solution in GGPLot is also possible
Z<-(sample.int(101,size=100,replace=TRUE)-1)/20
Y<-(sample.int(101,size=100,replace=TRUE)-1)/10
X<-(sample.int(101,size=100,replace=TRUE)-1)/5
boxplot(Z)
cat <- c(rep("A",0.1*100),rep("B",0.2*100),rep("C",0.65*100),rep("D",0.05*100))
cat <- sample(x, 100)
df <- data.frame(X, Y, Z, cat)
library(lattice)
cloud(Z ~ Y * X, group = cat, data = df, auto.key = TRUE)
Try
cloud(Z ~ Y * X, group = cat, data = df, auto.key = TRUE,
aspect=c(2,.5))
From ?cloud
:
aspect
is taken to be a numeric vector of length 2, giving the relative aspects of the y-size/x-size and z-size/x-size of the enclosing cube.
This is for the formula of the form z ~ x * y
.
Note that you have Z ~ Y * X
so the definitions are switched.
EDIT: You could also calculate the relative sizes with something like
cloud(Z ~ Y * X, group = cat, data = df, auto.key = TRUE,
aspect=c(diff(range(X))/diff(range(Y)),diff(range(Z))/diff(range(Y))))