Quantcast
Channel: Active questions tagged r - Stack Overflow
Viewing all articles
Browse latest Browse all 201839

How to rotate 3D Scatterplot

$
0
0

Below is a code that works using the scatterplot3d() function to run a 3D scatterplot of height vs weight vs volume where points are a Class value between 1-6. The angle is currently at 45 degrees and I know I can tilt the plot by changing the angle. What code do I use to rotate the plot to the left or right so that I can provide multiple views of the plot?

df
#    Class   height     weight    volume
# 1    4     0.83         0.85      0.83
# 2    2     0.75         0.80      0.76
# 3    3     0.75         0.80      0.84
# 4    5     0.52         0.59      1
# 5    6     0.52         0.59      0.99

 color <- c(rgb(0.68, 0.93, 0.96), rgb(0, 0.74, 0.92), rgb(0.68, 0.86, 0.49), rgb(1, 0.8, 0.3), 
 rgb(1, 0, 0))
 scatterplot3d(x=c(0.0, 0.5, 0.5, 0, 0), y=c(0, 0, 0.5, 0.5, 0), z=c(0, 0, 0, 0, 0), box=T, type='l', 
 color='grey', grid=F, lwd=2, xlab='height', ylab='', zlab='volume', xlim=c(0, 1), ylim=c(0, 1), 
 zlim=c(0,1), angle=45)
 text(7, 0, 'weight', srt=45)
 par(new=T)

 scatterplot3d(x=c(0.0, 0.5, 0.5, 0.0, 0.0), y=c(0.5, 0.5, 1, 1, 0.5), z=rep(0,5), box=F, type='l', 
 color='grey', grid=F, lwd=2,xlab='', ylab='', zlab='', xlim=c(0, 1), ylim=c(0, 1), zlim=c(0,1), 
 axis=F, angle=45)
 par(new=T)

 scatterplot3d(x=c(0.5, 1, 1, 0.5, 0.5), y=c(0.0, 0.0, 0.5, 0.5, 0.0), z=rep(0,5), box=F, type='l', 
 color='grey', grid=F, lwd=2,
          xlab='', ylab='', zlab='', xlim=c(0, 1), ylim=c(0, 1), zlim=c(0,1), axis=F, angle=45)
 par(new=T)

 scatterplot3d(x=c(0.5, 1, 1, 0.5, 0.5), y=c(0.5, 0.5, 1, 1, 0.5), z=rep(0,5), box=F, type='l', 
 color='grey', grid=F, lwd=2,
          xlab='', ylab='', zlab='', xlim=c(0, 1), ylim=c(0, 1), zlim=c(0,1), axis=F, angle=45)
 par(new=T)

 for (i in 6:2) {

 scatterplot3d(height[Class==i], weight[Class==i], volume[Class==i], box=F, pch=c(2,1,0,1,20)[i-1], 
 color=color[i-1], grid=F,
            xlab='', ylab='', zlab='', xlim=c(0, 1), ylim=c(0, 1), zlim=c(0, 1), axis=F, angle=45)
 par(new=T)
 }
 legend(0.2, 4.7, legend=c(paste('Level', 2:6)), pch=c(2,1,0,1,19), col=color, title='Class', 
 cex=0.70)

Viewing all articles
Browse latest Browse all 201839

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>