Dear all.

 

Possibly some of you will remember me asking about producing 3d density
plots of 100 particles moving randomly over 100 time steps. Thank you
for your help.

 

I went with the suggestion by Thierry Onkelin

Of using 

 

Positions <- expand.grid(Run = seq_len(100), ID = seq_len(101))
Positions$X <- runif(nrow(Positions), -.5, .5) Positions$Y <-
runif(nrow(Positions), -.5, .5) Positions[Positions$ID == 1, c("X",
"Y")] <- Positions[Positions$ID == 1, c("X", "Y")] + matrix(c(50, 40),
ncol = 2, nrow = 100, byrow = TRUE)

library(plyr)

Positions <- ddply(Positions, "Run", function(x){

      x <- x[order(x$ID), ]

      x$X <- cumsum(x$X)

      x$Y <- cumsum(x$Y)

      x

})

library(ggplot2)

ggplot(Positions, aes(x = X, y = Y)) + geom_density2d()

 

Instead of releasing 100 particles at t=1, I would like to release

10 at t=1 tracked for 100 time steps

20 at t=2 tracked for 99 time steps

30 at t=3 tracked for 98  time steps

40 at t=4 tracked for 97 time steps

            And then produce a density contour plot of the this

 

 

so  I am guessing I would need to loop a matrix, but what format is used
for this.

 

I am really not proficient and quite ignorant in the ways of R and can
just about loop a function, I have tried to use the same process for a
matrix, but this will not work.

 

I hope that is understandable, Any ideas?

 

Thanks and regards 

 

 

 


	[[alternative HTML version deleted]]

