问题
I need to draw a line around all of my data points that plot within x-y space. I do not need 2d density distribution. See the picture attached (the field was just drawn manually). Thank you. scatter plot with line around data points
回答1:
This is the perfect use case for ggalt
's geom_encircle
:
#install.packages('ggalt')
library(ggalt)
#> Loading required package: ggplot2
ggplot(iris, aes(Sepal.Length, Sepal.Width)) +
geom_point() +
geom_encircle()

You can also encircle by group:
ggplot(iris, aes(Sepal.Length, Sepal.Width, color = Species)) +
geom_point() +
geom_encircle()

来源:https://stackoverflow.com/questions/44661972/ggplot-how-to-draw-contour-line-for-2d-scatter-plot-to-outline-the-data-points