4

I have a series of points that I want to place a boundary around. How can I go about this?

These are my points: enter image description here

I tried geom_line but that was obviously wrong since it produced this!

enter image description here

Thanks

Elizabeth
  • 6,391
  • 17
  • 62
  • 90
  • ...as long as the points are in the correct order. – Spacedman Sep 26 '12 at 13:46
  • @Spacedman, do you have a recommendation for unordered points? There isn't a `geom_convex_hull`, is there (although the boundary above isn't even convex, which makes it worse)? – Ben Bolker Sep 26 '12 at 13:55
  • 1
    Its pretty much impossible to automate - look at that awkward bit towards the top where there's three sets of points in parallel. Is that an inlet (in which case from which side) or an island or a spiky bit of coastline. My recommendation is to join the dots manually. – Spacedman Sep 26 '12 at 13:59
  • luckily the points are in the right order as I am basically tracing reefs in googlemap as paths...not the most elegant of solutions but hey it works – Elizabeth Sep 26 '12 at 14:11
  • If the reefs you are tracing are in google maps imagery then you are most likely violating their terms of use... – Spacedman Sep 26 '12 at 14:14
  • Surely not since it is merely a crude path and google maps themselves allow the export of crude paths – Elizabeth Sep 26 '12 at 15:22

1 Answers1

4

Use geom_path instead of geom_line. Here is an example:

i <- seq(0, 2*pi, length.out=50)
dat <- data.frame(x=cos(i), y=sin(i))

library(ggplot2)
ggplot(dat, aes(x, y)) + geom_line()

enter image description here

ggplot(dat, aes(x, y)) + geom_path()

enter image description here

Andrie
  • 176,377
  • 47
  • 447
  • 496
  • geom_path doesn't always necessary give nice shape as you have shown.Are there other options to try? – alily Nov 01 '16 at 11:02