3

I have searched high and low across the web and in StackOverflow, but I can't find out how to adjust the axes in the scatter3d() function.

My example code is

library(mvtnorm)
library(rgl)
library(car)

# multivariate norm data, split into two groups
set.seed(41367)
sigma <- matrix(c(9,2,0,2,4,1,0,1,1), ncol=3)
pcaData <- data.frame(rmvnorm(n=100, mean=c(9,4,0), sigma=sigma), gl(2,50))

names(pcaData)<-c("PC1", "PC2", "PC3", "ID")

# Obtain overall min and max across all numerical data
minScale <- min(pcaData[,1:3]) # = -1.883 from 3rd column
maxScale <- max(pcaData[,1:3]) # = 16.309 from 1st column

with(pcaData,{
  scatter3d(PC1, PC2, PC3, surface=F, groups = ID, ellipsoid = T,  grid = F,
            axis.scales = T,
            xlim = c(minScale, maxScale),
            ylim = c(minScale, maxScale),
            zlim = c(minScale, maxScale),
            xlab = "PC-1", 
            ylab = "PC-2",
            zlab = "PC-3")
})
    

Based on above, I would like to have all three axes span a common range. I assumed that xlim = c(low, high) would work, but it is not recognized.

Any help would be appreciated.

Cheers.

lovalery
  • 4,524
  • 3
  • 14
  • 28
  • Welcome to Stack Overflow! Please provide a [minimal reproducible example](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) and include all the packages that are necessary to run your code. That way others can run your code. – Jota May 12 '15 at 22:27
  • Thanks Frank. My first stab included my interpretation of a minimal reproducible example. Your included link was very informative and helpful. – Gregory Steeno May 13 '15 at 13:46
  • I believe `scatter3D()` forces the axes to fit a perfectly symmetrical cube. Hence, you would have to dig into the function to translate both the axes and the points to the desired positions. – Adam Erickson Dec 14 '15 at 09:13

0 Answers0