[R] Convex hull line coordinates..

Gabor Grothendieck ggrothendieck at myway.com
Mon Mar 21 21:26:02 CET 2005


 <achilleas.psomas <at> wsl.ch> writes:

: 
: Hello R-Helpers..
: 
: I am still new in R and I have the following question..
: I am applying the function chull on a 2D dataset and have the convex hull
: nicely
: calculated and plotted.
: Do you know if there is a way to extract the coordinates of the line created
: from the connection of the chull data points..
: I have alredy tried with "approx" to lineary interpolate but its not working
: correctly since the interpolated values sometimes fall inside the convex .
: Using the "yleft" or "yright" doesnt seem to help..
: 
: Any suggestions?

1. First suggestion is not to post by following up on an unrelated thread
since some people won't see it.   e.g. try finding it on gmane.  Its there
but good luck on finding it.

2. Second suggestion is an example which creates a matrix z whose 
columns are the regression coefficients of the successive line 
segments.  Note use of lm's subset= arg to simplify code:

example(chull)  # creates hpts and X and plots convex hull
z <- sapply(2:length(hpts), function(i)
	coef(lm(X[,2] ~ X[,1], subset = hpts[i-1:0])) ) 

# we can use z to display _full_ lines, on top of the line
# _segments_ that were displyed in example(chull):
for(i in 1:ncol(z)) abline(coef = z[,i], col = "red", lty = 2)




More information about the R-help mailing list