Highlight Groups with Convex Hull in ggplot2
To draw a line bounding box around the outermost points for each group we will use chull() method with grouped data points which computes the subset of points that lie on the convex hull of the set of points specified.
And to highlight the convex hull we can use geom_polygon() methods with convex hull datasets.
Syntax: geom_polygon( data, alpha, aes())
Parameters:
- data: Datasets
- alpha: Opacity of Points/Border
- aes: Color Highlight of data points.
R
# Find the convex hull of the points being plotted hull <- iris %>% group_by (Species) %>% slice ( chull (Sepal.Length, Sepal.Width)) plot + geom_polygon (data = hull, alpha = 0.2, aes (fill = Species,colour = Species)) |
Output:
How to Highlight Groups with Convex Hull in ggplot2 in R?
In this article, we are going to see how to highlight groups with the convex hull in ggplot2 using R Programming Language.
Convex hull polygon refers to the draw a line bounding box around the outermost points in each group.