useR-Blejec-animatoR
-
Upload
andrej-blejec -
Category
Documents
-
view
218 -
download
3
description
Transcript of useR-Blejec-animatoR
![Page 1: useR-Blejec-animatoR](https://reader031.fdocuments.in/reader031/viewer/2022020221/568c4e0a1a28ab4916a65563/html5/thumbnails/1.jpg)
animatoR
dynamic graphics in R
National Institute of BiologyLjubljana, Slovenia
useR! 2011
A. Blejec [email protected] (NIB) animatoR useR! 2011 1 / 35
![Page 2: useR-Blejec-animatoR](https://reader031.fdocuments.in/reader031/viewer/2022020221/568c4e0a1a28ab4916a65563/html5/thumbnails/2.jpg)
Outline
1 Introduction
2 Homotopy
3 animatoR functions
4 Examples
5 Advanced examplesFireworksScatterplotQuantilesMatricesDistributionsJoint and marginal distribution
A. Blejec [email protected] (NIB) animatoR useR! 2011 2 / 35
![Page 3: useR-Blejec-animatoR](https://reader031.fdocuments.in/reader031/viewer/2022020221/568c4e0a1a28ab4916a65563/html5/thumbnails/3.jpg)
Animation solutions for R :
the main idea is: plot frame by frame
package animation provides an organized environment for subsequentplotting, see AniWiki
A. Blejec [email protected] (NIB) animatoR useR! 2011 3 / 35
![Page 4: useR-Blejec-animatoR](https://reader031.fdocuments.in/reader031/viewer/2022020221/568c4e0a1a28ab4916a65563/html5/thumbnails/4.jpg)
Drawbacks
plotting everything can be slow for complex figures
smooth movements require intermediate plots, thus lot of frames toplot
A. Blejec [email protected] (NIB) animatoR useR! 2011 4 / 35
![Page 11: useR-Blejec-animatoR](https://reader031.fdocuments.in/reader031/viewer/2022020221/568c4e0a1a28ab4916a65563/html5/thumbnails/11.jpg)
Moving a point, line traces the movement.
A. Blejec [email protected] (NIB) animatoR useR! 2011 6 / 35
![Page 12: useR-Blejec-animatoR](https://reader031.fdocuments.in/reader031/viewer/2022020221/568c4e0a1a28ab4916a65563/html5/thumbnails/12.jpg)
Moving a point ...t = 0
●
t = 0.33
●
t = 0.67
●
t = 1
●
A. Blejec [email protected] (NIB) animatoR useR! 2011 7 / 35
![Page 13: useR-Blejec-animatoR](https://reader031.fdocuments.in/reader031/viewer/2022020221/568c4e0a1a28ab4916a65563/html5/thumbnails/13.jpg)
Linear homotopy
Start coordinate x0End coordinate x1
For parameter t ∈ [0, 1]
xt = h(x0, x1, t) = (1− t) · x0 + t · x1
A. Blejec [email protected] (NIB) animatoR useR! 2011 8 / 35
![Page 14: useR-Blejec-animatoR](https://reader031.fdocuments.in/reader031/viewer/2022020221/568c4e0a1a28ab4916a65563/html5/thumbnails/14.jpg)
Linear homotopywhen: start, end, enter, exit ... life
0 , 1
t
h
0.0 0.2 0.4 0.6 0.8 1.0
x0
x1
●●●●●●●●
●●●●●●●●
●●●●●●●●
●●●●●●●●
●●●●●●●●
●●●●●●●●
●●●●●●●●
●●●●●●●●
●●●●●●●●
●●●●●●●●
●●●●●●●●
●●●●●●●●
●●●●●
0.3 , 0.7
t
h
0.0 0.2 0.4 0.6 0.8 1.0
x0
x1
●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●
0.3 , 0.7 , 0.1 , 0.9
t
h
0.0 0.2 0.4 0.6 0.8 1.0
x0
x1
●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●
0.4 , 0.6 , 0.1 , 0.9
t
h
0.0 0.2 0.4 0.6 0.8 1.0
x0
x1
●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●
A. Blejec [email protected] (NIB) animatoR useR! 2011 9 / 35
![Page 15: useR-Blejec-animatoR](https://reader031.fdocuments.in/reader031/viewer/2022020221/568c4e0a1a28ab4916a65563/html5/thumbnails/15.jpg)
Moving pointstpoints()
> for (t in seq(0, 1, length = 100)) {+ newplot(stamp = TRUE)+ tpoints(2, 2, 9, 5, t, pch = 16, cex = 2,+ trace = TRUE)+ }
A. Blejec [email protected] (NIB) animatoR useR! 2011 10 / 35
![Page 16: useR-Blejec-animatoR](https://reader031.fdocuments.in/reader031/viewer/2022020221/568c4e0a1a28ab4916a65563/html5/thumbnails/16.jpg)
Timed functions
tpoints (x0, y0, x1 = x0, y1 = y0, t, when, trace = FALSE, trace.col = "grey", ...)
tlines (x0, y0, x1, y1, t, when, ...)
tsegments (x0, y0, x1, y1, t, when, fixed = 1, ...)
tarrows (x0, y0, x1, y1, t, when, fixed = 1, length = 0.125, ...)
tpolygon (x0, y0, x1, y1, t, when, ...)
trect (xleft0, ybottom0, xright0, ytop0, xleft1, ybottom1, xright1, ytop1, t, when, ...)
ttext (x0, y0, x1 = x0, y1 = y0, t, when, text = "", ...)
A. Blejec [email protected] (NIB) animatoR useR! 2011 11 / 35
![Page 17: useR-Blejec-animatoR](https://reader031.fdocuments.in/reader031/viewer/2022020221/568c4e0a1a28ab4916a65563/html5/thumbnails/17.jpg)
Timed parameters ...
tcex (cex0 = 1, cex1 = 1, t, when, ...)
trgb (x0, x1 = x0, t, when = c(0, 1), alpha0 = 1, alpha1 = 1, ...)
tmatrix (X1, X0 = diag(nrow(X1)), t, when, ...)
A. Blejec [email protected] (NIB) animatoR useR! 2011 12 / 35
![Page 18: useR-Blejec-animatoR](https://reader031.fdocuments.in/reader031/viewer/2022020221/568c4e0a1a28ab4916a65563/html5/thumbnails/18.jpg)
Function animator()
animator (block, life = 1, fps = 25, pause = 0.5, verbose = FALSE)
Accepts argument block as a character string
animator('newplot()tpoints(2,2,9,5,trace=TRUE,pch=16,cex=2)
')
A. Blejec [email protected] (NIB) animatoR useR! 2011 13 / 35
![Page 19: useR-Blejec-animatoR](https://reader031.fdocuments.in/reader031/viewer/2022020221/568c4e0a1a28ab4916a65563/html5/thumbnails/19.jpg)
Function animator()
Argument block as an expression
> block <- expression({+ newplot()+ tpoints(2, 2, 9, 5, trace = TRUE, pch = 16,+ cex = 2)+ })> animator(block)
A. Blejec [email protected] (NIB) animatoR useR! 2011 14 / 35
![Page 20: useR-Blejec-animatoR](https://reader031.fdocuments.in/reader031/viewer/2022020221/568c4e0a1a28ab4916a65563/html5/thumbnails/20.jpg)
Class animator
A block of commands (expression or character version) can be changed toa class animator
> x <- as.animator(block, life = 2)> x
expression({newplot()tpoints(2, 2, 9, 5, trace = TRUE, pch = 16, cex = 2)
})attr(,"class")[1] "animator"attr(,"life")[1] 2
> is.animator(x)
[1] TRUE
> plot(x)
A. Blejec [email protected] (NIB) animatoR useR! 2011 15 / 35
![Page 21: useR-Blejec-animatoR](https://reader031.fdocuments.in/reader031/viewer/2022020221/568c4e0a1a28ab4916a65563/html5/thumbnails/21.jpg)
Animated graphics in a PDF fileuse package animate in LaTeX
> plot(as.animator(block))> includeLatex(vspace = "-2cm")
A. Blejec [email protected] (NIB) animatoR useR! 2011 16 / 35
![Page 29: useR-Blejec-animatoR](https://reader031.fdocuments.in/reader031/viewer/2022020221/568c4e0a1a28ab4916a65563/html5/thumbnails/29.jpg)
Projection to the first principal component
A. Blejec [email protected] (NIB) animatoR useR! 2011 24 / 35
![Page 30: useR-Blejec-animatoR](https://reader031.fdocuments.in/reader031/viewer/2022020221/568c4e0a1a28ab4916a65563/html5/thumbnails/30.jpg)
Move points to median (0.0, 0.3)then expand to mid-quintiles (0.6, 1.0)
A. Blejec [email protected] (NIB) animatoR useR! 2011 25 / 35
![Page 33: useR-Blejec-animatoR](https://reader031.fdocuments.in/reader031/viewer/2022020221/568c4e0a1a28ab4916a65563/html5/thumbnails/33.jpg)
Matrix multiplication: change of direction and magnitude
A. Blejec [email protected] (NIB) animatoR useR! 2011 28 / 35
![Page 34: useR-Blejec-animatoR](https://reader031.fdocuments.in/reader031/viewer/2022020221/568c4e0a1a28ab4916a65563/html5/thumbnails/34.jpg)
Matrix multiplication: find the eigenvectors
A. Blejec [email protected] (NIB) animatoR useR! 2011 29 / 35
![Page 37: useR-Blejec-animatoR](https://reader031.fdocuments.in/reader031/viewer/2022020221/568c4e0a1a28ab4916a65563/html5/thumbnails/37.jpg)
From bivariate distribution to marginal distributions
A. Blejec [email protected] (NIB) animatoR useR! 2011 32 / 35
![Page 38: useR-Blejec-animatoR](https://reader031.fdocuments.in/reader031/viewer/2022020221/568c4e0a1a28ab4916a65563/html5/thumbnails/38.jpg)
From marginal distributions to bivariate ?
A. Blejec [email protected] (NIB) animatoR useR! 2011 33 / 35
![Page 39: useR-Blejec-animatoR](https://reader031.fdocuments.in/reader031/viewer/2022020221/568c4e0a1a28ab4916a65563/html5/thumbnails/39.jpg)
From marginal distributions to bivariate ?
A. Blejec [email protected] (NIB) animatoR useR! 2011 34 / 35
![Page 40: useR-Blejec-animatoR](https://reader031.fdocuments.in/reader031/viewer/2022020221/568c4e0a1a28ab4916a65563/html5/thumbnails/40.jpg)
From marginal distributions to bivariate ?
A. Blejec [email protected] (NIB) animatoR useR! 2011 35 / 35