Brownian motion, or random walk, can be regarded as the trace of some cumulative normal random numbers.

1 |

`n` |
Number of points in the scatterplot |

`xlim, ylim` |
Arguments passed to |

`...` |
other arguments passed to |

The location of the next step is “current location + random Gaussian numbers”, i.e.,

*x[k + 1] = x[k] + rnorm(1)*

*y[k + 1] = y[k] + rnorm(1)*

where *(x, y)* stands for the location of a point.

None (invisible `NULL`

).

The maximum number of steps in the motion is specified in
`ani.options('nmax')`

.

Yihui Xie

http://vis.supstat.com/2012/11/brownian-motion-with-r

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | ```
oopt = ani.options(interval = 0.05, nmax = ifelse(interactive(),
150, 2))
brownian.motion(pch = 21, cex = 5, col = "red", bg = "yellow",
main = "Demonstration of Brownian Motion")
ani.options(oopt)
## create an HTML animation page
saveHTML({
par(mar = c(3, 3, 1, 0.5), mgp = c(2, 0.5, 0), tcl = -0.3,
cex.axis = 0.8, cex.lab = 0.8, cex.main = 1)
ani.options(interval = 0.05, nmax = ifelse(interactive(),
150, 10))
brownian.motion(pch = 21, cex = 5, col = "red", bg = "yellow")
}, description = c("Random walk on the 2D plane: for each point",
"(x, y), x = x + rnorm(1) and y = y + rnorm(1)."),
title = "Demonstration of Brownian Motion")
ani.options(oopt)
``` |

Questions? Problems? Suggestions? Tweet to @rdrrHQ or email at ian@mutexlabs.com.

Please suggest features or report bugs with the GitHub issue tracker.

All documentation is copyright its authors; we didn't write any of that.