Learn R Programming

BMhyd (version 1.2-8)

Plot_ConvexHull: Convex hull

Description

Plotting the convex hall for given 2D datasets.

Usage

Plot_ConvexHull(xcoord, ycoord, lcolor)

Arguments

xcoord
coordinate for the horizontal axis.
ycoord
coordinate for the vertical axis.
lcolor
color of the convect hull.

Value

The convex hull plot for a set of 2D points.

Details

This function uses the base function chull(), which takes x,y coordinates of data and outputs a vector(hpts variable) of integers that indicate the points in dataset that comprise the convex hull around data. It then uses the base function lines to draw the convex hull using the x,y coordinates stored in hpts.

References

https://chitchatr.wordpress.com/2011/12/30/convex-hull-around-scatter-plot-in-r/

Examples

Run this code
	# Create a set of random data to plot convex hull around
	x<-rnorm(100,0.8,0.3)
	y<- rnorm(100,0.8,0.3)
	#get max and min of all x and y data for nice plotting
	xrange<-range(x)
	yrange<-range(y)
	#plot it up!
	plot(x,y,type="p",pch=1,col='black',xlim=c(xrange),ylim=c(yrange))
	Plot_ConvexHull(xcoord=x,ycoord=y,lcolor='red')
	

Run the code above in your browser using DataLab