data(flea)
flea_std <- apply(flea[,1:6], 2, function(x) (x-mean(x))/sd(x))
t1 <- save_history(flea_std, max=2)
t1i <- tourr::interpolate(t1, 0.1)
p <- render_anim(data=flea_std, frames=t1i)
if (require(ggplot2)) {
pg <- ggplot() +
geom_path(data=p$circle, aes(x=c1, y=c2, frame=frame)) +
geom_segment(data=p$axes, aes(x=x1, y=y1, xend=x2, yend=y2, frame=frame)) +
geom_text(data=p$axes, aes(x=x2, y=y2, frame=frame, label=axis_labels)) +
geom_point(data=p$frames, aes(x=P1, y=P2, frame=frame, label=obs_labels)) +
coord_equal() +
theme_bw() +
theme(axis.text=element_blank(),
axis.title=element_blank(),
axis.ticks=element_blank(),
panel.grid=element_blank())
if (interactive()) {
require(plotly)
ggplotly(pg, width=500, height=500) |>
animation_button(label="Go") |>
animation_slider(len=0.8, x=0.5, xanchor="center") |>
animation_opts(easing="linear", transition=0, redraw=FALSE)
}
}
Run the code above in your browser using DataLab