Nearest neighbour distances and kernel estimation

60 views
Skip to first unread message

Michel Barbosa

unread,
Mar 9, 2009, 8:39:47 PM3/9/09
to ggplot2
Dear list,

I'd like to know if it's possible to use nearest neighbour distances
in combination with ggplot2? In spatstat, one is able to create so-
called Stienen diagrams (http://skitch.com/mbarbosa/b8q62/stienen-
diagram) in which the radius of the circle depicts the nearest
neighbour distance for that point. Is it possible to create such plots
or even additional plots using nearest neighbour distances?

Kind regards,

Michel

Michel Barbosa

unread,
Mar 9, 2009, 8:50:47 PM3/9/09
to ggplot2
I forgot to mention my question about Kernel Density Estimation. I've
used the point geom to create a kernel density surface using the
following code:

myplot <- myplot + stat_density2d(geom="point", aes(x = lng, y = lat,
size = ..density.., colour = ..density..), contour = FALSE)

The kernel density estimation surface lets me analyse the density/
intensity of restaurants. However, now I'd like to create a smoothed
surface of the values of the ratings of my restaurants. I'd like to
generate a plot such as http://skitch.com/mbarbosa/b8q9q/smoothing .

Is this possible with ggplot2 as well?

Kind regards,

Michel

jiho

unread,
Mar 9, 2009, 9:55:04 PM3/9/09
to Michel Barbosa, ggplot2
On 2009-March-09 , at 20:50 , Michel Barbosa wrote:

> Is this possible with ggplot2 as well?


you need to do the interpolation separately and then feed the data to
geom_tile.

I might be wrong, and Hadley will correct me, but ggplot is a
*plotting* package. This means, for me at least, that most computation
is done beforehand and that ggplot comes into play once you have a
data.frame filled with the data you want to represent. Even though
some statistical functions, such as smoothing, contouring,
manipulating scales etc. are directly available, ggplot is not a do-it-
all package in which you would feed the raw data and which would
output the graphics. So basically, I would recommend to use spastat
(or other interpolation packages: kriging, akima etc.) to compute
whatever you need, put that in a data.frame, and then start thinking
about ggplot.

From that point on, the manual and the website should allow you to
find the appropriate function easily (geom_tile is quite obvious in
the documentation).

JiHO
---
http://jo.irisson.free.fr/

hadley wickham

unread,
Mar 9, 2009, 10:30:12 PM3/9/09
to jiho, Michel Barbosa, ggplot2
On Mon, Mar 9, 2009 at 7:55 PM, jiho <jo.ir...@gmail.com> wrote:
>
> On 2009-March-09  , at 20:50 , Michel Barbosa wrote:
>
>> Is this possible with ggplot2 as well?
>
>
> you need to do the interpolation separately and then feed the data to
> geom_tile.
>
> I might be wrong, and Hadley will correct me, but ggplot is a
> *plotting* package. This means, for me at least, that most computation
> is done beforehand and that ggplot comes into play once you have a
> data.frame filled with the data you want to represent. Even though
> some statistical functions, such as smoothing, contouring,
> manipulating scales etc. are directly available, ggplot is not a do-it-
> all package in which you would feed the raw data and which would
> output the graphics. So basically, I would recommend to use spastat
> (or other interpolation packages: kriging, akima etc.) to compute
> whatever you need, put that in a data.frame, and then start thinking
> about ggplot.

Yes, that's exactly right :)

Hadley

--
http://had.co.nz/

Michel Barbosa

unread,
Mar 10, 2009, 6:03:54 PM3/10/09
to ggplot2
Dear JIHO, Hadley,

thanks for the clear answer. I now understand that I should look into
the various R packages and somehow generate a dataframe suitable for
(further) plotting with ggplot2. I'll have a look at spatstat
functions and how to generate dataframes as well as other packages.

Kind regards,

Michel

On 10 mrt, 03:30, hadley wickham <h.wick...@gmail.com> wrote:
Reply all
Reply to author
Forward
0 new messages