[R-sig-eco] 3d density plot

Kingsford Jones kingsfordjones at gmail.com
Sat Jun 20 00:05:21 CEST 2009


Hi Nabeil,

I'm not sure I understand what you'd like to accomplish, but perhaps
the following will be helpful:

example(kde2d, package='MASS')


hth,

Kingsford Jones


On Fri, Jun 19, 2009 at 10:32 AM, Nabeil Salama<N.Salama at marlab.ac.uk> wrote:
> 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]]
>
> _______________________________________________
> R-sig-ecology mailing list
> R-sig-ecology at r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-sig-ecology
>



More information about the R-sig-ecology mailing list