Dear R gurus and users, I seem to have problem finding the right tool for plotting convex hulls over 2D plots, after a cluster analysis. In fact I would like to draw a convex hull in 2D for a generic group of points. I found a "convhulln", but this doesn't seem to give me a convex hull. Here is what I do:> library(mvtnorm) > Mean <- c(2,1) > Sigma <- matrix(c(1,0,0,1),ncol=2) > Y <- rmvnorm(n=100,mean=Mean,sigma=Sigma) > hull <- convhulln(Y) > hull[,1] [,2] [1,] 16 26 [2,] 16 4 [3,] 87 47 [4,] 87 4 [5,] 21 26 [6,] 21 94 [7,] 54 47 [8,] 54 75 [9,] 23 94 [10,] 23 75 I was expecting hull to give me a few 2D points that would enclose the 100 random points generated, but this doen't seem to be the case. Probably I'm using the wrong tool here. Any help with this would be greatly appreciated. Thank you. J Dr James Foadi PhD Membrane Protein Laboratory (MPL) Diamond Light Source Ltd Diamond House Harewell Science and Innovation Campus Chilton, Didcot Oxfordshire OX11 0DE Email : james.foadi at diamond.ac.uk Alt Email: j.foadi at imperial.ac.uk -- This e-mail and any attachments may contain confidential...{{dropped:8}}
Try this: plot(Y) polygon(Y[chull(Y),]) On Tue, Nov 24, 2009 at 1:58 PM, <james.foadi at diamond.ac.uk> wrote:> Dear R gurus and users, > I seem to have problem finding the right tool for plotting convex hulls over > 2D plots, after a cluster analysis. In fact I would like to draw a convex hull > in 2D for a generic group of points. I found a "convhulln", but this doesn't seem > to give me a convex hull. Here is what I do: > > >> library(mvtnorm) >> Mean <- c(2,1) >> Sigma <- matrix(c(1,0,0,1),ncol=2) >> Y <- rmvnorm(n=100,mean=Mean,sigma=Sigma) >> hull <- convhulln(Y) >> hull > ? ? ?[,1] [,2] > ?[1,] ? 16 ? 26 > ?[2,] ? 16 ? ?4 > ?[3,] ? 87 ? 47 > ?[4,] ? 87 ? ?4 > ?[5,] ? 21 ? 26 > ?[6,] ? 21 ? 94 > ?[7,] ? 54 ? 47 > ?[8,] ? 54 ? 75 > ?[9,] ? 23 ? 94 > [10,] ? 23 ? 75 > > > I was expecting hull to give me a few 2D points that would enclose the 100 random points generated, > but this doen't seem to be the case. > > Probably I'm using the wrong tool here. > Any help with this would be greatly appreciated. Thank you. > > J > > Dr James Foadi PhD > Membrane Protein Laboratory (MPL) > Diamond Light Source Ltd > Diamond House > Harewell Science and Innovation Campus > Chilton, Didcot > Oxfordshire OX11 0DE > > Email ? ?: ?james.foadi at diamond.ac.uk > Alt Email: ?j.foadi at imperial.ac.uk > > > -- > This e-mail and any attachments may contain confidential...{{dropped:8}} > > ______________________________________________ > R-help at r-project.org mailing list > stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. >-- Henrique Dallazuanna Curitiba-Paran?-Brasil 25? 25' 40" S 49? 16' 22" O
-----Original Message----- From: Henrique Dallazuanna [mailto:wwwhsd at gmail.com] Sent: Tue 24/11/2009 16:10 To: Foadi, James (Imperial Coll.,RAL,DIA) Cc: r-help at r-project.org Subject: Re: [R] convex hull for cluster analysis Try this: plot(Y) polygon(Y[chull(Y),]) Yes! Lovely! Thanks. J Dr James Foadi PhD Membrane Protein Laboratory (MPL) Diamond Light Source Ltd Diamond House Harewell Science and Innovation Campus Chilton, Didcot Oxfordshire OX11 0DE Email : james.foadi at diamond.ac.uk Alt Email: j.foadi at imperial.ac.uk -- This e-mail and any attachments may contain confidential...{{dropped:8}}