[R] density plot - beginner's question
Deepayan Sarkar
deepayan at stat.wisc.edu
Tue Jan 14 07:16:04 CET 2003
On Monday 13 January 2003 05:22 pm, Saurav Pathak wrote:
> Hi,
>
> I am trying to plot densities given on a two dimensional grid. My
> data is in the an external file, and is arranged in three columns:
> x, y, density
>
> how may i get a plot of this? i would like to get (1) a three
> dimensional plot and (2) a color coded two dimensional plot.
persp() for (1) and image() or filled.contour() for (2). Both need the density
in the form of a matrix, as described in their respective help pages.
Alternately, you could you the 3D functions in the lattice package:
library(lattice)
levelplot(density ~ x * y)
for (2).
wireframe(density ~ x * y)
will give you something similar to persp(), but it will be much slower.
>
> I have tried using
>
> image(x, y, density)
>
> but i am asked to put the data in ascending order. i am not sure
> how i may put grid points in an ascending order.
>
> I would also like to know if i could use any other function, other
> than image.
>
> thank you in advance.
More information about the R-help
mailing list