Scatterplot3d

Published onesixx on

help참조

 

#install.packages("scatterplot3d") 
library("scatterplot3d")

#################################################################
### Data
data(trees) 
str(trees); head(trees); summary(trees)

#################################################################
### Aesthetics, geometric objects
#1. scatterplot3d(x, y=NULL, z=NULL,...)
x <- trees$Girth
y <- trees$Height
z <- trees$Volume
scatterplot3d(x,y,z)

#2. scatterplot3d()  x is Matrix or dataframe
scatterplot3d(trees)

#3. scatterplot3d()  x is formula
attach(trees)
scatterplot3d(Volume ~ Girth+Height)
detach(trees)

###
# title & axis name
scatterplot3d(trees, main="title & axis name",
              xlab="Girth", ylab="Height", zlab="Volume")
# xlim, ylim, zlim
scatterplot3d(trees, main="xlim, ylim, zlim c(min,max)",
              xlim=c(10,20), ylim=c(70,80))
# grid & box, axis
scatterplot3d(trees, main="grid & box", sub="axis color",
              col.axis="blue", col.grid="red",
              grid=TRUE, box=FALSE)


# size of point
scatterplot3d(trees, main="size of point",
              pch = 16)
# color of point
scatterplot3d(trees, main="color of point",
              type="p", pch = 16, color="skyblue")
# type (p or h)
scatterplot3d(trees, main="type (p or h)",
              type="h", lwd=5, pch="", color=grey(31:1/40)) # 31 nrow(trees)
# angle
scatterplot3d(trees, main="angle",
              pch = 6, color="purple", angle = 66)


#################################################################
###Layer
attach(iris)
s3d1 <- scatterplot3d(iris[,1:3])
pchs0 <- c(16, 17, 18) 
pchs <- pchs0[as.numeric(Species)]
colors0 <- c("black", "green", "blue")
colors <- colors0[as.numeric(Species)]

s3d2 <- scatterplot3d(iris[,1:3], main="labels(text), legend",
                      pch=pchs, color=colors)
### legend
legend("bottom", legend=levels(iris$Species),
       pch=pchs0, col=colors0, 
       inset=-0.25, xpd=TRUE, horiz = TRUE)
# adding points
s3d2$points3d(seq(4,7,1.5), seq(4.5,2.5,-1), seq(2,6,2),
              col="red", type="h", pch=16)
### summary(s3d2)
# labels
text(s3d1$xyz.convert(iris[,1:3]), y=NULL, labels=rownames(iris),
     cex=0.7, pos=2, col="black")
# adding plane
my.lm <- lm(Petal.Length ~ Sepal.Length + Sepal.Width)
s3d2$plane3d(my.lm)
detach(iris)

 

Categories: Uncategorized

onesixx

Blog Owner

Leave a Reply

Your email address will not be published.