Saturday, 30 March 2013

Adding Dimensions in R

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.

Data Set Creation Commands and DataSet :

> data<-rnorm(50,mean=20,sd =10)
> x<-sample(data,10)
> y<-sample(data,10)
> z<-sample(data,10)
> t<-cbind(x,y,z)
       
                                                                                                                                                                           

Normal Plot:   plot3d(T[, 1:3])   



Colour Plot: plot3d(T[, 1:3], col = rainbow(1000))




Color Plot of spheres:  plot3d(T[, 1:3], col = rainbow(1000), type = 's')





Assignment 2:

Choose 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

Data set creation for two random variables and then introducing third variable z


> x<-rnorm(5000,mean=20,sd=10)
> y<-rnorm(5000,mean=20,sd=10)
> z1<-sample(letters,5)
> z2<-sample(z1,5000,replace=TRUE)
> z<-as.factor(z2)






Plots:
>qplot(x,y)



>qplot(x,z)

                             

Semi-transparent plot

> qplot(x,z, alpha=I(2/10))
                           


Colour plot

> qplot(x,y, color=z)

                             

Logarithmic colour plot

> qplot(log(x),log(y), color=z)
                               

Best Fit and Smooth curve using "geom"

> qplot(x,y,geom=c("path","smooth"))

                                     


> qplot(x,y,geom=c("point","smooth"))
                                   

> qplot(x,y,geom=c("boxplot","smooth"))
                                         

> qplot(x,y,geom=c("boxplot","jitter"))






























                 

No comments:

Post a Comment