Created
May 12, 2015 18:06
-
-
Save amoeba/e425d84fef96de7a9bbb to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # animation-2.r | |
| # author: Bryce Mecum ([email protected]) | |
| # | |
| # Animations in R Tutorial | |
| # Part 2 of 6 | |
| # | |
| # Extend part 1 by plotting a random (uniform) walk starting in the bottom | |
| # right-hand corner and moving North and West. | |
| library(maps) | |
| xrange <- 180:240 | |
| yrange <- 45:70 | |
| ndays <- 30 | |
| jump_distance_x <- 1 | |
| jump_distance_y <- 1 | |
| positions <- data.frame(day = 1:ndays, x = c(225, rep(NA, ndays - 1)), y = c(50, rep(NA, ndays - 1))) | |
| positions | |
| for(i in 2:ndays) | |
| { | |
| positions[i,"x"] <- positions[i - 1,"x"] + runif(1, -jump_distance_x, 0) | |
| positions[i,"y"] <- positions[i - 1,"y"] + runif(1, 0, jump_distance_y) | |
| } | |
| positions | |
| map('world2', xlim = range(xrange), ylim = range(yrange)) | |
| map.axes() | |
| points(y ~ x, | |
| data = positions, | |
| cex = 1, | |
| col = "red", | |
| pch = 19) | |
| lines(y ~ x, data = positions) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment