knitr::opts_chunk$set( collapse = TRUE, comment = "#>", fig.path = "README-" )
This package adds a geom_convexhull function, extending the geom_polygon one.
library(devtools) devtools::install_github("cmartin/ggConvexHull")
The simplest case
library(ggplot2) library(ggConvexHull) n <- 10 test_df <- data.frame( a = runif(n), b = runif(n) ) ggplot(test_df,aes(x = a,y = b)) + geom_point() + geom_convexhull(alpha = 0.3, fill = "blue")
It is especially useful to visualize the output of ordination functions with a polygon per group, e.g.
library(vegan) library(ggplot2) library(ggConvexHull) data("iris") df <- as.data.frame( scores(rda(iris[,1:3]))$site ) df$Species = iris$Species ggplot(df,aes(x = PC1, y = PC2,col = Species)) + geom_convexhull(alpha = 0.3,aes(fill = Species)) + geom_point() + theme_minimal()
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.