ggplot: How to draw contour line for 2d scatter plot to outline the data points

三世轮回 提交于 2019-12-11 08:44:08

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!