Saturday, 30 March 2013

IT Business Lab Class 10

IT Business Lab ; Assignment 10        3D Plotting



Assignment 1: 

To Create 3 vectors, x, y, z and choose any random values for them, bind them together and to create 3 dimensional plots of the same.


Commands:

First creating a random data set of 50 items with mean =30 and standard deviation =10

> data <- rnorm(50,mean=30,sd=10)
> data

Taking sample data of length 10 from the created data set in three different vectors x,y,z
> x <- sample(data,10)
> x

> y <- sample(data,10)
> y

> z <- sample(data,10)
> z

Binding the three vectors x,y,z into a vector T using cbind
> T <- cbind(x,y,z)
> T
          


Data Set

Plotting 3d graph 

Command:

> plot3d(T[,1:3])
3D plot

Plotting of graph with labels for axes and color

Command 
> plot3d(T[,1:3], xlab="X Axis" , ylab="Y Axis" , zlab="Z Axis", col=rainbow(500))
3D plot with color

Plotting of graph with labels for axes, color and type = spheres

Command
> plot3d(T[,1:3], xlab="X Axis" , ylab="Y Axis" , zlab="Z Axis", col=rainbow(5000), type='s')
3D Plot with spheres


Plotting of graph with labels for axes, color and type = points

Command

> plot3d(T[,1:3], xlab="X Axis" , ylab="Y Axis" , zlab="Z Axis", col=rainbow(5000), type='p')
3D Plot with Points


Plotting of graph with labels for axes, color and type = lines

Command

> plot3d(T[,1:3], xlab="X Axis" , ylab="Y Axis" , zlab="Z Axis", col=rainbow(5000), type='l')
3D Plot with Lines



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

Commands

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

Creating Quick Plots

Command:

>qplot(x,y)
x and y qplot

>qplot(x,z)
x and z qplot

For semi-transparent plot

> qplot(x,z, alpha=I(2/10))
Semi-transparent Plot


For coloured plot

> qplot(x,y, color=z)

Colored plot


For Logarithmic coloured plot

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

Best Fit and Smooth curve using "geom"

Command:

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

geom='path'

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

geom='point'


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

No comments:

Post a Comment