I have a set of points on a plane. They are partitioned into subsets. I want to plot a closed curve around points that belong to the same subset, so that points that belong to a subset will be inside the curve, and those that aren't will be outside. Therefore simple circles, or a convex hull might not work.
For a starter, let's say I just want to have a smooth curve around a set of point (without the requirement that it excludes other points)
Any ideas how to do that in R?
---added later---
What I'm looking eventually, is something in the spirit of the graphics in here: https://tex.stackexchange.com/questions/1175/drawing-a-hypergraph - although the context is not a hypergraph, but rather a given set of points and a partition of those.
Okay, here's a version of an answer that I think gets close to what you are chasing: It uses the
spline.poly
function created over at this answer ( https://gis.stackexchange.com/a/24929 ) on the GIS forum.Here's some example points:
Set up a basic plot
And the result:
EDIT TO ADD A CONCAVE EXAMPLE
This part of the answer uses the
alphahull
libraryGenerate and plot the ahull object - the alpha value seems to be very important in determining the fit of the polygon to the data.
And the result:
After some googling, I little modify this example Morota ggplot2
EDIT
It uses the chull function with bezier
Simply:
Plot:
the plot
The
ggalt
package providesgeom_encircle
, which is supposed to provide something like this - convex, but smooth: