[R] Plot 3d density

Maximilian Lklweryc maxlklweryc at gmail.com
Wed Nov 28 17:06:52 CET 2012


I want to create a 3d plot with densities.

I use the function density to first create a 2d dimensional plot for
specific x values, the function then creates the density and puts them
into a y variable. Now I have a second set of x values and put it
again into the density function and I get a second set of y variables
and so on.... I want to put those sets into a 3d plot, I hope you know
what I mean. So I have a surface of densities....

E.g. I have:

x1<-c(1:10)
x2<-c(2:11)
y1<-c(1,1,2,1,3,4,2,3,2,2)
y2<-c(1,2,3,1,3,6,2,8,2,2)
.
.
.
.

Now I want to put on the x axis for the value 1 the first set that
means for x=1 on the y axis of the 3d plot the x values from the first
set and on the z axis the densities. So I have a "disk" for x=1, for
x=2 I have the second "disk" and so on, so I get a density "mountain".

I hope I am understandable, if you have a better idea to realize it
then you are welcome! I want to do it with the persp function, would
be nice if you make an example with that function,

The function kde2d does not help.

Thanks a lot for your help.



More information about the R-help mailing list