[R] scatter3D and colours

Sarah Goslee sarah.goslee at gmail.com
Thu Jul 14 20:29:08 CEST 2016


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)
>



More information about the R-help mailing list