#set larger 'interval' if the speed is too fast 
x = matrix(runif(200), ncol = 2)
kmeans.ani(x = x, centers = 2, interval = 0.5) 
# create HTML animation page 
op = par(mar = c(2, 2, 3, 1), cex.axis = 0.75, cex.main = 1)
ani.start() 
kmeans.ani(saveANI = TRUE, x = x, centers = 3, interval = 1,
    width = 600, height = 600) 
ani.stop()
par(op)Run the code above in your browser using DataLab