Goal: I want to create a 3D barplot (as shown below) showing value z for each combination of methods "X1"-"X4" and "Y1"-"Y4", where the labels shall correspond to the rank of the z variable.
Problem: As you can see below, the labels in the image do not match the ranking values of z (rank 1 = lowest value of z, rank 16 = highest value of z). For instance, combination "X1-Y3" should have the index 1 instead of 8, because it has the lowest z-value. Hence, how can I fix this?
Image-Output (with wrong labels): Here is the image output that I get, with the wrong labels (i.e. the labels do not correspond to the ranks of the z-axis values).
R-Code: For image above, where I overlay a textplot onto a barplot.
# load necessary libraries
library(lattice)
library(latticeExtra)
# create dataframe
df.test <- data.frame(matrix(NA, nrow=16, ncol=4))
names(df.test) <- c("x", "y", "z", "z.rank")
# fill dataframe
df.test$x <- as.factor(rep(c("X1", "X2", "X3", "X4"), times=4))
df.test$y <- as.factor(rep( paste0("Y", 1:4), each=4))
set.seed(2); df.test$z <- abs(rnorm(16, 0, 1))
# labels (rankings of z, from largest to smallest)
df.test$z.rank <- as.numeric(rank(df.test$z))
# plot 1 (bars)
p1.test <- cloud(z~x+y, data=df.test, panel.3d.cloud=panel.3dbars,
ylab="Y", xlab="X", zlab="Z",
xbase=0.2, ybase=0.2, scales=list(arrows=FALSE, col="black", distance=1),
par.settings = list(axis.line = list(col = "transparent")),
screen = list(z = 35, x = -35, y=0),
alpha.facet = 1.00, border = "transparent",
zoom=1.00
); print(p1.test)
# plot 2 (labels)
p2.test <- cloud(z~x+y, data=df.test, panel.3d.cloud=panel.3dtext,
labels=as.character(df.test$z.rank),
ylab="", xlab="", zlab="",
par.settings = list(axis.line = list(col = "transparent")),
screen = list(z = 35, x = -35, y=0),
alpha.facet = 1.00, border = "transparent",
zoom=1.00, cex=0.5, pos=3, offset=1.75
); print(p2.test)
# plot both (overlay p2.test onto p1.test)
print(p1.test, more=TRUE)
print(p2.test, more=FALSE)