0

The scatterplot3D function seems to be plotting incorrectly and I am unsure about why. For example, the following commands should yield identical plots but they do not. I also providing reproducible code to create the data structures below. I guess it is not correctly processing my input?

install.packages("scatterplot3d")
library("scatterplot3d")
cent = array(dim=c(4,3))
cll = c("Factor1", "Factor2", "Factor3")
colnames(cent) = cll
cent[1,] = c(-0.25320707, -0.5878291, -0.4522262)
cent[2,] = c(2.49368231, 0.5911989, -0.3728652)
cent[3,] = c(-0.02927063, -0.2627355, 1.6147719)
cent[4,] = c(-0.63391974, 1.0109955, -0.1542808)

new.cent = array(dim=c(4,3))
colnames(new.cent) = cll
new.cent[1,] = c(2.1572533, 0.4985594, -0.1989068)
new.cent[2,] = c(-0.1362396, -0.4134629, 1.2677813)
new.cent[3,] = c(-0.2566698, -0.6602819, -0.5245323)
new.cent[4,] = c(-0.5847768, 0.7672588, -0.1918044)

Now I try to plot

plot.new()
scatterplot3d(new.cent, pch = 10)
points(cent, pch = 3)

plot of new.cent with cent added as points in different format

plot.new()
scatterplot3d(cent, pch = 3)
points(new.cent, pch = 10)

plot of cent with new.cent added as points in different format

The above points don't seem correct in any case... Moreover, if I try to add a single point as in "points(cent[1,])" it adds three points which is also indicative of the malfunction.

hariskr
  • 1
  • 1
  • 1
    It's easier to help you if you include a simple [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) with sample input and desired output that can be used to test and verify possible solutions. Explicitly list any non-base R packages you are using. – MrFlick Jan 18 '22 at 18:17
  • Done, thanks for the tip – hariskr Jan 18 '22 at 18:38
  • It's still not clear where the `scatterplot3d` actually comes from. That's not a base R function. – MrFlick Jan 18 '22 at 18:42
  • 1
    Can you help me understand why you expect two sets of different coordinates to render identical plots? – Jon Spring Jan 18 '22 at 19:07
  • These are the same sets of coordinates, I just changed the formatting of the points. I added them in inverse orders using plot() and points() in the two examples. visually, they do not seem to make sense either. scatterplot3d is from the package of the same name: https://cran.r-project.org/web/packages/scatterplot3d/scatterplot3d.pdf – hariskr Jan 18 '22 at 21:17

1 Answers1

0

Please refer to linked manual, how to add points3d to the plot. Also, to compare plots, please make sure they axes limits are the same.

library("scatterplot3d")
cent = array(dim=c(4,3))
cll = c("Factor1", "Factor2", "Factor3")
colnames(cent) = cll
cent[1,] = c(-0.25320707, -0.5878291, -0.4522262)
cent[2,] = c(2.49368231, 0.5911989, -0.3728652)
cent[3,] = c(-0.02927063, -0.2627355, 1.6147719)
cent[4,] = c(-0.63391974, 1.0109955, -0.1542808)

new.cent = array(dim=c(4,3))
colnames(new.cent) = cll
new.cent[1,] = c(2.1572533, 0.4985594, -0.1989068)
new.cent[2,] = c(-0.1362396, -0.4134629, 1.2677813)
new.cent[3,] = c(-0.2566698, -0.6602819, -0.5245323)
new.cent[4,] = c(-0.5847768, 0.7672588, -0.1918044)


plot.new()
a <- scatterplot3d(new.cent, pch = 10, xlim = c(-1,2.5), ylim = c(-1,1.5), zlim = c(-1,2))
a$points3d(cent, pch = 3)

b <- scatterplot3d(cent, pch = 3, xlim = c(-1,2.5), ylim = c(-1,1.5), zlim = c(-1,2))
b$points3d(new.cent, pch = 10)

Created on 2022-01-27 by the reprex package (v2.0.1)

Grzegorz Sapijaszko
  • 1,913
  • 1
  • 5
  • 12