- Toda anĆ”lise estatĆstica depende de boas estratĆ©gias para a visualizaĆ§Ć£o de dados;
- Formas ineficientes de visualizaĆ§Ć£o colaboram para inferĆŖncias incorretas;
- A aplicaƧnao de boas estratĆ©gias grĆ”ficas nĆ£o Ć© uma tarefa trivial.
MĆ©todo | funĆ§Ć£o (graphics) | no pacote (package) |
---|---|---|
3D scatterplot | cloud (lattice) | |
Matrix of scatterplots | pairs | splom (lattice) |
Bivariate density surface | persp | wireframe (lattice) |
Contour plot | contour, image contourLines, filled.contour | contourplot (lattice) , contour (MASS), levelplot (lattice) |
Parallel coord. plot | parallel (lattice), parallelplot (MASS) |
MĆ©todo | funĆ§Ć£o (graphics) | no pacote (package) |
---|---|---|
Star plot | stars | . |
Segment plot | stars | . |
Interactive 3D graphics | (rggobi), (rgl) |
data(iris) pairs(iris[101:150, 1:4])
panel.d <- function(x, ...) { usr <- par("usr") on.exit(par(usr)) par(usr = c(usr[1:2], 0, .5)) lines(density(x)) }
x <- scale(iris[101:150, 1:4]) r <- range(x) pairs(x, diag.panel = panel.d, xlim = r, ylim = r)
library(lattice) splom(iris[101:150, 1:4])
splom(iris[,1:4], groups = iris$Species)
splom(~iris[1:4], groups = Species, data = iris, col = 1, pch = c(1, 2, 3), cex = c(.5,.5,.5))
\[ f(x,y) = \frac{1}{2\pi}e^{-\frac{1}{2}(x^2 + y^2)} , (x,y) \in \Re^{2}\]
Define-se, entĆ£o a funĆ§Ć£o bivariada e determinam-se seus valores em um grid:
f <- function(x,y) { z <- (1/(2*pi)) * exp(-.5 * (x^2 + y^2)) } y <- x <- seq(-3, 3, length=50) z <- outer(x, y, f)
persp(x, y, z)
persp(x, y, z, theta=45, phi=30, expand=0.6, ltheta=120, shade=0.75, ticktype="detailed", xlab="X", ylab="Y", zlab=expression(f(x,y)))
GrĆ”ficos de superfĆcies podem ser feitos usando a funĆ§Ć£o wireframe (lattice)
O grĆ”fico a seguir mostra a distribuiĆ§Ć£o normal multivariada usando o wireframe
wireframe
library(lattice) wireframe(z)
cloud
produz grĆ”ficos de dispersĆ£o 3D;library(lattice) cloud(Petal.Length ~ Sepal.Length * Sepal.Width, data=iris, groups=Species)
cloud(Sepal.Length~Petal.Length*Petal.Width, data=iris, groups=Species, pch=1:3, zlab="SL", screen=list(z=30, x=-75, y=0))
countour(graphics)
e countorplot(lattice)
podem ser utilizadas para isso;volcano
como exemplo. Ele Ć© uma matriz de 87x61 contendo informaƧƵes topograficas do vulcĆ£o de Maunga Whau.contour(volcano, asp = 1, labcex = 1)
library(lattice) contourplot(volcano)
contour
;filledcontour
;levelplot
;image(volcano, col = terrain.colors(100), axes = FALSE) contour(volcano, levels = seq(100,200,by = 10), add = TRUE)
filled.contour(volcano, color = terrain.colors, asp = 1)
levelplot(volcano)
hexbin
possui uma implementaĆ§Ć£o que incorpora densidade dos dados em seus diagramas.x <- matrix(rnorm(2e6), nc=2) plot(x, xlab='Dim 1', ylab='Dim 2')
library(hexbin) plot(hexbin(x), xlab='Dim 1', ylab='Dim 2')
Se \(X_1, \dots, X_n \in R^d\), uma idĆ©ia de visualizaĆ§Ć£o em duas dimensƵes Ć© projetar cada vetor em uma funĆ§Ć£o real. As "Curvas de Andrews" mapeiam a observaĆ§Ć£o \(x_i = x_{i1}, \dots, x_{id}\) na funĆ§Ć£o:
\[ f_{i}(t) = \frac{x_{i1}}{\sqrt{2}} + x_{i2}\sin{t} + {x_{i3}}\cos{t} + {x_{i4}}\sin{2t} + {x_{i5}}\cos{2t} + \dots\]
\[ = \frac{x_{i1}}{\sqrt{2}} + \sum_{1 \leq k \leq d/2} x_{i,2k}\sin{kt} + \sum_{1 \leq k \leq d/2}x_{i,2k+1}\cos{kt} \]
\[ -\pi \leq t \leq \pi \]
Assim, cada observaĆ§Ć£o Ć© representada por sua projeĆ§Ć£o em um conjunto de funƧƵes base (ortogonais): \(\{ 2^{-1/2}, \{sin kt\}, \{cos kt\} \}\)
lefshape
no pacote DAAG
;library(DAAG) x <- with(leafshape17, cbind(bladelen, petiole, bladewid)) n <- nrow(x) mins <- apply(x, 2, min) maxs <- apply(x, 2, max) r <- maxs - mins y <- sweep(x, 2, mins) y <- sweep(y, 2, r, "/") x <- 2 * y - 1 a <- seq(-pi, pi, len=101) dim(a) <- length(a)
f <- function(a, v) { v[1]/sqrt(2) + v[2]*sin(a) + v[3]*cos(a) } plot(0, 0, xlim=c(-pi, pi), ylim=c(-3,3), xlab="t", ylab="Andrews Curves", main="", type="n") for (i in 1:n) { g <- leafshape17$arch[i] + 1 y <- apply(a, MARGIN = 1, FUN = f, v = x[i,]) lines(a, y, lty = g) } legend(3, c("Orthotropic", "Plagiotropic"), lty = 1:2)
parallelplot
no pacote lattice
;parcoord
no pacote MASS
.library(DAAG) library(MASS) x <- crabs[seq(5, 200, 5), ]
parcoord(x[4:8])
library(lattice) x <- crabs[seq(5, 200, 5), ] a <- x$CW * x$CL x[4:8] <- x[4:8] / sqrt(a)
parallelplot(~x[4:8] | sp*sex, x)
stars(graphics)
.library(MASS) x <- subset(crabs[seq(5, 200, 5), ], sex=='M') x[4:8] <- x[4:8] / sqrt(x$CW * x$CL) stars(x[4:8], draw.segments = TRUE, labels = as.character(x$sp))
CapĆtulo 4 - Maria Rizzo - Statistical Computing with R