1

I want to plot a 3 dimensional scatter plot of the following data

structure(list(F = c(18.2108626198083, 2.06349206349206, -15.6842105263158, 
10.9896271376507, -0.556328233657855, 12.076929537247, -16.769617936399, 
-5.40540540540539, 26.7848350566224, 3.44509736144716, -3.78808674169641, 
-3.93232738911752, -17.0253164556962, 50.0781773509046, 12.510897994769, 
20.2367901775926, 26.6812295209861, 0.823250592490954,  -8.45476109793292, 
0.4381988516168, 3.25581395348837, 70.7155195926903, 65.3364908808144, 
34.9882618902704, 13.5342789598109, 15.7754010695187, 25.8784621744522, 
51.1947779461476, 57.65475695887, 25.3116162145177, 3.82276281494354, 
1.79372197309418, 10.2564102564102, 8.47766636280765, -3.43749999999999, 
-2.43828101188662, 7.02947845804989, 6.6265060240964, -17.7431906614786, 
20.9261635366849, -19.79443353736, -5.68079350766456, -3.64931019136626, 
-3.52055681450308, -6.89010606850983, -6.04523785373771, 28.3127758289012, 
7.76389909380357, 1.91727321143262, 3.78228782287824, -11.9123325005678, 
32.2663618176622, 47.3957158962796, 34.7805642633229, -9.11998349324254, 
18.3434354013117, -17.5318341912761, 0.428658909981627, 23.4457537586347, 
42.3697650663943, 6.65660170189404, 11.7365833950576, 27.9735682819383, 
29.3706293706294, 3.40623879526711, -2.29291468704813, -26.2389149713093, 
15.121107266436, -8.24175824175825, -30.518697225573, -7.83855903935958
), D = c(3, 4, 4, 5, 5, 1, 5, 3, 0, 4, 4, 0, 4, 3, 0, 1, 1, 6, 
3, 4, 1, 5, 2, 4, 1, 3, 3, 2, 6, 5, 1, 2, 1, 5, 0, 1, 2, 5, 0, 
4, 0, 1, 1, 0, 2, 2, 2, 6, 6, 3, 1, 6, 6, 2, 3, 6, 0, 1, 3, 2, 
2, 3, 4, 2, 1, 3, 0, 0, 2, 4, 5), C = c(38, 38, 40, 40, 38, 36, 
38, 36, 42, 36, 36, 40, 38, 38, 24, 42, 34, 40, 40, 40, 34, 42, 
36, 42, 38, 40, 44, 40, 38, 36, 32, 30, 32, 36, 38, 38, 32, 40, 
32, 34, 38, 42, 28, 36, 42, 34, 42, 36, 44, 36, 36, 40, 38, 38, 
32, 42, 30, 30, 34, 36, 40, 34, 44, 32, 40, 42, 34, 36, 34, 42, 
44)), .Names = c("F", "D", "C"), row.names = c("var1", "var2", 
"var3", "var4", "var5", "var6", "var7", "var8", "var9", "var10", 
"var11", "var12", "var13", "var14", "var15", "var16", "var17", 
"var18", "var19", "var20", "var21", "var22", "var23", "var24", 
"var25", "var26", "var27", "var28", "var29", "var30", "var31", 
"var32", "var33", "var34", "var35", "var36", "var37", "var38", 
"var39", "var40", "var41", "var42", "var43", "var44", "var45", 
"var46", "var47", "var48", "var49", "var50", "var51", "var52", 
"var53", "var54", "var55", "var56", "var57", "var58", "var59", 
"var60", "var61", "var62", "var63", "var64", "var65", "var66", 
"var67", "var68", "var69", "var70", "var71"), class = "data.frame")

enter image description here

I want to get a picture as the shown in the figure above. I used scatterplot3d package as the following and I get the figure like the one below.

 with(phos, {
 s3d <- scatterplot3d(C,D,F,grid=TRUE, box=TRUE, cex.lab=2,
 color="red", cex.main=2,pch=19,main="3D Scatterplot",
 ylab="D", xlab="C", zlab="F", type="h"
 )})

enter image description here

What I want is that the grid to appear in the other two planes (i.e. I want grid in all 3 planes, X, Y, and Z) and remove the three (only those three) lines in front of the plot. If I do

box=FALSE

in the code above, I get the figure as below which is missing two vertical lines and also the grid and that is not what I want. Is there a way around for this. I would prefer scatterplot3d solutions and not rgl as rgl does not use the base graphics.

enter image description here

discipulus
  • 2,665
  • 3
  • 34
  • 51

1 Answers1

3

Using the function addgrids3d.r() with the source code posted in this forum, you can plot the data in the following way:

scatterplot3d(phos$C,phos$D,phos$F, color="red", pch = 19, grid=FALSE, box=FALSE, main="3D Scatterplot", cex.main=2,cex.lab=2,ylab="D", xlab="C", zlab="F")
addgrids3d(phos$C,phos$D,phos$F, grid = c("xy", "xz", "yz"))

enter image description here

This plot is not exactly as you wanted it (the values of the C axis are increasing to the right, while in your image they are increasing to the left), but it contains the desired grid and does not have the three lines in the front that you wanted to remove. With rgl one could probably achieve a result that is even more similar to your desired output.

RHertel
  • 23,412
  • 5
  • 38
  • 64
  • Thanks but I have this result myself. I want the grid behind the points (in all three planes) and also I want to remove three lines in front. – discipulus Jul 29 '15 at 17:28
  • @lovedynasty: You need to be more clear about how that results is not what you request. The grids do appear "behind the points". What lines need to be removed? – IRTFM Jul 29 '15 at 19:41
  • @BondedDust : Now the answer is fine. The answer was updated. The comment came before the answer was updated. – discipulus Jul 29 '15 at 19:44