Showing posts with label line plot. Show all posts
Showing posts with label line plot. Show all posts

Friday, May 3, 2013

RG#109:small plot(s) with in a big plot

require(ggplot2)
library(gridBase)

plot(cos, -pi, 2*pi, ylim = c(-1.3, 1.5), col = "red")
myd <- data.frame (X = 1:10, Y = c(3, 4, 8, 7, 2, 1, 9, 4, 2, 3))
qp <- qplot(X, Y, data=myd) + theme_bw()

print(qp, vp=viewport(.65, .65, .25, .25))

 library(lattice)
library(gridBase)

plot.new()
pushViewport(viewport())
set.seed(1234)
xvars <- rnorm(25, 5, 1)
yvars <- rnorm(25, 5, 1)
xyplot(yvars~xvars,  xlim = c(0, 10), ylim = c(0, 10) )
pushViewport(viewport(x=.6,y=.85,width=.20,height=.15,just=c("left","top")))
grid.rect()
par(plt = gridPLT(), new=TRUE)
plot(xvars,yvars)
popViewport(2)






 

Tuesday, April 9, 2013

RG#46: 3D-spinning scatter plots


set.seed(12444)
X = rnorm (1000, 50, 10)
Y = X*0.6+rnorm(length(X), 0, 10)
Z = Y*0.3+ +rnorm(length(X), 0, 10) 


# using rgl package 

library(rgl)

plot3d(Z, X, Y, col="red", size=3)



# another using package Rcmdr 

library(Rcmdr)
scatter3d(Z, X, Y)






RG#45: 3D scatter plots (with vertical lines and regression line)


set.seed(12444)
X = rnorm (1000, 50, 10)
Y = X*0.6+rnorm(length(X), 0, 10)
Z = Y*0.3+ +rnorm(length(X), 0, 10) 


# 3D Scatterplot
require(scatterplot3d)
scatterplot3d(X,Y,Z, pch = 19, color = "green4", main="3D Scatterplot")




thdp <- scatterplot3d(X,Y,Z, pch = 19,  main="3D Scatterplot", highlight.3d=TRUE,
type="h")

fitm <- lm(Z ~ X+Y) 
thdp$plane3d(fitm)

trdt <- scatterplot3d(X,Y,Z, pch = 19, color = "green4", main="3D Scatterplot")
trdt$plane3d(fitm)


require(lattice)

cloud(Z~X*Y,main="3D Scatterplot", pch = 18, col = "green4", scales = list(arrows = FALSE))