How can I create open polygons using R like these two examples:
Asked
Active
Viewed 481 times
2 Answers
4
A little vague on what your use will be for this, but geom_path
within the package ggplot2
is a fairly simple approach.
First create a data frame, with x
and y
being your cartesian coordinates for all vertices:
df <- data.frame(plot = c(rep(1, 3), rep(2, 4)),
x = c(1, 0, 2, 0.5, 0, 2, 2.5),
y = c(1, 0, 0, 1, 0, 0, 1))
Now plot:
library(ggplot2)
ggplot(data = df, aes(x = x, y = y, group = 1)) +
geom_path(size = 1) +
facet_grid(. ~ plot) +
theme_bw()
If you want more flexibility with customization, I suggest you create a separate, more detailed question.

Dave Gruenewald
- 5,329
- 1
- 23
- 35
2
If you do not want to use ggplot
you can do a similar thing as @DaveGruenewald with the native plot
function.
Just do:
plot(c(0.5, 0, 2), c(1, 0, 0), type='l')
plot(c(0.5, 0, 2, 2.5), c(1, 0, 0, 1), type='l')
to get plots similar to @DaveGruenewald.

Mosquite
- 588
- 1
- 4
- 15