Dear R-help, I am using the plot3D package to produce 3D spheres along with 95% CIs distinguishing each sphere with a predefined colour (see the reproducible example at the end). I have been successful in producing a similar plot using a different data set (kindly see https://www.dropbox.com/s/snpgiqgqaiqgpiv/exp1combined.pdf?dl=0), but in this case I cannot arrange the colours as desired. Specifically, the colours obtaind do not correspond to those in the "cols" object below (kindly see https://www.dropbox.com/s/nhljsuare84g811/test_exp2.pdf?dl=0). Any help/tips would be greatly appreciated. Thank you very much in advance. Best regards, Jorge Velez.- ## package needed if(!require(plot3D)) install.packages("plot3D") require(plot3D) ## data to be plotted d0 <- structure(list(X = c(2.5, -2, 1), Z = c(-3.5, 4, -1), Y = c(8, -8.5, -1)), .Names = c("X", "Z", "Y"), row.names = c("high", "low", "medium"), class = "data.frame") d0 ## confidence intervals to be added CI2 <- structure(list(z = structure(c(2, 3, 4, 2, 3, 4), .Dim = c(3L, 2L), .Dimnames = list(c("high", "low", "medium"), c("97.5%", "97.5%"))), y = structure(c(4, 5, 5, 4, 5, 5), .Dim = c(3L, 2L ), .Dimnames = list(c("high", "low", "medium"), c("97.5%", "97.5%" ))), x = structure(c(3, 7, 5, 3, 7, 5), .Dim = c(3L, 2L), .Dimnames = list( c("high", "low", "medium"), c("97.5%", "97.5%"))), alen = 0, lwd = 2), .Names = c("z", "y", "x", "alen", "lwd")) ## colours I would like to have cols <- c("#0080ff", "#ff00ff", "darkgreen") # this produces the 3D plot, but the colours are not properly assigned with(d0, scatter3D(X, Z, Y, bty = "b2", col = cols, pch = 20, cex = 4, ticktype = "detailed", colkey = FALSE, phi 20, theta = -140, zlim = c(-14, 14), xlim = c(-14, 14), ylim = c(-14, 14), xlab = "X", ylab = "Z", zlab = "Y", CI = CI2)) mtext('Experiment 2', line = -0.5, side = 3, cex = 1.3) ?## R session details R> sessionInfo() R version 3.2.4 Patched (2016-03-28 r70416) Platform: x86_64-apple-darwin13.4.0 (64-bit) Running under: OS X 10.11.5 (El Capitan) locale: [1] en_AU.UTF-8/en_AU.UTF-8/en_AU.UTF-8/C/en_AU.UTF-8/en_AU.UTF-8 attached base packages: [1] stats graphics grDevices utils datasets parallel compiler [8] methods base other attached packages: [1] plot3D_1.1 readxl_0.1.1 loaded via a namespace (and not attached): [1] tools_3.2.4 misc3d_0.8-4 Rcpp_0.12.5 [[alternative HTML version deleted]]
I assume you want some variant of: with(d0, scatter3D(X, Z, Y, bty = "b2", col = cols, colvar = c(1, 2, 3), pch = 20, cex = 4, ticktype = "detailed", colkey = FALSE, phi 20, theta = -140, zlim = c(-14, 14), xlim = c(-14, 14), ylim = c(-14, 14), xlab = "X", ylab = "Z", zlab = "Y", CI = CI2)) mtext('Experiment 2', line = -0.5, side = 3, cex = 1.3) You should reread the help for scatter3D, paying close attention to col and colvar arguments. The default value of colvar is z, and that's what scatter3D() was using. Setting colvar to your chosen levels gives you the result you expect. Thanks for the complete reproducible example. I wouldn't have even looked at your problem without something to test. Sarah On Thu, Jul 14, 2016 at 1:55 PM, Jorge I Velez <jorgeivanvelez at gmail.com> wrote:> Dear R-help, > > I am using the plot3D package to produce 3D spheres along with 95% CIs > distinguishing each sphere with a predefined colour (see the reproducible > example at the end). > > I have been successful in producing a similar plot using a different data > set (kindly see > https://www.dropbox.com/s/snpgiqgqaiqgpiv/exp1combined.pdf?dl=0), but in > this case I cannot arrange the colours as desired. Specifically, the > colours obtaind do not correspond to those in the "cols" object below (kindly > see https://www.dropbox.com/s/nhljsuare84g811/test_exp2.pdf?dl=0). > > Any help/tips would be greatly appreciated. > > Thank you very much in advance. > > Best regards, > Jorge Velez.- > > > ## package needed > if(!require(plot3D)) install.packages("plot3D") > require(plot3D) > > ## data to be plotted > d0 <- structure(list(X = c(2.5, -2, 1), Z = c(-3.5, 4, -1), Y = c(8, > -8.5, -1)), .Names = c("X", "Z", "Y"), row.names = c("high", > "low", "medium"), class = "data.frame") > d0 > > ## confidence intervals to be added > CI2 <- structure(list(z = structure(c(2, 3, 4, 2, 3, 4), .Dim = c(3L, > 2L), .Dimnames = list(c("high", "low", "medium"), c("97.5%", > "97.5%"))), y = structure(c(4, 5, 5, 4, 5, 5), .Dim = c(3L, 2L > ), .Dimnames = list(c("high", "low", "medium"), c("97.5%", "97.5%" > ))), x = structure(c(3, 7, 5, 3, 7, 5), .Dim = c(3L, 2L), .Dimnames = list( > c("high", "low", "medium"), c("97.5%", "97.5%"))), alen = 0, > lwd = 2), .Names = c("z", "y", "x", "alen", "lwd")) > > ## colours I would like to have > cols <- c("#0080ff", "#ff00ff", "darkgreen") > > # this produces the 3D plot, but the colours are not properly assigned > with(d0, scatter3D(X, Z, Y, bty = "b2", col = cols, > pch = 20, cex = 4, ticktype = "detailed", colkey = FALSE, phi > 20, theta = -140, zlim = c(-14, 14), xlim = c(-14, 14), ylim = c(-14, 14), > xlab = "X", ylab = "Z", zlab = "Y", CI = CI2)) > mtext('Experiment 2', line = -0.5, side = 3, cex = 1.3) >
Thank you very much, Sarah, for your help. The colvar argument was certainly what I needed. I will follow your suggestion. Cheers, Jorge.- On Thu, Jul 14, 2016 at 1:29 PM, Sarah Goslee <sarah.goslee at gmail.com> wrote:> I assume you want some variant of: > with(d0, scatter3D(X, Z, Y, bty = "b2", col = cols, colvar = c(1, 2, 3), > pch = 20, cex = 4, ticktype = "detailed", colkey = FALSE, phi > 20, theta = -140, zlim = c(-14, 14), xlim = c(-14, 14), ylim = c(-14, 14), > xlab = "X", ylab = "Z", zlab = "Y", CI = CI2)) > mtext('Experiment 2', line = -0.5, side = 3, cex = 1.3) > > You should reread the help for scatter3D, paying close attention to > col and colvar arguments. The default value of colvar is z, and that's > what scatter3D() was using. Setting colvar to your chosen levels gives > you the result you expect. > > Thanks for the complete reproducible example. I wouldn't have even > looked at your problem without something to test. > > Sarah > > On Thu, Jul 14, 2016 at 1:55 PM, Jorge I Velez <jorgeivanvelez at gmail.com> > wrote: > > Dear R-help, > > > > I am using the plot3D package to produce 3D spheres along with 95% CIs > > distinguishing each sphere with a predefined colour (see the reproducible > > example at the end). > > > > I have been successful in producing a similar plot using a different data > > set (kindly see > > https://www.dropbox.com/s/snpgiqgqaiqgpiv/exp1combined.pdf?dl=0), but in > > this case I cannot arrange the colours as desired. Specifically, the > > colours obtaind do not correspond to those in the "cols" object below > (kindly > > see https://www.dropbox.com/s/nhljsuare84g811/test_exp2.pdf?dl=0). > > > > Any help/tips would be greatly appreciated. > > > > Thank you very much in advance. > > > > Best regards, > > Jorge Velez.- > > > > > > ## package needed > > if(!require(plot3D)) install.packages("plot3D") > > require(plot3D) > > > > ## data to be plotted > > d0 <- structure(list(X = c(2.5, -2, 1), Z = c(-3.5, 4, -1), Y = c(8, > > -8.5, -1)), .Names = c("X", "Z", "Y"), row.names = c("high", > > "low", "medium"), class = "data.frame") > > d0 > > > > ## confidence intervals to be added > > CI2 <- structure(list(z = structure(c(2, 3, 4, 2, 3, 4), .Dim = c(3L, > > 2L), .Dimnames = list(c("high", "low", "medium"), c("97.5%", > > "97.5%"))), y = structure(c(4, 5, 5, 4, 5, 5), .Dim = c(3L, 2L > > ), .Dimnames = list(c("high", "low", "medium"), c("97.5%", "97.5%" > > ))), x = structure(c(3, 7, 5, 3, 7, 5), .Dim = c(3L, 2L), .Dimnames > list( > > c("high", "low", "medium"), c("97.5%", "97.5%"))), alen = 0, > > lwd = 2), .Names = c("z", "y", "x", "alen", "lwd")) > > > > ## colours I would like to have > > cols <- c("#0080ff", "#ff00ff", "darkgreen") > > > > # this produces the 3D plot, but the colours are not properly assigned > > with(d0, scatter3D(X, Z, Y, bty = "b2", col = cols, > > pch = 20, cex = 4, ticktype = "detailed", colkey = FALSE, phi > > > 20, theta = -140, zlim = c(-14, 14), xlim = c(-14, 14), ylim = c(-14, > 14), > > xlab = "X", ylab = "Z", zlab = "Y", CI = CI2)) > > mtext('Experiment 2', line = -0.5, side = 3, cex = 1.3) > > >[[alternative HTML version deleted]]