Assignment 1:
Create 3 vectors, x, y, z and choose any random values for them, ensuring they are of equal length,
Create 3 dimensional plot of the same.
Solution:
Step 1:
Create dataset of 50 items with mean =22 and standard deviation =5
data<-rnorm(50,mean=22,sd=5).
Step2 :
Find out three random sample of equal length to create 3 vectors x,y,z,
> x<-sample(data,15)
> y<-sample(data,15)
> z<-sample(data,15)
Step3: Bind the 3 vectors together.
> bindedData<-cbind(x,y,z)
> bindedData
plot3d(bindedData[,1:3])
plot3d(bindedData[,1:3],xlab="X Axis" , ylab="Y Axis" , zlab="Z Axis", col=rainbow(5000))
c) With Spheres
plot3d(bindedData[,1:3],xlab="X Axis" , ylab="Y Axis" , zlab="Z Axis", col=rainbow(5000), type="s")
d)
plot3d(bindedData[,1:3],xlab="X Axis" , ylab="Y Axis" , zlab="Z Axis", col=rainbow(5000), type="l")
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 :
Step1:
Create 2 random variables x,y using rnorm
Add a 3rd variable by sampling data and using the factor as shown -:
> x <- rnorm(1000, mean= 40 , sd=10)
> y <- rnorm(1000, mean= 30, sd=10)
> z1 <- sample(letters, 5)
> z2 <- sample(z1, 1000, replace=TRUE)
> z <- as.factor(z2)
a) x & y
b) qplot(x,z)
c)Semi transparent qplot between x and z with alpha
Create 3 dimensional plot of the same.
Solution:
Step 1:
Create dataset of 50 items with mean =22 and standard deviation =5
data<-rnorm(50,mean=22,sd=5).
Step2 :
Find out three random sample of equal length to create 3 vectors x,y,z,
> x<-sample(data,15)
> y<-sample(data,15)
> z<-sample(data,15)
Step3: Bind the 3 vectors together.
> bindedData<-cbind(x,y,z)
> bindedData
3D Plots
a) Normal 3d Plot:
plot3d(bindedData[,1:3])
b) With labelled Axis
plot3d(bindedData[,1:3],xlab="X Axis" , ylab="Y Axis" , zlab="Z Axis", col=rainbow(5000))
c) With Spheres
plot3d(bindedData[,1:3],xlab="X Axis" , ylab="Y Axis" , zlab="Z Axis", col=rainbow(5000), type="s")
d)
plot3d(bindedData[,1:3],xlab="X Axis" , ylab="Y Axis" , zlab="Z Axis", col=rainbow(5000), type="l")
Assignment 2:
Create 2 random variablesCreate 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 :
Step1:
Create 2 random variables x,y using rnorm
Add a 3rd variable by sampling data and using the factor as shown -:
> x <- rnorm(1000, mean= 40 , sd=10)
> y <- rnorm(1000, mean= 30, sd=10)
> z1 <- sample(letters, 5)
> z2 <- sample(z1, 1000, replace=TRUE)
> z <- as.factor(z2)
Plots:
a) x & y
b) qplot(x,z)
c)Semi transparent qplot between x and z with alpha
qplot(x,z , alpha=I(4/10))
d) Colored Plot
qplot(x,y , color=z)
e) Logarithmic Colored Plot
qplot(log(x),log(y) , color=z)
f)smooth curve and best fit line using geom
qplot(x,y,geom=c("path","smooth"))
qplot(x,y,geom=c("point","smooth"))
g) qplot(x,y,geom=c("boxplot","jitter"))














No comments:
Post a Comment