Thursday, 28 March 2013

Drishtikon- Data Visualization and Coloring in 3D

                                     Data Visualization and Coloring in 3D

#this post is created as a solution for assignment for IT & Business Applications Lab, Spring Semester, VGSoM, IIT Kharagpur Class of 2014.

Assignment:1
  • Create 3 vectors, x, y, z and choose any random values for them.
  • Ensuring they are of equal length, bind them together.
  • Create 3 dimensional plots of the same.
Solution:
Commands used in R :
> Random1<-rnorm(30,mean=0,sd=1)
> Random1
> x<-Random1[1:10]
> x
> y<-Random1[11:20]
> y
> z<-Random1[21:30]
> z
> T<-cbind(x,y,z)
> T


Screenshots of Randomization of numbers using rnorm is given below:

    3D-visualization of the generated Vector>>>
     > plot3d(T[,1:3])

      Coloring is done in the following way:
      plot3d(T[,1:3],col=rainbow(64)):


    The points are represented as sphere using the following command:
     > plot3d(T[,1:3],col=rainbow(64),type= 's')

Assignment:2
  • Read the documentation of rnorm and pnorm,
  • Create 2 random variables
  • Create 3 plots:
  • 1. X-Y
  • 2. X-Y|Z (introducing a variable z and cbind it to z and y with 5 diff categories) 
  • 3. Color code and draw the graph 
  • 4. Smooth and best fit line for the curve
Solution:
Creating a data set for two random variables and then introducing third variable z
Commands

 X-Y ,X-Y|Z (introducing a variable z and cbind it to x and y with 5 diff categories)
> x<-rnorm(1500,100,10)
> y<-rnorm(1500,85,5)
> z1<-sample(letters,5)
> z2<-sample(z1,1500,replace=TRUE)
> z<-as.factor(z2)
> t<-cbind(x,y,z)
> qplot(x,y)
 
qplot(x,z)
 
 
 

qplot(x,z,alpha=I(1/10))
 
 
 
qplot(x,y,geom=c("point","smooth"))
 
 
 
 qplot(x,y,colour=z)
 
 
qplot(log(x),log(y),colour=z)
 
 
 

No comments:

Post a Comment