Dear all. 

 

I am new to R so I am probably asking something that will be sneered at.


 

I am moving 100 "particles" in both x,y dimensions and would like to
plot the density of particles at each Cartesian coordinate. 

 

I can simply use: 

 

plot(density(positionX)

plot(density(positionY)

 

to produce the relevant density of particles at either an X or a Y
point, however how would it be possible to overlay the densities so that
I obtain a density at a particular coordinate.

 

An mock example of what I am currently doing is 

 

posX    <- matrix (nrow=101,ncol=100,data=0)

posY     <- matrix (nrow=101,ncol=100,data=0)

 

posX[1,]<-50

posY[1,]<-40

 

for (j in 1:100) {

posX[j+1,]<- posX[j,]+(runif(100)-0.5)

posY[j+1,]<- posY[j,]+(runif(100)-0.5)

 

}

 

matplot(posX,posY,type="l")

plot(density((posY[,j])))

plot(density((posX[,j])))

 

Simply I would like to know the density of particles at coordinates of
the matplot.

>From the example given the density of particles at 50,40 will be higher
than at the edges. But to quantifiably see this would be an advantage.

 

 

Any help?

 

I hope that is understandable.

 

Many thanks 


	[[alternative HTML version deleted]]

