plot3dProj | R Documentation |
TODO
plot3dProj(x, col = NULL,
cls = NULL, size = 3,
alpha = 1, main = NULL,
x2 = NULL, col2 = NULL,
cls2 = NULL, size2 = 3,
alpha2 = 1, main2 = NULL,
x3 = NULL, col3 = NULL,
cls3 = NULL, size3 = 3,
alpha3 = 1, main3 = NULL,
palette = c("black",
"red", "green",
"blue"), scale = TRUE,
tx = function(y) y,
dimToShow = NULL,
k = NULL, type = "sawm,fw",
widths = 1, heights = 1,
devices = rgl.cur(),
col.axes = "gray",
axesExpansion = 1.1,
annotateWireFrame = FALSE,
ellipses = list(list(center = rep(0,
ncol(x)), x = diag(rep(1,
ncol(x))), col = "gray",
alpha = 0.2)),
boxes = list(list(center = rep(0,
ncol(x)), scale = rep(0,
ncol(x)), col = "gray",
alpha = 0.2)),
wfboxes = list(list(center = rep(0,
ncol(x)), scale = rep(0,
ncol(x)), col = "gray",
alpha = 0.2)),
planes = list(list(a = 1,
b = 0, c = 0,
d = 0, col = "gray",
alpha = 0.2)),
texts = list(list(center = rep(0,
ncol(x)), text = "text",
col = "gray",
alpha = 0.2)),
debug = FALSE)
x |
a data frame or matrix to visualize. Instances in rows, features in columns. It must have at least 3 columns (dimensions). |
col |
the color of individual instances color of individual instances, recycled if necessary |
cls |
class membership of individual instances. This serves the only purpose of alternative color specification: if 'col' is NULL ... |
size |
|
alpha |
|
main |
title of |
x2 |
another data frame or matrix to visualize. |
col2 |
the color of data in |
cls2 |
class membership of data in |
size2 |
|
alpha2 |
|
main2 |
title of |
x3 |
another data frame or matrix to visualize. |
col3 |
the color of data in |
cls3 |
class membership of data in |
size3 |
|
alpha3 |
|
main3 |
title of |
palette |
color |
scale |
if TRUE, data get scaled to the range of '[-1, 1]' in all dimensions |
tx |
Transform function used to transform data from
the k-dimensional space of |
dimToShow |
a numeric or character vector of dimensions
of |
k |
if |
type |
a character string defining the
Each of |
widths |
relative |
heights |
relative |
devices |
a list of |
col.axes |
color of axes in the 3D plot |
axesExpansion |
|
annotateWireFrame |
if |
ellipses |
a
list or a list of lists defining |
boxes |
a
list or a list of lists defining |
wfboxes |
a
list or a list of lists defining wire frame |
planes |
a
list or a list of lists defining |
texts |
a
list or a list of lists defining |
debug |
if TRUE, debugs will be printed. If numeric of value greater than 1, verbose debugs will be produced. |
a list of rgl device IDs holding the scenes plotted
Tomas Sieger
if (interactive() && require(rgl)) {
# Plot a 3D scatter plot and 2D scatter plots as
# faces of a parallelepipedon:
plot3dProj(iris[,1:3], cls=iris$Species)
# Plot 4D data in a 3D scatter plot on a new device,
# use PCA to go from 4D to 3D, and add a bounding box and 3D axes
# decoration (\code{type='d'}) on top of the axes of the 4D space
# (\code{type='a'}).
plot3dProj(iris[,1:4], cls=iris$Species, tx=txPca(iris[,1:4]), type='sad', devices=NULL)
# Plot the iris data set with additional decoration: ellipses
# representing individual species of the flowers, a box and a text
# in the center, and a plane.
iris.setosa<-iris[iris$Species=='setosa',1:3]
iris.versicolor<-iris[iris$Species=='versicolor',1:3]
iris.virginica<-iris[iris$Species=='virginica',1:3]
plot3dProj(iris[,1:3], col=c('red','green','blue')[as.numeric(iris$Species)],
type='sdpbet', # scatter plot with decoration, a plane, a box,
# elippses and a text
ellipse=list(
list(cov(iris.setosa),center=colMeans(iris.setosa),col='red',alpha=.1),
list(cov(iris.versicolor),center=colMeans(iris.versicolor),col='green',alpha=.1),
list(cov(iris.virginica),center=colMeans(iris.virginica),col='blue',alpha=.1)),
box=list(center=colMeans(iris[,1:3]),scale=c(.3,.3,.3),col='black',alpha=.2),
planes=list(0,0,1,-2.5,col='yellow',alpha=.2),
texts=list(colMeans(iris[,1:3]),text='center',col='black'),
devices=NULL)
# Plot two data sets: all Iris flowers (on the left side) and
# Setosa and Versicolor species only (on the right side).
# In both cases, produce 2D and 3D spatter plots.
# For the second data set, alter the size and the alpha value
# of Setosa flowers. Also, plot small axes under the scatter plots.
plot3dProj(x = iris[, 1:3], cls = iris$Species,
main = 'Setosa, Versicolor and Virginica',
x2 = iris[iris$Species != 'virginica', 1:3],
cls2 = iris$Species[iris$Species != 'virginica'],
alpha2 = c(1,.3)[1+(iris$Species[iris$Species != 'virginica']=='setosa')],
size2 = c(3,10)[1+(iris$Species[iris$Species != 'virginica']=='setosa')],
main2 = 'Setosa and Versicolor',
ty='fw,swm,s2m2d,f2;,a',heights=c(2,1),
devices=NULL) # devices=NULL opens a new 'rgl' device
}
# TODO: unify/propagate scaling done in plot3dProj here ?!
# p <- prcomp(iris[, 1:4], center = TRUE, scale = TRUE)
# tx <- function (y,center=TRUE) {
# if(center) y<-y-matrix(colMeans(iris[, 1:4]),nrow=nrow(y),ncol=4,byrow=TRUE)
# y<-t(t(p$rotation[,1:3])%*%t(y))
# return (y)
# }
# plot3dProj(iris[,1:4], tx=tx, cls=iris$Species)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.