[R] Animation problem

Tlellami cnoble at lgl.com
Thu Jun 14 20:12:27 CEST 2012


Using the animation package, I am trying to show fish movement over a jpeg of
our study area. I want to show fish detection at each of 5 sites on each day
they are detected. Each of the five fish species will have their own color
(not coded yet). I am able to create the animation, though the data is not
plotting correctly, and I feel that the problem lies with a loop that I
can't seem to figure out. I only want fish to "show" when they are detected,
which is provided in the "hits" column, where 1 = hit, 0 = no hit.

The data(tagdata) looks like this:

Day Tag Species Receiver    hits    x   y
1   1   xbow    10  1   105 350
1   2   cut 20  0   105 630
1   3   smilie  30  0   185 325
1   4   coho    40  0   280 250
1   5   mar 50  1   380 315
1   6   xbow    10  1   105 350
2   1   xbow    10  0   105 350
2   2   cut 20  1   105 630
2   3   smilie  30  1   185 325
2   4   coho    40  0   280 250
2   5   mar 50  0   380 315
3   1   xbow    10  0   105 350
3   2   cut 20  0   105 630
3   3   smilie  30  1   185 325
3   4   coho    40  1   280 250
3   5   mar 50  1   380 315

And my code:

saveHTML({
      nmax <- length(unique(tagdata$Day))
  # set the interval (secs) between panels
    oopt <- ani.options(interval = 1, nmax = nmax)
  # plot the jpeg 
  for( i in 1 : nmax){
    plot(BCan, xlim = c(50, 800), ylim = c(200, 700))
  # to keep the map (jpeg) from disappearing at each iteration
    par(new = TRUE)
  # Plot the bubbles
    symbols(tagdata$x[i], tagdata$y[i], circles = tagdata$hits[i], inches =
0.35, xlim = c(50, 800), ylim = c(200, 700), text = i)
    text(tagdata$x, tagdata$y, tagdata$Species)
    }
  },

  # save the file
    img.name = "Box.Canyon", htmlfile = "Box.Canyon.html", 
  # set the height and width of the animation, and save it in the working
directory
    ani.height = 500, ani.width = 600, outdir = getwd(),
    title = "Box Canyon fish movement animation",
    description = c("Attempt to show fish movement over the Box Canyon
map"))



--
View this message in context: http://r.789695.n4.nabble.com/Animation-problem-tp4633433.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list