Search code examples
r3drgl

How to join points in Plot3D (rgl) in R


I am trying to make a 3D plot and join the points according only to variable V1 but I am having the following result:

plot3d(Datos$V1,
       Datos$V2,
       Datos$V3,
       type="l",
       xlab="v1",ylab="v2",zlab="v3",
       group.by=Datos$V1,
       col = Datos$V1)

3D plot

I am trying to remove the diagonal line but I can't seem to find the issue here.


Solution

  • There's no group.by argument to plot3d. You'll need to plot the groups separately. For example,

    plot3d(Datos$V1,
       Datos$V2,
       Datos$V3,
       type="n",   # Plot nothing, but set up the axes
       xlab="v1",ylab="v2",zlab="v3")
    for (g in unique(Datos$V1)) 
       with(subset(Datos, V1 == g), 
         lines3d(V1, V2, V3, col = g))