アニメーションを行いたい場合は、アニメーション パッケージ、またはtkexamp
TeachingDemos パッケージの関数を使用して作成された GUI のアニメーション コントロールがあります。color.scale.lines
plotrix パッケージを使用して、最後の数点を色のグラデーションでプロットすることにより、アニメーションを強化できます。
以下に例を示します。
library(TeachingDemos)
library(plotrix)
tmpfun <- function(start,numpoints=10) {
plot(ccc$Lon,ccc$Lat, xlab='Longitute', ylab='Lattitude', type='n')
to <- min(nrow(ccc), start+numpoints)
color.scale.lines( ccc$Lon[start:to], ccc$Lat[start:to],
c(0.7,0), c(0.7,0), c(0.7,0), colvar=seq_len(numpoints) )
}
tmplist <- list( numpoints=list('spinbox', init=10, from=1, to=nrow(ccc)),
start=list('animate',init=1, from=1, to=nrow(ccc)) )
tkexamp( tmpfun, tmplist )
時間を考慮した 2 番目の例を次に示します。
tmpfun2 <- function(start, dur=120) {
time <- as.numeric(h2h$Time3)
fr <- which( time >= start )[1]
if( is.na(fr) ) fr <- nrow(h2h)-1
to <- which( time >= start+dur )[1]
if( is.na(to) ) to <- nrow(h2h)
plot(h2h$Lon, h2h$Lat, xlab='Longitute', ylab='Lattitude',
type='n', main=paste('Times',time[fr],'to',time[to]) )
color.scale.lines( h2h$Lon[fr:to], h2h$Lat[fr:to],
c(0.7,0), c(0.7,0), c(0.7,0), colvar=time[fr:to])
}
tmplist2 <- list( dur=list('spinbox', init=120, from=10, to=1200),
start=list('animate',init=0, from=0, to=1780, delay=100,
resolution=10) )
tkexamp( tmpfun2, tmplist2 )
どちらの例でも色をいじってみると、より意味のある色のグラデーションが得られる場合があります。