Adding a legend to scatter3d plot

前端 未结 1 1954
無奈伤痛
無奈伤痛 2021-02-09 13:13

One of the possible packages for interactive 3D plots is rgl. What I would like to do is to build 3D scatterplot with color coding according to some factor variable. The 3D dime

相关标签:
1条回答
  • 2021-02-09 13:46

    That's not a plot3d image (unless perhaps you have another package loaded) , but looks like a scatter3d rendering constructed with the scatter3d function from the car package by John Fox:

      require(rgl)
      require(car)
      scatter3d(x=loadings[[1]], y=loadings[[2]], z=loadings[[3]], 
                point.col = as.numeric(as.factor(loadings[,4])), size = 10)
    

    The scatter3d function does depend on rgl functions but has quite a few customization options. You offered no code to construct a "legend", so I played around with the example offered in rgl::text3d:

     text3d(1+ font/8, 1+cex/4, 1+famnum/8, text=paste(family, font), adj = 0.5, 
           color="blue", family=family, font=font, cex=cex)
    

    enter image description here

    With the new data this is in response to the request for text and points:

     scatter3d(x=loadings[[1]], y=loadings[[2]], z=loadings[[3]], 
                 point.col = as.numeric(as.factor(loadings[,4])), size = 10)
     text3d(x=1.1, y=c(.9,1,1.1), z=1.1, names(loadings) ,col="black")
     points3d(x=1.2,y=c(.9,1,1.1),z=1.1, col=as.numeric(as.factor(loadings[,4])), size=5)
    

    enter image description here

    0 讨论(0)
提交回复
热议问题