1

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
  • There is a convexhull function is some package or another. But as it's name implies it will be convex. After sos::findFn("convexhull") I'd try either spatstat or dismo. It appears from the illustration of ggalt::geom_encircle below, that it might also be a convex result. Commented Jun 20, 2017 at 21:53

1 Answer 1

4

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()

Sign up to request clarification or add additional context in comments.

8 Comments

Thank you! Looks helpful, however I get the error: could not find function "geom_encircle". I have ggplot2 and ggalt installed. Weird.
also updated and loaded? On my system: packageVersion('ggplot2'): ‘2.2.1’ packageVersion('ggalt'): ‘0.4.0’
remove.packages("ggalt") install.packages("ggalt") update.packages("ggalt") packageVersion("ggalt") gives [1] ‘0.1.1’
It requires ggplot2 version 2.2.1. Is ggplot updated too?
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.