Create a layer of convex hull for ggplot2 plots.

stat_chull(
  mapping = NULL,
  data = NULL,
  geom = "polygon",
  position = "identity",
  na.rm = FALSE,
  show.legend = NA,
  inherit.aes = TRUE,
  ...
)

Source

Source: vignette Extending ggplot2

Arguments

mapping

Set of aesthetic mappings created by aes or aes_. If specified and inherit.aes = TRUE (the default), it is combined with the default mapping at the top level of the plot. You must supply mapping if there is no plot mapping.

data

A layer specific dataset - only needed if you want to override the plot defaults.

geom

The geometric object to use display the data.

position

The position adjustment to use for overlapping points on this layer.

na.rm

If FALSE (the default), removes missing values with a warning. If TRUE silently removes missing values.

show.legend

logical. Should this layer be included in the legends? NA, the default, includes if any aesthetics are mapped. FALSE never includes, and TRUE always includes.

inherit.aes

If FALSE, overrides the default aesthetics, rather than combining with them. This is most useful for helper functions that define both data and aesthetics and shouldn't inherit behaviour from the default plot specification, e.g. borders.

...

Other arguments passed on to layer. These are often aesthetics, used to set an aesthetic to a fixed value, like color = "red" or size = 3.

Value

Layer of convex hull for ggplot2 plots.

Author

Hadley Wickham

Examples


ggplot(mpg, aes(displ, hwy)) +
             geom_point() +
             stat_chull(fill = NA, colour = "black")



ggplot(mpg, aes(displ, hwy, colour = drv)) +
             geom_point() +
             stat_chull(fill = NA)



ggplot(mpg, aes(displ, hwy)) +
             stat_chull(geom = "point", size = 4, colour = "red") +
             geom_point()